Overview
Comment: | Correctly call load. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | runtime |
Files: | files | file ages | folders |
SHA3-256: |
d13674c4c9a60512b19912e37ac08d34 |
User & Date: | js on 2012-04-18 18:41:01 |
Other Links: | branch diff | manifest | tags |
Context
2012-04-18
| ||
19:03 | Fix forwarding on AMD64. check-in: 895b9e3cb6 user: js tags: runtime | |
18:41 | Correctly call load. check-in: d13674c4c9 user: js tags: runtime | |
18:00 | Split OBJC_CLASS_INFO_INITIALIZED. check-in: 5a719c9b1f user: js tags: runtime | |
Changes
Modified src/runtime/class.m from [106999ef41] to [93558a0a33].
︙ | ︙ | |||
22 23 24 25 26 27 28 29 30 31 32 33 34 35 | #include <assert.h> #import "runtime.h" #import "runtime-private.h" static struct objc_hashtable *classes = NULL; static void register_class(Class cls) { if (classes == NULL) classes = objc_hashtable_alloc(2); | > > | 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | #include <assert.h> #import "runtime.h" #import "runtime-private.h" static struct objc_hashtable *classes = NULL; static Class *load_queue = NULL; static size_t load_queue_cnt = 0; static void register_class(Class cls) { if (classes == NULL) classes = objc_hashtable_alloc(2); |
︙ | ︙ | |||
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | unsigned int i; for (ml = cls->methodlist; ml != NULL; ml = ml->next) for (i = 0; i < ml->count; i++) objc_register_selector( (struct objc_abi_selector*)&ml->methods[i]); } static BOOL has_load(struct objc_abi_class *cls) { struct objc_abi_method_list *ml; unsigned int i; for (ml = cls->methodlist; ml != NULL; ml = ml->next) for (i = 0; i < ml->count; i++) if (!strcmp(ml->methods[i].name, "load")) return YES; return NO; } void objc_update_dtable(Class cls) { struct objc_method_list *ml; struct objc_category **cats; struct objc_sparsearray *dtable; | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | unsigned int i; for (ml = cls->methodlist; ml != NULL; ml = ml->next) for (i = 0; i < ml->count; i++) objc_register_selector( (struct objc_abi_selector*)&ml->methods[i]); } static void call_method(Class cls, const char *method) { struct objc_method_list *ml; SEL selector; unsigned int i; selector = sel_registerName(method); for (ml = cls->isa->methodlist; ml != NULL; ml = ml->next) for (i = 0; i < ml->count; i++) if (sel_isEqual((SEL)&ml->methods[i].sel, selector)) ((void(*)(id, SEL))ml->methods[i].imp)(cls, selector); } static BOOL has_load(struct objc_abi_class *cls) { struct objc_abi_method_list *ml; unsigned int i; for (ml = cls->methodlist; ml != NULL; ml = ml->next) for (i = 0; i < ml->count; i++) if (!strcmp(ml->methods[i].name, "load")) return YES; return NO; } static void call_load(Class cls) { if (cls->info & OBJC_CLASS_INFO_LOADED) return; if (cls->superclass != Nil) call_load(cls->superclass); call_method(cls, "load"); cls->info |= OBJC_CLASS_INFO_LOADED; } void objc_update_dtable(Class cls) { struct objc_method_list *ml; struct objc_category **cats; struct objc_sparsearray *dtable; |
︙ | ︙ | |||
102 103 104 105 106 107 108 | cls->dtable = dtable; if (cls->subclass_list != NULL) for (i = 0; cls->subclass_list[i] != NULL; i++) objc_update_dtable(cls->subclass_list[i]); } | < < < < < < < < < < < < < < < < < < < < < < < < < < < | 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | cls->dtable = dtable; if (cls->subclass_list != NULL) for (i = 0; cls->subclass_list[i] != NULL; i++) objc_update_dtable(cls->subclass_list[i]); } static void add_subclass(Class cls) { size_t i; if (cls->superclass->subclass_list == NULL) { if ((cls->superclass->subclass_list = |
︙ | ︙ | |||
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 | objc_update_dtable(cls); objc_update_dtable(cls->isa); cls->info |= OBJC_CLASS_INFO_SETUP; cls->isa->info |= OBJC_CLASS_INFO_SETUP; } inline Class objc_classname_to_class(const char *name) { Class c; if (classes == NULL) return Nil; objc_global_mutex_lock(); c = (Class)objc_hashtable_get(classes, name); objc_global_mutex_unlock(); return c; } | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > < < < < < < < < < < < < < < < < | 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 | objc_update_dtable(cls); objc_update_dtable(cls->isa); cls->info |= OBJC_CLASS_INFO_SETUP; cls->isa->info |= OBJC_CLASS_INFO_SETUP; } void objc_register_all_classes(struct objc_abi_symtab *symtab) { size_t i; for (i = 0; i < symtab->cls_def_cnt; i++) register_class((Class)symtab->defs[i]); for (i = 0; i < symtab->cls_def_cnt; i++) { struct objc_abi_class *cls; BOOL load; cls = (struct objc_abi_class*)symtab->defs[i]; load = has_load(cls->metaclass); register_selectors(cls); register_selectors(cls->metaclass); if (load) { Class cls_ = (Class)cls; setup_class(cls_); if (cls_->info & OBJC_CLASS_INFO_SETUP) call_load(cls_); else { if (load_queue == NULL) load_queue = malloc(sizeof(Class)); else load_queue = realloc(load_queue, sizeof(Class) * (load_queue_cnt + 1)); if (load_queue == NULL) ERROR("Not enough memory for load " "queue!"); load_queue[load_queue_cnt++] = cls_; } } } /* Process load queue */ for (i = 0; i < load_queue_cnt; i++) { setup_class(load_queue[i]); if (load_queue[i]->info & OBJC_CLASS_INFO_LOADED) { call_load(load_queue[i]); load_queue_cnt--; if (load_queue_cnt == 0) { free(load_queue); load_queue = NULL; continue; } load_queue[i] = load_queue[load_queue_cnt]; load_queue = realloc(load_queue, sizeof(Class) * load_queue_cnt); if (load_queue == NULL) ERROR("Not enough memory for load queue!"); } } } inline Class objc_classname_to_class(const char *name) { Class c; if (classes == NULL) return Nil; objc_global_mutex_lock(); c = (Class)objc_hashtable_get(classes, name); objc_global_mutex_unlock(); return c; } inline Class objc_lookup_class(const char *name) { Class cls = objc_classname_to_class(name); if (cls == NULL) return Nil; |
︙ | ︙ | |||
250 251 252 253 254 255 256 | return Nil; } /* Set it first to prevent calling it recursively */ cls->info |= OBJC_CLASS_INFO_INITIALIZED; cls->isa->info |= OBJC_CLASS_INFO_INITIALIZED; | | | 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 | return Nil; } /* Set it first to prevent calling it recursively */ cls->info |= OBJC_CLASS_INFO_INITIALIZED; cls->isa->info |= OBJC_CLASS_INFO_INITIALIZED; call_method(cls, "initialize"); objc_global_mutex_unlock(); return cls; } Class |
︙ | ︙ |