Index: src/runtime/category.m ================================================================== --- src/runtime/category.m +++ src/runtime/category.m @@ -103,17 +103,17 @@ register_selectors(cats[i]); register_category(cats[i]); } } -struct objc_abi_category** +struct objc_category** objc_categories_for_class(Class cls) { if (categories == NULL) return NULL; - return (struct objc_abi_category**)objc_hashtable_get(categories, + return (struct objc_category**)objc_hashtable_get(categories, cls->name); } void objc_free_all_categories(void) Index: src/runtime/class.m ================================================================== --- src/runtime/class.m +++ src/runtime/class.m @@ -68,12 +68,12 @@ } void objc_update_dtable(Class cls) { - struct objc_abi_method_list *ml; - struct objc_abi_category **cats; + struct objc_method_list *ml; + struct objc_category **cats; struct objc_sparsearray *dtable; unsigned int i; if (cls->superclass != Nil) dtable = objc_sparsearray_copy(cls->superclass->dtable); @@ -80,12 +80,12 @@ else dtable = objc_sparsearray_new(); for (ml = cls->methodlist; ml != NULL; ml = ml->next) for (i = 0; i < ml->count; i++) - objc_sparsearray_set(dtable, (uint32_t) - (uintptr_t)ml->methods[i].name, ml->methods[i].imp); + objc_sparsearray_set(dtable, + ml->methods[i].sel.uid, ml->methods[i].imp); if ((cats = objc_categories_for_class(cls)) != NULL) { for (i = 0; cats[i] != NULL; i++) { unsigned int j; @@ -92,12 +92,12 @@ ml = (cls->info & OBJC_CLASS_INFO_CLASS ? cats[i]->instance_methods : cats[i]->class_methods); for (; ml != NULL; ml = ml->next) for (j = 0; j < ml->count; j++) - objc_sparsearray_set(dtable, (uint32_t) - (uintptr_t)ml->methods[j].name, + objc_sparsearray_set(dtable, + (uint32_t)ml->methods[j].sel.uid, ml->methods[j].imp); } } if (cls->dtable != NULL) @@ -291,20 +291,20 @@ } const char* objc_get_type_encoding(Class cls, SEL sel) { - struct objc_abi_method_list *ml; - struct objc_abi_category **cats; + struct objc_method_list *ml; + struct objc_category **cats; unsigned int i; objc_global_mutex_lock(); for (ml = cls->isa->methodlist; ml != NULL; ml = ml->next) { for (i = 0; i < ml->count; i++) { - if ((uintptr_t)ml->methods[i].name == sel->uid) { - const char *ret = ml->methods[i].types; + if (ml->methods[i].sel.uid == sel->uid) { + const char *ret = ml->methods[i].sel.types; objc_global_mutex_unlock(); return ret; } } } @@ -312,14 +312,14 @@ if ((cats = objc_categories_for_class(cls)) != NULL) { for (; *cats != NULL; cats++) { for (ml = (*cats)->class_methods; ml != NULL; ml = ml->next) { for (i = 0; i < ml->count; i++) { - if ((uintptr_t)ml->methods[i].name == + if (ml->methods[i].sel.uid == sel->uid) { const char *ret = - ml->methods[i].types; + ml->methods[i].sel.types; objc_global_mutex_unlock(); return ret; } } } @@ -332,21 +332,21 @@ } IMP objc_replace_class_method(Class cls, SEL sel, IMP newimp) { - struct objc_abi_method_list *ml; - struct objc_abi_category **cats; + struct objc_method_list *ml; + struct objc_category **cats; unsigned int i; BOOL replaced = NO; IMP oldimp = NULL; objc_global_mutex_lock(); for (ml = cls->isa->methodlist; ml != NULL; ml = ml->next) { for (i = 0; i < ml->count; i++) { - if ((uintptr_t)ml->methods[i].name == sel->uid) { + if (ml->methods[i].sel.uid == sel->uid) { oldimp = ml->methods[i].imp; ml->methods[i].imp = newimp; replaced = YES; break; } @@ -356,11 +356,11 @@ if ((cats = objc_categories_for_class(cls)) != NULL) { for (; *cats != NULL; cats++) { for (ml = (*cats)->class_methods; ml != NULL; ml = ml->next) { for (i = 0; i < ml->count; i++) { - if ((uintptr_t)ml->methods[i].name == + if (ml->methods[i].sel.uid == sel->uid) { oldimp = ml->methods[i].imp; ml->methods[i].imp = newimp; replaced = YES; break; @@ -370,18 +370,18 @@ } } if (!replaced) { /* FIXME: We need a way to free this at objc_exit() */ - if ((ml = malloc(sizeof(struct objc_abi_method_list))) == NULL) + if ((ml = malloc(sizeof(struct objc_method_list))) == NULL) ERROR("Not enough memory to replace method!"); ml->next = cls->isa->methodlist; ml->count = 1; - ml->methods[0].name = (const char*)sel->uid; + ml->methods[0].sel.uid = sel->uid; /* FIXME: We need to get the type from a superclass */ - ml->methods[0].types = sel->types; + ml->methods[0].sel.types = sel->types; ml->methods[0].imp = newimp; cls->isa->methodlist = ml; } @@ -393,21 +393,21 @@ } IMP objc_replace_instance_method(Class cls, SEL sel, IMP newimp) { - struct objc_abi_method_list *ml; - struct objc_abi_category **cats; + struct objc_method_list *ml; + struct objc_category **cats; unsigned int i; BOOL replaced = NO; IMP oldimp = NULL; objc_global_mutex_lock(); for (ml = cls->methodlist; ml != NULL; ml = ml->next) { for (i = 0; i < ml->count; i++) { - if ((uintptr_t)ml->methods[i].name == sel->uid) { + if (ml->methods[i].sel.uid == sel->uid) { oldimp = ml->methods[i].imp; ml->methods[i].imp = newimp; replaced = YES; break; } @@ -417,11 +417,11 @@ if ((cats = objc_categories_for_class(cls)) != NULL) { for (; *cats != NULL; cats++) { for (ml = (*cats)->instance_methods; ml != NULL; ml = ml->next) { for (i = 0; i < ml->count; i++) { - if ((uintptr_t)ml->methods[i].name == + if (ml->methods[i].sel.uid == sel->uid) { oldimp = ml->methods[i].imp; ml->methods[i].imp = newimp; replaced = YES; break; @@ -431,18 +431,18 @@ } } if (!replaced) { /* FIXME: We need a way to free this at objc_exit() */ - if ((ml = malloc(sizeof(struct objc_abi_method_list))) == NULL) + if ((ml = malloc(sizeof(struct objc_method_list))) == NULL) ERROR("Not enough memory to replace method!"); ml->next = cls->methodlist; ml->count = 1; - ml->methods[0].name = (const char*)sel->uid; + ml->methods[0].sel.uid = sel->uid; /* FIXME: We need to get the type from a superclass */ - ml->methods[0].types = sel->types; + ml->methods[0].sel.types = sel->types; ml->methods[0].imp = newimp; cls->methodlist = ml; } Index: src/runtime/protocol.m ================================================================== --- src/runtime/protocol.m +++ src/runtime/protocol.m @@ -22,12 +22,12 @@ #import "runtime-private.h" @implementation Protocol - (BOOL)_isImplementedByClass: (Class)cls { - struct objc_abi_protocol_list *pl; - struct objc_abi_category **cats; + struct objc_protocol_list *pl; + struct objc_category **cats; long i, j; objc_global_mutex_lock(); for (pl = cls->protocols; pl != NULL; pl = pl->next) { Index: src/runtime/runtime-private.h ================================================================== --- src/runtime/runtime-private.h +++ src/runtime/runtime-private.h @@ -55,11 +55,11 @@ struct objc_abi_category { const char *category_name; const char *class_name; struct objc_abi_method_list *instance_methods; struct objc_abi_method_list *class_methods; - struct objc_abi_protocol_list *protocols; + struct objc_protocol_list *protocols; }; struct objc_abi_super { id self; Class class; @@ -73,16 +73,10 @@ struct objc_abi_method_description_list { int count; struct objc_abi_method_description list[1]; }; -struct objc_abi_protocol_list { - struct objc_abi_protocol_list *next; - long count; - Protocol *list[1]; -}; - struct objc_abi_static_instances { const char *class_name; id instances[1]; }; @@ -124,19 +118,25 @@ struct objc_sparsearray_level3 { const void *buckets[256]; BOOL empty; }; + +enum objc_abi_class_info { + OBJC_CLASS_INFO_CLASS = 0x01, + OBJC_CLASS_INFO_METACLASS = 0x02, + OBJC_CLASS_INFO_INITIALIZED = 0x04 +}; typedef struct { of_mutex_t mutex; of_thread_t owner; int count; } objc_mutex_t; extern void objc_register_all_categories(struct objc_abi_symtab*); -extern struct objc_abi_category** objc_categories_for_class(Class); +extern struct objc_category** objc_categories_for_class(Class); extern void objc_free_all_categories(void); extern void objc_update_dtable(Class); extern void objc_register_all_classes(struct objc_abi_symtab*); extern Class objc_classname_to_class(const char*); extern void objc_free_all_classes(void); Index: src/runtime/runtime.h ================================================================== --- src/runtime/runtime.h +++ src/runtime/runtime.h @@ -45,15 +45,15 @@ const char *name; unsigned long version; unsigned long info; unsigned long instance_size; void *ivars; - struct objc_abi_method_list *methodlist; + struct objc_method_list *methodlist; struct objc_sparsearray *dtable; Class *subclass_list; void *sibling_class; - struct objc_abi_protocol_list *protocols; + struct objc_protocol_list *protocols; void *gc_object_type; unsigned long abi_version; void *ivar_offsets; void *properties; }; @@ -65,14 +65,33 @@ struct objc_selector { uintptr_t uid; const char *types; }; -enum objc_abi_class_info { - OBJC_CLASS_INFO_CLASS = 0x01, - OBJC_CLASS_INFO_METACLASS = 0x02, - OBJC_CLASS_INFO_INITIALIZED = 0x04 +struct objc_method { + struct objc_selector sel; + IMP imp; +}; + +struct objc_method_list { + struct objc_method_list *next; + unsigned int count; + struct objc_method methods[1]; +}; + +struct objc_category { + const char *category_name; + const char *class_name; + struct objc_method_list *instance_methods; + struct objc_method_list *class_methods; + struct objc_protocol_list *protocols; +}; + +struct objc_protocol_list { + struct objc_protocol_list *next; + long count; + Protocol *list[1]; }; #define Nil (Class)0 #define nil (id)0 #define YES (BOOL)1