@@ -66,14 +66,13 @@ static void register_selectors(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++) + for (unsigned int i = 0; i < ml->count; i++) objc_register_selector( (struct objc_abi_selector*)&ml->methods[i]); } Class @@ -128,34 +127,28 @@ } 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++) + SEL selector = sel_registerName(method); + + for (struct objc_method_list *ml = cls->isa->methodlist; + ml != NULL; ml = ml->next) + for (unsigned int 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(Class cls) { - struct objc_method_list *ml; - SEL selector; - unsigned int i; - - selector = sel_registerName("load"); - - for (ml = cls->isa->methodlist; ml != NULL; ml = ml->next) - for (i = 0; i < ml->count; i++) + SEL selector = sel_registerName("load"); + + for (struct objc_method_list *ml = cls->isa->methodlist; + ml != NULL; ml = ml->next) + for (size_t i = 0; i < ml->count; i++) if (sel_isEqual((SEL)&ml->methods[i].sel, selector)) return true; return false; } @@ -177,11 +170,10 @@ void objc_update_dtable(Class cls) { struct objc_method_list *ml; struct objc_category **cats; - unsigned int i; if (!(cls->info & OBJC_CLASS_INFO_DTABLE)) return; if (cls->dtable == empty_dtable) @@ -189,36 +181,31 @@ if (cls->superclass != Nil) objc_dtable_copy(cls->dtable, cls->superclass->dtable); for (ml = cls->methodlist; ml != NULL; ml = ml->next) - for (i = 0; i < ml->count; i++) + for (unsigned int i = 0; i < ml->count; i++) objc_dtable_set(cls->dtable, (uint32_t)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; - + for (unsigned int i = 0; cats[i] != NULL; i++) { 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++) + for (unsigned int j = 0; j < ml->count; j++) objc_dtable_set(cls->dtable, (uint32_t)ml->methods[j].sel.uid, ml->methods[j].imp); } } - if (cls->subclass_list != NULL) { - Class *iter; - - for (iter = cls->subclass_list; *iter != NULL; iter++) + if (cls->subclass_list != NULL) + for (Class *iter = cls->subclass_list; *iter != NULL; iter++) objc_update_dtable(*iter); - } } static void add_subclass(Class cls) { @@ -251,12 +238,10 @@ static void update_ivar_offsets(Class cls) { - unsigned i; - if (!(cls->info & OBJC_CLASS_INFO_NEW_ABI)) return; if (cls->instance_size > 0) return; @@ -265,19 +250,19 @@ if (cls->superclass != Nil) { cls->instance_size += cls->superclass->instance_size; if (cls->ivars != NULL) { - for (i = 0; i < cls->ivars->count; i++) { + for (unsigned int i = 0; i < cls->ivars->count; i++) { cls->ivars->ivars[i].offset += cls->superclass->instance_size; *cls->ivar_offsets[i] = cls->ivars->ivars[i].offset; } } } else - for (i = 0; i < cls->ivars->count; i++) + for (unsigned int i = 0; i < cls->ivars->count; i++) *cls->ivar_offsets[i] = cls->ivars->ivars[i].offset; } static void setup_class(Class cls) @@ -368,22 +353,20 @@ } void objc_register_all_classes(struct objc_abi_symtab *symtab) { - uint32_t i; - - for (i = 0; i < symtab->cls_def_cnt; i++) { + for (uint16_t i = 0; i < symtab->cls_def_cnt; i++) { struct objc_abi_class *cls = (struct objc_abi_class*)symtab->defs[i]; register_class(cls); register_selectors(cls); register_selectors(cls->metaclass); } - for (i = 0; i < symtab->cls_def_cnt; i++) { + for (uint16_t i = 0; i < symtab->cls_def_cnt; i++) { Class cls = (Class)symtab->defs[i]; if (has_load(cls)) { setup_class(cls); @@ -402,11 +385,11 @@ } else cls->info |= OBJC_CLASS_INFO_LOADED; } /* Process load queue */ - for (i = 0; i < load_queue_cnt; i++) { + for (size_t i = 0; i < load_queue_cnt; i++) { setup_class(load_queue[i]); if (load_queue[i]->info & OBJC_CLASS_INFO_SETUP) { call_load(load_queue[i]); @@ -482,21 +465,21 @@ } unsigned int objc_getClassList(Class *buf, unsigned int count) { - uint32_t i; unsigned int j; objc_global_mutex_lock(); if (buf == NULL) return classes_cnt; if (classes_cnt < count) count = classes_cnt; - for (i = j = 0; i < classes->size; i++) { + j = 0; + for (uint32_t i = 0; i < classes->size; i++) { void *cls; if (j >= count) { objc_global_mutex_unlock(); return j; @@ -626,19 +609,18 @@ const char* class_getMethodTypeEncoding(Class cls, SEL sel) { struct objc_method_list *ml; struct objc_category **cats; - unsigned int i; if (cls == Nil) return NULL; objc_global_mutex_lock(); for (ml = cls->methodlist; ml != NULL; ml = ml->next) { - for (i = 0; i < ml->count; i++) { + for (unsigned int i = 0; i < ml->count; i++) { if (sel_isEqual((SEL)&ml->methods[i].sel, sel)) { const char *ret = ml->methods[i].sel.types; objc_global_mutex_unlock(); return ret; } @@ -647,11 +629,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++) { + for (unsigned int i = 0; i < ml->count; i++) { if (ml->methods[i].sel.uid == sel->uid) { const char *ret = ml->methods[i].sel.types; objc_global_mutex_unlock(); @@ -673,17 +655,16 @@ IMP class_replaceMethod(Class cls, SEL sel, IMP newimp, const char *types) { struct objc_method_list *ml; struct objc_category **cats; - unsigned int i; IMP oldimp; objc_global_mutex_lock(); for (ml = cls->methodlist; ml != NULL; ml = ml->next) { - for (i = 0; i < ml->count; i++) { + for (unsigned int i = 0; i < ml->count; i++) { if (ml->methods[i].sel.uid == sel->uid) { oldimp = ml->methods[i].imp; ml->methods[i].imp = newimp; objc_update_dtable(cls); @@ -701,11 +682,11 @@ ml = (*cats)->class_methods; else ml = (*cats)->instance_methods; for (; ml != NULL; ml = ml->next) { - for (i = 0; i < ml->count; i++) { + for (unsigned int i = 0; i < ml->count; i++) { if (ml->methods[i].sel.uid == sel->uid) { oldimp = ml->methods[i].imp; ml->methods[i].imp = newimp; @@ -840,16 +821,14 @@ } void objc_unregister_all_classes(void) { - uint32_t i; - if (classes == NULL) return; - for (i = 0; i < classes->size; i++) { + for (uint32_t i = 0; i < classes->size; i++) { if (classes->data[i] != NULL && classes->data[i] != &objc_deleted_bucket) { void *cls = (Class)classes->data[i]->obj; if (cls == Nil || (uintptr_t)cls & 1)