Commit b427203d by Nicola Pero Committed by Nicola Pero

sendmsg.c: Reindented some code and tidied up comments.

2010-12-15  Nicola Pero  <nicola.pero@meta-innovation.com>

	* sendmsg.c: Reindented some code and tidied up comments.  No
	actual code changes.

From-SVN: r167835
parent 6da95378
2010-12-15 Nicola Pero <nicola.pero@meta-innovation.com>
* sendmsg.c: Reindented some code and tidied up comments. No
actual code changes.
2010-12-14 Nicola Pero <nicola.pero@meta-innovation.com> 2010-12-14 Nicola Pero <nicola.pero@meta-innovation.com>
* objc/Object.h: Moved all the methods, with the exception of * objc/Object.h: Moved all the methods, with the exception of
......
...@@ -60,32 +60,30 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see ...@@ -60,32 +60,30 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
#define INVISIBLE_STRUCT_RETURN 0 #define INVISIBLE_STRUCT_RETURN 0
#endif #endif
/* The uninstalled dispatch table */ /* The uninstalled dispatch table. */
struct sarray *__objc_uninstalled_dtable = 0; /* !T:MUTEX */ struct sarray *__objc_uninstalled_dtable = 0; /* !T:MUTEX */
/* Two hooks for method forwarding. If either is set, it is invoked /* Two hooks for method forwarding. If either is set, it is invoked to
* to return a function that performs the real forwarding. If both * return a function that performs the real forwarding. If both are
* are set, the result of __objc_msg_forward2 will be preferred over * set, the result of __objc_msg_forward2 will be preferred over that
* that of __objc_msg_forward. If both return NULL or are unset, * of __objc_msg_forward. If both return NULL or are unset, the
* the libgcc based functions (__builtin_apply and friends) are * libgcc based functions (__builtin_apply and friends) are used. */
* used.
*/
IMP (*__objc_msg_forward) (SEL) = NULL; IMP (*__objc_msg_forward) (SEL) = NULL;
IMP (*__objc_msg_forward2) (id, SEL) = NULL; IMP (*__objc_msg_forward2) (id, SEL) = NULL;
/* Send +initialize to class */ /* Send +initialize to class. */
static void __objc_send_initialize (Class); static void __objc_send_initialize (Class);
static void __objc_install_dispatch_table_for_class (Class); static void __objc_install_dispatch_table_for_class (Class);
/* Forward declare some functions */ /* Forward declare some functions. */
static void __objc_init_install_dtable (id, SEL); static void __objc_init_install_dtable (id, SEL);
/* Various forwarding functions that are used based upon the /* Various forwarding functions that are used based upon the
return type for the selector. return type for the selector.
__objc_block_forward for structures. __objc_block_forward for structures.
__objc_double_forward for floats/doubles. __objc_double_forward for floats/doubles.
__objc_word_forward for pointers or types that fit in registers. */ __objc_word_forward for pointers or types that fit in registers. */
static double __objc_double_forward (id, SEL, ...); static double __objc_double_forward (id, SEL, ...);
static id __objc_word_forward (id, SEL, ...); static id __objc_word_forward (id, SEL, ...);
typedef struct { id many[8]; } __big; typedef struct { id many[8]; } __big;
...@@ -99,14 +97,15 @@ static struct objc_method * search_for_method_in_hierarchy (Class class, SEL sel ...@@ -99,14 +97,15 @@ static struct objc_method * search_for_method_in_hierarchy (Class class, SEL sel
struct objc_method * search_for_method_in_list (struct objc_method_list * list, SEL op); struct objc_method * search_for_method_in_list (struct objc_method_list * list, SEL op);
id nil_method (id, SEL); id nil_method (id, SEL);
/* Given a selector, return the proper forwarding implementation. */ /* Given a selector, return the proper forwarding implementation. */
inline inline
IMP IMP
__objc_get_forward_imp (id rcv, SEL sel) __objc_get_forward_imp (id rcv, SEL sel)
{ {
/* If a custom forwarding hook was registered, try getting a forwarding /* If a custom forwarding hook was registered, try getting a
function from it. There are two forward routine hooks, one that forwarding function from it. There are two forward routine hooks,
takes the receiver as an argument and one that does not. */ one that takes the receiver as an argument and one that does
not. */
if (__objc_msg_forward2) if (__objc_msg_forward2)
{ {
IMP result; IMP result;
...@@ -120,11 +119,11 @@ __objc_get_forward_imp (id rcv, SEL sel) ...@@ -120,11 +119,11 @@ __objc_get_forward_imp (id rcv, SEL sel)
return result; return result;
} }
/* In all other cases, use the default forwarding functions built using /* In all other cases, use the default forwarding functions built
__builtin_apply and friends. */ using __builtin_apply and friends. */
{ {
const char *t = sel->sel_types; const char *t = sel->sel_types;
if (t && (*t == '[' || *t == '(' || *t == '{') if (t && (*t == '[' || *t == '(' || *t == '{')
#ifdef OBJC_MAX_STRUCT_BY_VALUE #ifdef OBJC_MAX_STRUCT_BY_VALUE
&& objc_sizeof_type (t) > OBJC_MAX_STRUCT_BY_VALUE && objc_sizeof_type (t) > OBJC_MAX_STRUCT_BY_VALUE
...@@ -234,7 +233,8 @@ __objc_resolve_instance_method (Class class, SEL sel) ...@@ -234,7 +233,8 @@ __objc_resolve_instance_method (Class class, SEL sel)
/* Temporary definition until we include objc/runtime.h. */ /* Temporary definition until we include objc/runtime.h. */
objc_EXPORT Class objc_lookupClass (const char *name); objc_EXPORT Class objc_lookupClass (const char *name);
/* Given a class and selector, return the selector's implementation. */ /* Given a class and selector, return the selector's
implementation. */
inline inline
IMP IMP
get_imp (Class class, SEL sel) get_imp (Class class, SEL sel)
...@@ -250,10 +250,10 @@ get_imp (Class class, SEL sel) ...@@ -250,10 +250,10 @@ get_imp (Class class, SEL sel)
void *res = sarray_get_safe (class->dtable, (size_t) sel->sel_id); void *res = sarray_get_safe (class->dtable, (size_t) sel->sel_id);
if (res == 0) if (res == 0)
{ {
/* Not a valid method */ /* Not a valid method. */
if (class->dtable == __objc_uninstalled_dtable) if (class->dtable == __objc_uninstalled_dtable)
{ {
/* The dispatch table needs to be installed. */ /* The dispatch table needs to be installed. */
objc_mutex_lock (__objc_runtime_mutex); objc_mutex_lock (__objc_runtime_mutex);
/* Double-checked locking pattern: Check /* Double-checked locking pattern: Check
...@@ -266,8 +266,8 @@ get_imp (Class class, SEL sel) ...@@ -266,8 +266,8 @@ get_imp (Class class, SEL sel)
} }
objc_mutex_unlock (__objc_runtime_mutex); objc_mutex_unlock (__objc_runtime_mutex);
/* Call ourselves with the installed dispatch table /* Call ourselves with the installed dispatch table and get
and get the real method */ the real method. */
res = get_imp (class, sel); res = get_imp (class, sel);
} }
else else
...@@ -277,8 +277,7 @@ get_imp (Class class, SEL sel) ...@@ -277,8 +277,7 @@ get_imp (Class class, SEL sel)
/* Get the method from the dispatch table (we try to get it /* Get the method from the dispatch table (we try to get it
again in case another thread has installed the dtable just again in case another thread has installed the dtable just
after we invoked sarray_get_safe, but before we checked after we invoked sarray_get_safe, but before we checked
class->dtable == __objc_uninstalled_dtable). class->dtable == __objc_uninstalled_dtable). */
*/
res = sarray_get_safe (class->dtable, (size_t) sel->sel_id); res = sarray_get_safe (class->dtable, (size_t) sel->sel_id);
if (res == 0) if (res == 0)
{ {
...@@ -305,12 +304,12 @@ get_imp (Class class, SEL sel) ...@@ -305,12 +304,12 @@ get_imp (Class class, SEL sel)
if (res == 0) if (res == 0)
{ {
/* If that fails, then return the forwarding /* If that fails, then return the forwarding
implementation. We don't know the receiver (only its implementation. We don't know the receiver (only
class), so we have to pass 'nil' as the first its class), so we have to pass 'nil' as the first
argument. Passing the class as first argument is argument. Passing the class as first argument is
wrong because the class is not the receiver; it can wrong because the class is not the receiver; it
result in us calling a class method when we want an can result in us calling a class method when we
instance method of the same name. */ want an instance method of the same name. */
res = __objc_get_forward_imp (nil, sel); res = __objc_get_forward_imp (nil, sel);
} }
} }
...@@ -338,15 +337,15 @@ method_get_imp (struct objc_method * method) ...@@ -338,15 +337,15 @@ method_get_imp (struct objc_method * method)
} }
/* Query if an object can respond to a selector, returns YES if the /* Query if an object can respond to a selector, returns YES if the
object implements the selector otherwise NO. Does not check if the object implements the selector otherwise NO. Does not check if the
method can be forwarded. */ method can be forwarded. */
inline inline
BOOL BOOL
__objc_responds_to (id object, SEL sel) __objc_responds_to (id object, SEL sel)
{ {
void *res; void *res;
/* Install dispatch table if need be */ /* Install dispatch table if need be. */
if (object->class_pointer->dtable == __objc_uninstalled_dtable) if (object->class_pointer->dtable == __objc_uninstalled_dtable)
{ {
objc_mutex_lock (__objc_runtime_mutex); objc_mutex_lock (__objc_runtime_mutex);
...@@ -357,7 +356,7 @@ __objc_responds_to (id object, SEL sel) ...@@ -357,7 +356,7 @@ __objc_responds_to (id object, SEL sel)
objc_mutex_unlock (__objc_runtime_mutex); objc_mutex_unlock (__objc_runtime_mutex);
} }
/* Get the method from the dispatch table */ /* Get the method from the dispatch table. */
res = sarray_get_safe (object->class_pointer->dtable, (size_t) sel->sel_id); res = sarray_get_safe (object->class_pointer->dtable, (size_t) sel->sel_id);
return (res != 0); return (res != 0);
} }
...@@ -370,7 +369,7 @@ class_respondsToSelector (Class class_, SEL selector) ...@@ -370,7 +369,7 @@ class_respondsToSelector (Class class_, SEL selector)
if (class_ == Nil || selector == NULL) if (class_ == Nil || selector == NULL)
return NO; return NO;
/* Install dispatch table if need be */ /* Install dispatch table if need be. */
if (class_->dtable == __objc_uninstalled_dtable) if (class_->dtable == __objc_uninstalled_dtable)
{ {
objc_mutex_lock (__objc_runtime_mutex); objc_mutex_lock (__objc_runtime_mutex);
...@@ -381,15 +380,15 @@ class_respondsToSelector (Class class_, SEL selector) ...@@ -381,15 +380,15 @@ class_respondsToSelector (Class class_, SEL selector)
objc_mutex_unlock (__objc_runtime_mutex); objc_mutex_unlock (__objc_runtime_mutex);
} }
/* Get the method from the dispatch table */ /* Get the method from the dispatch table. */
res = sarray_get_safe (class_->dtable, (size_t) selector->sel_id); res = sarray_get_safe (class_->dtable, (size_t) selector->sel_id);
return (res != 0); return (res != 0);
} }
/* This is the lookup function. All entries in the table are either a /* This is the lookup function. All entries in the table are either a
valid method *or* zero. If zero then either the dispatch table valid method *or* zero. If zero then either the dispatch table
needs to be installed or it doesn't exist and forwarding is attempted. */ needs to be installed or it doesn't exist and forwarding is
attempted. */
IMP IMP
objc_msg_lookup (id receiver, SEL op) objc_msg_lookup (id receiver, SEL op)
{ {
...@@ -400,14 +399,16 @@ objc_msg_lookup (id receiver, SEL op) ...@@ -400,14 +399,16 @@ objc_msg_lookup (id receiver, SEL op)
(sidx)op->sel_id); (sidx)op->sel_id);
if (result == 0) if (result == 0)
{ {
/* Not a valid method */ /* Not a valid method. */
if (receiver->class_pointer->dtable == __objc_uninstalled_dtable) if (receiver->class_pointer->dtable == __objc_uninstalled_dtable)
{ {
/* The dispatch table needs to be installed. /* The dispatch table needs to be installed. This
This happens on the very first method call to the class. */ happens on the very first method call to the
class. */
__objc_init_install_dtable (receiver, op); __objc_init_install_dtable (receiver, op);
/* Get real method for this in newly installed dtable */ /* Get real method for this in newly installed
dtable. */
result = get_imp (receiver->class_pointer, op); result = get_imp (receiver->class_pointer, op);
} }
else else
...@@ -415,8 +416,7 @@ objc_msg_lookup (id receiver, SEL op) ...@@ -415,8 +416,7 @@ objc_msg_lookup (id receiver, SEL op)
/* The dispatch table has been installed. Check again /* The dispatch table has been installed. Check again
if the method exists (just in case the dispatch table if the method exists (just in case the dispatch table
has been installed by another thread after we did the has been installed by another thread after we did the
previous check that the method exists). previous check that the method exists). */
*/
result = sarray_get_safe (receiver->class_pointer->dtable, result = sarray_get_safe (receiver->class_pointer->dtable,
(sidx)op->sel_id); (sidx)op->sel_id);
if (result == 0) if (result == 0)
...@@ -432,7 +432,7 @@ objc_msg_lookup (id receiver, SEL op) ...@@ -432,7 +432,7 @@ objc_msg_lookup (id receiver, SEL op)
if (result == 0) if (result == 0)
{ {
/* If the method still just doesn't exist for /* If the method still just doesn't exist for
the class, attempt to forward the method. */ the class, attempt to forward the method. */
result = __objc_get_forward_imp (receiver, op); result = __objc_get_forward_imp (receiver, op);
} }
} }
...@@ -477,16 +477,16 @@ __objc_init_dispatch_tables () ...@@ -477,16 +477,16 @@ __objc_init_dispatch_tables ()
selector_resolveInstanceMethod =sel_register_name ("resolveInstanceMethod:"); selector_resolveInstanceMethod =sel_register_name ("resolveInstanceMethod:");
} }
/* This function is called by objc_msg_lookup when the /* This function is called by objc_msg_lookup when the dispatch table
dispatch table needs to be installed; thus it is called once needs to be installed; thus it is called once for each class,
for each class, namely when the very first message is sent to it. */ namely when the very first message is sent to it. */
static void static void
__objc_init_install_dtable (id receiver, SEL op __attribute__ ((__unused__))) __objc_init_install_dtable (id receiver, SEL op __attribute__ ((__unused__)))
{ {
objc_mutex_lock (__objc_runtime_mutex); objc_mutex_lock (__objc_runtime_mutex);
/* This may happen, if the programmer has taken the address of a /* This may happen, if the programmer has taken the address of a
method before the dtable was initialized... too bad for him! */ method before the dtable was initialized... too bad for him! */
if (receiver->class_pointer->dtable != __objc_uninstalled_dtable) if (receiver->class_pointer->dtable != __objc_uninstalled_dtable)
{ {
objc_mutex_unlock (__objc_runtime_mutex); objc_mutex_unlock (__objc_runtime_mutex);
...@@ -495,23 +495,23 @@ __objc_init_install_dtable (id receiver, SEL op __attribute__ ((__unused__))) ...@@ -495,23 +495,23 @@ __objc_init_install_dtable (id receiver, SEL op __attribute__ ((__unused__)))
if (CLS_ISCLASS (receiver->class_pointer)) if (CLS_ISCLASS (receiver->class_pointer))
{ {
/* receiver is an ordinary object */ /* receiver is an ordinary object. */
assert (CLS_ISCLASS (receiver->class_pointer)); assert (CLS_ISCLASS (receiver->class_pointer));
/* install instance methods table */ /* Install instance methods table. */
__objc_install_dispatch_table_for_class (receiver->class_pointer); __objc_install_dispatch_table_for_class (receiver->class_pointer);
/* call +initialize -- this will in turn install the factory /* Call +initialize -- this will in turn install the factory
dispatch table if not already done :-) */ dispatch table if not already done. :-) */
__objc_send_initialize (receiver->class_pointer); __objc_send_initialize (receiver->class_pointer);
} }
else else
{ {
/* receiver is a class object */ /* receiver is a class object. */
assert (CLS_ISCLASS ((Class)receiver)); assert (CLS_ISCLASS ((Class)receiver));
assert (CLS_ISMETA (receiver->class_pointer)); assert (CLS_ISMETA (receiver->class_pointer));
/* Install real dtable for factory methods */ /* Install real dtable for factory methods. */
__objc_install_dispatch_table_for_class (receiver->class_pointer); __objc_install_dispatch_table_for_class (receiver->class_pointer);
__objc_send_initialize ((Class)receiver); __objc_send_initialize ((Class)receiver);
...@@ -520,7 +520,7 @@ __objc_init_install_dtable (id receiver, SEL op __attribute__ ((__unused__))) ...@@ -520,7 +520,7 @@ __objc_init_install_dtable (id receiver, SEL op __attribute__ ((__unused__)))
} }
/* Install dummy table for class which causes the first message to /* Install dummy table for class which causes the first message to
that class (or instances hereof) to be initialized properly */ that class (or instances hereof) to be initialized properly. */
void void
__objc_install_premature_dtable (Class class) __objc_install_premature_dtable (Class class)
{ {
...@@ -528,11 +528,11 @@ __objc_install_premature_dtable (Class class) ...@@ -528,11 +528,11 @@ __objc_install_premature_dtable (Class class)
class->dtable = __objc_uninstalled_dtable; class->dtable = __objc_uninstalled_dtable;
} }
/* Send +initialize to class if not already done */ /* Send +initialize to class if not already done. */
static void static void
__objc_send_initialize (Class class) __objc_send_initialize (Class class)
{ {
/* This *must* be a class object */ /* This *must* be a class object. */
assert (CLS_ISCLASS (class)); assert (CLS_ISCLASS (class));
assert (! CLS_ISMETA (class)); assert (! CLS_ISMETA (class));
...@@ -541,60 +541,62 @@ __objc_send_initialize (Class class) ...@@ -541,60 +541,62 @@ __objc_send_initialize (Class class)
CLS_SETINITIALIZED (class); CLS_SETINITIALIZED (class);
CLS_SETINITIALIZED (class->class_pointer); CLS_SETINITIALIZED (class->class_pointer);
/* Create the garbage collector type memory description */ /* Create the garbage collector type memory description. */
__objc_generate_gc_type_description (class); __objc_generate_gc_type_description (class);
if (class->super_class) if (class->super_class)
__objc_send_initialize (class->super_class); __objc_send_initialize (class->super_class);
{ {
SEL op = sel_register_name ("initialize"); SEL op = sel_register_name ("initialize");
IMP imp = 0; IMP imp = 0;
struct objc_method_list * method_list = class->class_pointer->methods; struct objc_method_list * method_list = class->class_pointer->methods;
while (method_list) { while (method_list)
int i; {
struct objc_method * method; int i;
struct objc_method * method;
for (i = 0; i < method_list->method_count; i++) {
method = &(method_list->method_list[i]); for (i = 0; i < method_list->method_count; i++)
if (method->method_name {
&& method->method_name->sel_id == op->sel_id) { method = &(method_list->method_list[i]);
imp = method->method_imp; if (method->method_name
break; && method->method_name->sel_id == op->sel_id)
} {
} imp = method->method_imp;
break;
if (imp) }
break; }
method_list = method_list->method_next; if (imp)
break;
}
method_list = method_list->method_next;
}
if (imp) if (imp)
(*imp) ((id) class, op); (*imp) ((id) class, op);
} }
} }
} }
/* Walk on the methods list of class and install the methods in the reverse /* Walk on the methods list of class and install the methods in the
order of the lists. Since methods added by categories are before the methods reverse order of the lists. Since methods added by categories are
of class in the methods list, this allows categories to substitute methods before the methods of class in the methods list, this allows
declared in class. However if more than one category replaces the same categories to substitute methods declared in class. However if
method nothing is guaranteed about what method will be used. more than one category replaces the same method nothing is
Assumes that __objc_runtime_mutex is locked down. */ guaranteed about what method will be used. Assumes that
__objc_runtime_mutex is locked down. */
static void static void
__objc_install_methods_in_dtable (Class class, struct objc_method_list * method_list) __objc_install_methods_in_dtable (Class class, struct objc_method_list * method_list)
{ {
int i; int i;
if (! method_list) if (! method_list)
return; return;
if (method_list->method_next) if (method_list->method_next)
__objc_install_methods_in_dtable (class, method_list->method_next); __objc_install_methods_in_dtable (class, method_list->method_next);
for (i = 0; i < method_list->method_count; i++) for (i = 0; i < method_list->method_count; i++)
{ {
struct objc_method * method = &(method_list->method_list[i]); struct objc_method * method = &(method_list->method_list[i]);
...@@ -604,23 +606,23 @@ __objc_install_methods_in_dtable (Class class, struct objc_method_list * method_ ...@@ -604,23 +606,23 @@ __objc_install_methods_in_dtable (Class class, struct objc_method_list * method_
} }
} }
/* Assumes that __objc_runtime_mutex is locked down. */ /* Assumes that __objc_runtime_mutex is locked down. */
static void static void
__objc_install_dispatch_table_for_class (Class class) __objc_install_dispatch_table_for_class (Class class)
{ {
Class super; Class super;
/* If the class has not yet had its class links resolved, we must /* If the class has not yet had its class links resolved, we must
re-compute all class links */ re-compute all class links. */
if (! CLS_ISRESOLV (class)) if (! CLS_ISRESOLV (class))
__objc_resolve_class_links (); __objc_resolve_class_links ();
super = class->super_class; super = class->super_class;
if (super != 0 && (super->dtable == __objc_uninstalled_dtable)) if (super != 0 && (super->dtable == __objc_uninstalled_dtable))
__objc_install_dispatch_table_for_class (super); __objc_install_dispatch_table_for_class (super);
/* Allocate dtable if necessary */ /* Allocate dtable if necessary. */
if (super == 0) if (super == 0)
{ {
objc_mutex_lock (__objc_runtime_mutex); objc_mutex_lock (__objc_runtime_mutex);
...@@ -639,7 +641,7 @@ __objc_update_dispatch_table_for_class (Class class) ...@@ -639,7 +641,7 @@ __objc_update_dispatch_table_for_class (Class class)
Class next; Class next;
struct sarray *arr; struct sarray *arr;
/* not yet installed -- skip it */ /* Not yet installed -- skip it. */
if (class->dtable == __objc_uninstalled_dtable) if (class->dtable == __objc_uninstalled_dtable)
return; return;
...@@ -648,25 +650,24 @@ __objc_update_dispatch_table_for_class (Class class) ...@@ -648,25 +650,24 @@ __objc_update_dispatch_table_for_class (Class class)
arr = class->dtable; arr = class->dtable;
__objc_install_premature_dtable (class); /* someone might require it... */ __objc_install_premature_dtable (class); /* someone might require it... */
sarray_free (arr); /* release memory */ sarray_free (arr); /* release memory */
/* could have been lazy... */ /* Could have been lazy... */
__objc_install_dispatch_table_for_class (class); __objc_install_dispatch_table_for_class (class);
if (class->subclass_list) /* Traverse subclasses */ if (class->subclass_list) /* Traverse subclasses. */
for (next = class->subclass_list; next; next = next->sibling_class) for (next = class->subclass_list; next; next = next->sibling_class)
__objc_update_dispatch_table_for_class (next); __objc_update_dispatch_table_for_class (next);
objc_mutex_unlock (__objc_runtime_mutex); objc_mutex_unlock (__objc_runtime_mutex);
} }
/* This function adds a method list to a class. This function is /* This function adds a method list to a class. This function is
typically called by another function specific to the run-time. As typically called by another function specific to the run-time. As
such this function does not worry about thread safe issues. such this function does not worry about thread safe issues.
This one is only called for categories. Class objects have their This one is only called for categories. Class objects have their
methods installed right away, and their selectors are made into methods installed right away, and their selectors are made into
SEL's by the function __objc_register_selectors_from_class. */ SEL's by the function __objc_register_selectors_from_class. */
void void
class_add_method_list (Class class, struct objc_method_list * list) class_add_method_list (Class class, struct objc_method_list * list)
{ {
...@@ -679,7 +680,7 @@ class_add_method_list (Class class, struct objc_method_list * list) ...@@ -679,7 +680,7 @@ class_add_method_list (Class class, struct objc_method_list * list)
list->method_next = class->methods; list->method_next = class->methods;
class->methods = list; class->methods = list;
/* Update the dispatch table of class */ /* Update the dispatch table of class. */
__objc_update_dispatch_table_for_class (class); __objc_update_dispatch_table_for_class (class);
} }
...@@ -707,8 +708,8 @@ class_getInstanceMethod (Class class_, SEL selector) ...@@ -707,8 +708,8 @@ class_getInstanceMethod (Class class_, SEL selector)
if (m) if (m)
return m; return m;
/* Try going through +resolveInstanceMethod:, and do /* Try going through +resolveInstanceMethod:, and do the search
the search again if successful. */ again if successful. */
if (__objc_resolve_instance_method (class_, selector)) if (__objc_resolve_instance_method (class_, selector))
return search_for_method_in_hierarchy (class_, selector); return search_for_method_in_hierarchy (class_, selector);
...@@ -811,9 +812,9 @@ class_replaceMethod (Class class_, SEL selector, IMP implementation, ...@@ -811,9 +812,9 @@ class_replaceMethod (Class class_, SEL selector, IMP implementation,
} }
} }
/* Search for a method starting from the current class up its hierarchy. /* Search for a method starting from the current class up its
Return a pointer to the method's method structure if found. NULL hierarchy. Return a pointer to the method's method structure if
otherwise. */ found. NULL otherwise. */
static struct objc_method * static struct objc_method *
search_for_method_in_hierarchy (Class cls, SEL sel) search_for_method_in_hierarchy (Class cls, SEL sel)
{ {
...@@ -823,8 +824,8 @@ search_for_method_in_hierarchy (Class cls, SEL sel) ...@@ -823,8 +824,8 @@ search_for_method_in_hierarchy (Class cls, SEL sel)
if (! sel_is_mapped (sel)) if (! sel_is_mapped (sel))
return NULL; return NULL;
/* Scan the method list of the class. If the method isn't found in the /* Scan the method list of the class. If the method isn't found in
list then step to its super class. */ the list then step to its super class. */
for (class = cls; ((! method) && class); class = class->super_class) for (class = cls; ((! method) && class); class = class->super_class)
method = search_for_method_in_list (class->methods, sel); method = search_for_method_in_list (class->methods, sel);
...@@ -833,9 +834,9 @@ search_for_method_in_hierarchy (Class cls, SEL sel) ...@@ -833,9 +834,9 @@ search_for_method_in_hierarchy (Class cls, SEL sel)
/* Given a linked list of method and a method's name. Search for the named /* Given a linked list of method and a method's name. Search for the
method's method structure. Return a pointer to the method's method named method's method structure. Return a pointer to the method's
structure if found. NULL otherwise. */ method structure if found. NULL otherwise. */
struct objc_method * struct objc_method *
search_for_method_in_list (struct objc_method_list * list, SEL op) search_for_method_in_list (struct objc_method_list * list, SEL op)
{ {
...@@ -869,7 +870,7 @@ search_for_method_in_list (struct objc_method_list * list, SEL op) ...@@ -869,7 +870,7 @@ search_for_method_in_list (struct objc_method_list * list, SEL op)
static retval_t __objc_forward (id object, SEL sel, arglist_t args); static retval_t __objc_forward (id object, SEL sel, arglist_t args);
/* Forwarding pointers/integers through the normal registers */ /* Forwarding pointers/integers through the normal registers. */
static id static id
__objc_word_forward (id rcv, SEL op, ...) __objc_word_forward (id rcv, SEL op, ...)
{ {
...@@ -884,10 +885,10 @@ __objc_word_forward (id rcv, SEL op, ...) ...@@ -884,10 +885,10 @@ __objc_word_forward (id rcv, SEL op, ...)
} }
/* Specific routine for forwarding floats/double because of /* Specific routine for forwarding floats/double because of
architectural differences on some processors. i386s for architectural differences on some processors. i386s for example
example which uses a floating point stack versus general which uses a floating point stack versus general registers for
registers for floating point numbers. This forward routine floating point numbers. This forward routine makes sure that GCC
makes sure that GCC restores the proper return values */ restores the proper return values. */
static double static double
__objc_double_forward (id rcv, SEL op, ...) __objc_double_forward (id rcv, SEL op, ...)
{ {
...@@ -920,8 +921,9 @@ __objc_block_forward (id rcv, SEL op, ...) ...@@ -920,8 +921,9 @@ __objc_block_forward (id rcv, SEL op, ...)
} }
/* This function is installed in the dispatch table for all methods which are /* This function is installed in the dispatch table for all methods
not implemented. Thus, it is called when a selector is not recognized. */ which are not implemented. Thus, it is called when a selector is
not recognized. */
static retval_t static retval_t
__objc_forward (id object, SEL sel, arglist_t args) __objc_forward (id object, SEL sel, arglist_t args)
{ {
...@@ -929,7 +931,7 @@ __objc_forward (id object, SEL sel, arglist_t args) ...@@ -929,7 +931,7 @@ __objc_forward (id object, SEL sel, arglist_t args)
static SEL frwd_sel = 0; /* !T:SAFE2 */ static SEL frwd_sel = 0; /* !T:SAFE2 */
SEL err_sel; SEL err_sel;
/* first try if the object understands forward:: */ /* First try if the object understands forward::. */
if (! frwd_sel) if (! frwd_sel)
frwd_sel = sel_get_any_uid ("forward::"); frwd_sel = sel_get_any_uid ("forward::");
...@@ -939,8 +941,8 @@ __objc_forward (id object, SEL sel, arglist_t args) ...@@ -939,8 +941,8 @@ __objc_forward (id object, SEL sel, arglist_t args)
return (*imp) (object, frwd_sel, sel, args); return (*imp) (object, frwd_sel, sel, args);
} }
/* If the object recognizes the doesNotRecognize: method then we're going /* If the object recognizes the doesNotRecognize: method then we're
to send it. */ going to send it. */
err_sel = sel_get_any_uid ("doesNotRecognize:"); err_sel = sel_get_any_uid ("doesNotRecognize:");
if (__objc_responds_to (object, err_sel)) if (__objc_responds_to (object, err_sel))
{ {
...@@ -949,7 +951,7 @@ __objc_forward (id object, SEL sel, arglist_t args) ...@@ -949,7 +951,7 @@ __objc_forward (id object, SEL sel, arglist_t args)
} }
/* The object doesn't recognize the method. Check for responding to /* The object doesn't recognize the method. Check for responding to
error:. If it does then sent it. */ error:. If it does then sent it. */
{ {
char msg[256 + strlen ((const char *) sel_get_name (sel)) char msg[256 + strlen ((const char *) sel_get_name (sel))
+ strlen ((const char *) object->class_pointer->name)]; + strlen ((const char *) object->class_pointer->name)];
...@@ -968,8 +970,8 @@ __objc_forward (id object, SEL sel, arglist_t args) ...@@ -968,8 +970,8 @@ __objc_forward (id object, SEL sel, arglist_t args)
return (*imp) (object, sel_get_any_uid ("error:"), msg); return (*imp) (object, sel_get_any_uid ("error:"), msg);
} }
/* The object doesn't respond to doesNotRecognize: or error:; Therefore, /* The object doesn't respond to doesNotRecognize: or error:;
a default action is taken. */ Therefore, a default action is taken. */
_objc_abort ("%s\n", msg); _objc_abort ("%s\n", msg);
return 0; return 0;
...@@ -1006,10 +1008,9 @@ __objc_print_dtable_stats () ...@@ -1006,10 +1008,9 @@ __objc_print_dtable_stats ()
objc_mutex_unlock (__objc_runtime_mutex); objc_mutex_unlock (__objc_runtime_mutex);
} }
/* Returns the uninstalled dispatch table indicator. /* Returns the uninstalled dispatch table indicator. If a class'
If a class' dispatch table points to __objc_uninstalled_dtable dispatch table points to __objc_uninstalled_dtable then that means
then that means it needs its dispatch table to be installed. */ it needs its dispatch table to be installed. */
struct sarray * struct sarray *
objc_get_uninstalled_dtable () objc_get_uninstalled_dtable ()
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment