diff options
author | shebs <shebs@138bc75d-0d04-0410-961f-82ee72b054a4> | 2002-07-02 19:43:03 +0000 |
---|---|---|
committer | shebs <shebs@138bc75d-0d04-0410-961f-82ee72b054a4> | 2002-07-02 19:43:03 +0000 |
commit | 617763557711795ccc8087e4c7af30832f1af171 (patch) | |
tree | 8f207ea088d819aa3e3ed4230231f34c706b6e54 /libobjc/selector.c | |
parent | 894a031dc687848ac0c10c9e00a201f870b3179a (diff) | |
download | gcc-617763557711795ccc8087e4c7af30832f1af171.tar.gz |
2002-07-02 Rodney Brown <rbrown64@csc.com.au>
* objc/encoding.h: Fix formatting.
* objc/hash.h: Likewise.
* objc/objc-api.h: Likewise.
* objc/runtime.h: Likewise.
* objc/thr.h: Likewise.
* archive.c: Likewise.
* class.c: Likewise.
* encoding.c: Likewise.
* gc.c: Likewise.
* hash.c: Likewise.
* init.c: Likewise.
* misc.c: Likewise.
* nil_method.c: Likewise.
* objects.c: Likewise.
* sarray.c: Likewise.
* selector.c: Likewise.
* sendmsg.c: Likewise.
* thr-mach.c: Likewise.
* thr.c: Likewise.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@55190 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libobjc/selector.c')
-rw-r--r-- | libobjc/selector.c | 145 |
1 files changed, 71 insertions, 74 deletions
diff --git a/libobjc/selector.c b/libobjc/selector.c index 13a2afd1812..5f5a26bc9af 100644 --- a/libobjc/selector.c +++ b/libobjc/selector.c @@ -31,16 +31,16 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #define SELECTOR_HASH_SIZE 128 /* Tables mapping selector names to uid and opposite */ -static struct sarray* __objc_selector_array = 0; /* uid -> sel !T:MUTEX */ -static struct sarray* __objc_selector_names = 0; /* uid -> name !T:MUTEX */ +static struct sarray *__objc_selector_array = 0; /* uid -> sel !T:MUTEX */ +static struct sarray *__objc_selector_names = 0; /* uid -> name !T:MUTEX */ static cache_ptr __objc_selector_hash = 0; /* name -> uid !T:MUTEX */ -static void register_selectors_from_list(MethodList_t); +static void register_selectors_from_list (MethodList_t); /* Number of selectors stored in each of the above tables */ unsigned int __objc_selector_max_index = 0; /* !T:MUTEX */ -void __objc_init_selector_tables() +void __objc_init_selector_tables () { __objc_selector_array = sarray_new (SELECTOR_HASH_SIZE, 0); __objc_selector_names = sarray_new (SELECTOR_HASH_SIZE, 0); @@ -81,15 +81,15 @@ register_selectors_from_list (MethodList_t method_list) { Method_t method = &method_list->method_list[i]; method->method_name - = sel_register_typed_name ((const char*)method->method_name, - method->method_types); + = sel_register_typed_name ((const char *) method->method_name, + method->method_types); i += 1; } } /* Register instance methods as class methods for root classes */ -void __objc_register_instance_methods_to_class(Class class) +void __objc_register_instance_methods_to_class (Class class) { MethodList_t method_list; MethodList_t class_method_list; @@ -98,12 +98,12 @@ void __objc_register_instance_methods_to_class(Class class) Method_t curr_method; /* Only if a root class. */ - if(class->super_class) + if (class->super_class) return; /* Allocate a method list to hold the new class methods */ - new_list = objc_calloc(sizeof(struct objc_method_list) - + sizeof(struct objc_method[max_methods_no]), 1); + new_list = objc_calloc (sizeof (struct objc_method_list) + + sizeof (struct objc_method[max_methods_no]), 1); method_list = class->methods; class_method_list = class->class_pointer->methods; curr_method = &new_list->method_list[0]; @@ -118,7 +118,7 @@ void __objc_register_instance_methods_to_class(Class class) { Method_t mth = &method_list->method_list[i]; if (mth->method_name - && !search_for_method_in_list (class_method_list, + && ! search_for_method_in_list (class_method_list, mth->method_name)) { /* This instance method isn't a class method. @@ -126,10 +126,10 @@ void __objc_register_instance_methods_to_class(Class class) *curr_method = *mth; /* Reallocate the method list if necessary */ - if(++new_list->method_count == max_methods_no) + if (++new_list->method_count == max_methods_no) new_list = - objc_realloc(new_list, sizeof(struct objc_method_list) - + sizeof(struct + objc_realloc (new_list, sizeof (struct objc_method_list) + + sizeof (struct objc_method[max_methods_no += 16])); curr_method = &new_list->method_list[new_list->method_count]; } @@ -143,8 +143,8 @@ void __objc_register_instance_methods_to_class(Class class) if (new_list->method_count) { new_list = - objc_realloc(new_list, sizeof(struct objc_method_list) - + sizeof(struct objc_method[new_list->method_count])); + objc_realloc (new_list, sizeof (struct objc_method_list) + + sizeof (struct objc_method[new_list->method_count])); new_list->method_next = class->class_pointer->methods; class->class_pointer->methods = new_list; } @@ -156,21 +156,21 @@ void __objc_register_instance_methods_to_class(Class class) /* Returns YES iff t1 and t2 have same method types, but we ignore the argframe layout */ BOOL -sel_types_match (const char* t1, const char* t2) +sel_types_match (const char *t1, const char *t2) { - if (!t1 || !t2) + if (! t1 || ! t2) return NO; while (*t1 && *t2) { if (*t1 == '+') t1++; if (*t2 == '+') t2++; - while (isdigit((unsigned char)*t1)) t1++; - while (isdigit((unsigned char)*t2)) t2++; + while (isdigit ((unsigned char) *t1)) t1++; + while (isdigit ((unsigned char) *t2)) t2++; /* xxx Remove these next two lines when qualifiers are put in all selectors, not just Protocol selectors. */ - t1 = objc_skip_type_qualifiers(t1); - t2 = objc_skip_type_qualifiers(t2); - if (!*t1 && !*t2) + t1 = objc_skip_type_qualifiers (t1); + t2 = objc_skip_type_qualifiers (t2); + if (! *t1 && ! *t2) return YES; if (*t1 != *t2) return NO; @@ -187,35 +187,35 @@ sel_get_typed_uid (const char *name, const char *types) struct objc_list *l; sidx i; - objc_mutex_lock(__objc_runtime_mutex); + objc_mutex_lock (__objc_runtime_mutex); i = (sidx) hash_value_for_key (__objc_selector_hash, name); if (i == 0) { - objc_mutex_unlock(__objc_runtime_mutex); + objc_mutex_unlock (__objc_runtime_mutex); return 0; } - for (l = (struct objc_list*)sarray_get_safe (__objc_selector_array, i); + for (l = (struct objc_list *) sarray_get_safe (__objc_selector_array, i); l; l = l->tail) { - SEL s = (SEL)l->head; + SEL s = (SEL) l->head; if (types == 0 || s->sel_types == 0) { if (s->sel_types == types) { - objc_mutex_unlock(__objc_runtime_mutex); + objc_mutex_unlock (__objc_runtime_mutex); return s; } } else if (sel_types_match (s->sel_types, types)) { - objc_mutex_unlock(__objc_runtime_mutex); + objc_mutex_unlock (__objc_runtime_mutex); return s; } } - objc_mutex_unlock(__objc_runtime_mutex); + objc_mutex_unlock (__objc_runtime_mutex); return 0; } @@ -227,27 +227,27 @@ sel_get_any_typed_uid (const char *name) sidx i; SEL s = NULL; - objc_mutex_lock(__objc_runtime_mutex); + objc_mutex_lock (__objc_runtime_mutex); i = (sidx) hash_value_for_key (__objc_selector_hash, name); if (i == 0) { - objc_mutex_unlock(__objc_runtime_mutex); + objc_mutex_unlock (__objc_runtime_mutex); return 0; } - for (l = (struct objc_list*)sarray_get_safe (__objc_selector_array, i); + for (l = (struct objc_list *) sarray_get_safe (__objc_selector_array, i); l; l = l->tail) { s = (SEL) l->head; if (s->sel_types) { - objc_mutex_unlock(__objc_runtime_mutex); + objc_mutex_unlock (__objc_runtime_mutex); return s; } } - objc_mutex_unlock(__objc_runtime_mutex); + objc_mutex_unlock (__objc_runtime_mutex); return s; } @@ -258,22 +258,22 @@ sel_get_any_uid (const char *name) struct objc_list *l; sidx i; - objc_mutex_lock(__objc_runtime_mutex); + objc_mutex_lock (__objc_runtime_mutex); i = (sidx) hash_value_for_key (__objc_selector_hash, name); if (soffset_decode (i) == 0) { - objc_mutex_unlock(__objc_runtime_mutex); + objc_mutex_unlock (__objc_runtime_mutex); return 0; } - l = (struct objc_list*)sarray_get_safe (__objc_selector_array, i); - objc_mutex_unlock(__objc_runtime_mutex); + l = (struct objc_list *) sarray_get_safe (__objc_selector_array, i); + objc_mutex_unlock (__objc_runtime_mutex); if (l == 0) return 0; - return (SEL)l->head; + return (SEL) l->head; } /* return selector representing name */ @@ -285,18 +285,17 @@ sel_get_uid (const char *name) /* Get name of selector. If selector is unknown, the empty string "" is returned */ -const char* -sel_get_name (SEL selector) +const char *sel_get_name (SEL selector) { const char *ret; - objc_mutex_lock(__objc_runtime_mutex); - if ((soffset_decode((sidx)selector->sel_id) > 0) - && (soffset_decode((sidx)selector->sel_id) <= __objc_selector_max_index)) + objc_mutex_lock (__objc_runtime_mutex); + if ((soffset_decode ((sidx)selector->sel_id) > 0) + && (soffset_decode ((sidx)selector->sel_id) <= __objc_selector_max_index)) ret = sarray_get_safe (__objc_selector_names, (sidx) selector->sel_id); else ret = 0; - objc_mutex_unlock(__objc_runtime_mutex); + objc_mutex_unlock (__objc_runtime_mutex); return ret; } @@ -308,8 +307,7 @@ sel_is_mapped (SEL selector) } -const char* -sel_get_type (SEL selector) +const char *sel_get_type (SEL selector) { if (selector) return selector->sel_types; @@ -318,7 +316,7 @@ sel_get_type (SEL selector) } /* The uninstalled dispatch table */ -extern struct sarray* __objc_uninstalled_dtable; +extern struct sarray *__objc_uninstalled_dtable; /* Store the passed selector name in the selector record and return its selector value (value returned by sel_get_uid). @@ -331,35 +329,35 @@ SEL __sel_register_typed_name (const char *name, const char *types, struct objc_selector *orig, BOOL is_const) { - struct objc_selector* j; + struct objc_selector *j; sidx i; struct objc_list *l; i = (sidx) hash_value_for_key (__objc_selector_hash, name); if (soffset_decode (i) != 0) { - for (l = (struct objc_list*)sarray_get_safe (__objc_selector_array, i); + for (l = (struct objc_list *) sarray_get_safe (__objc_selector_array, i); l; l = l->tail) { - SEL s = (SEL)l->head; + SEL s = (SEL) l->head; if (types == 0 || s->sel_types == 0) { if (s->sel_types == types) { if (orig) { - orig->sel_id = (void*)i; + orig->sel_id = (void *) i; return orig; } else return s; } } - else if (!strcmp (s->sel_types, types)) + else if (! strcmp (s->sel_types, types)) { if (orig) { - orig->sel_id = (void*)i; + orig->sel_id = (void *) i; return orig; } else @@ -371,32 +369,32 @@ __sel_register_typed_name (const char *name, const char *types, else j = objc_malloc (sizeof (struct objc_selector)); - j->sel_id = (void*)i; + j->sel_id = (void *) i; /* Can we use the pointer or must copy types? Don't copy if NULL */ if ((is_const) || (types == 0)) - j->sel_types = (const char*)types; + j->sel_types = (const char *) types; else { - j->sel_types = (char *) objc_malloc(strlen(types)+1); - strcpy((char *)j->sel_types, types); + j->sel_types = (char *) objc_malloc (strlen (types) + 1); + strcpy ((char *) j->sel_types, types); } - l = (struct objc_list*)sarray_get_safe (__objc_selector_array, i); + l = (struct objc_list *) sarray_get_safe (__objc_selector_array, i); } else { __objc_selector_max_index += 1; - i = soffset_encode(__objc_selector_max_index); + i = soffset_encode (__objc_selector_max_index); if (orig) j = orig; else j = objc_malloc (sizeof (struct objc_selector)); - j->sel_id = (void*)i; + j->sel_id = (void *) i; /* Can we use the pointer or must copy types? Don't copy if NULL */ if ((is_const) || (types == 0)) - j->sel_types = (const char*)types; + j->sel_types = (const char *) types; else { - j->sel_types = (char *) objc_malloc(strlen(types)+1); - strcpy((char *)j->sel_types, types); + j->sel_types = (char *) objc_malloc (strlen (types) + 1); + strcpy ((char *) j->sel_types, types); } l = 0; } @@ -412,18 +410,18 @@ __sel_register_typed_name (const char *name, const char *types, if ((is_const) || (name == 0)) new_name = name; else { - new_name = (char *) objc_malloc(strlen(name)+1); - strcpy((char *)new_name, name); + new_name = (char *) objc_malloc (strlen (name) + 1); + strcpy ((char *) new_name, name); } - l = list_cons ((void*)j, l); + l = list_cons ((void *) j, l); sarray_at_put_safe (__objc_selector_names, i, (void *) new_name); sarray_at_put_safe (__objc_selector_array, i, (void *) l); if (is_new) hash_add (&__objc_selector_hash, (void *) new_name, (void *) i); } - sarray_realloc(__objc_uninstalled_dtable, __objc_selector_max_index+1); + sarray_realloc (__objc_uninstalled_dtable, __objc_selector_max_index + 1); return (SEL) j; } @@ -433,11 +431,11 @@ sel_register_name (const char *name) { SEL ret; - objc_mutex_lock(__objc_runtime_mutex); + objc_mutex_lock (__objc_runtime_mutex); /* Assume that name is not constant static memory and needs to be copied before put into a runtime structure. is_const == NO */ ret = __sel_register_typed_name (name, 0, 0, NO); - objc_mutex_unlock(__objc_runtime_mutex); + objc_mutex_unlock (__objc_runtime_mutex); return ret; } @@ -447,12 +445,11 @@ sel_register_typed_name (const char *name, const char *type) { SEL ret; - objc_mutex_lock(__objc_runtime_mutex); + objc_mutex_lock (__objc_runtime_mutex); /* Assume that name and type are not constant static memory and need to be copied before put into a runtime structure. is_const == NO */ ret = __sel_register_typed_name (name, type, 0, NO); - objc_mutex_unlock(__objc_runtime_mutex); + objc_mutex_unlock (__objc_runtime_mutex); return ret; } - |