Differences From Artifact [35a70014d0]:
- File src/runtime/category.m — part of check-in [0509d7a844] at 2019-01-03 19:13:03 on branch trunk — Update copyright (user: js, size: 3337) [annotate] [blame] [check-ins using]
To Artifact [ca01b62fa9]:
- File
src/runtime/category.m
— part of check-in
[ef6d69931e]
at
2019-02-07 00:46:41
on branch trunk
— Make style consistent between ObjFW and ObjFW_RT
ObjFW_RT used to be a separate project that followed the BSD style, as
it was written in pure C, while ObjFW's style is based on the BSD style
with changes to make it a better fit for Objective-C. This commit
changes ObjFW_RT to use the same style as ObjFW. (user: js, size: 3680) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
20 21 22 23 24 25 26 | #include <stdio.h> #include <stdlib.h> #include <string.h> #import "ObjFW_RT.h" #import "private.h" | | | | | > | | | | | | | | | | | | | | | | | | | | > | | | > > | | | | | | | | | | | | | | | | | | | 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 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 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 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | #include <stdio.h> #include <stdlib.h> #include <string.h> #import "ObjFW_RT.h" #import "private.h" static struct objc_hashtable *categoriesMap = NULL; static void registerSelectors(struct objc_abi_category *category) { for (struct objc_abi_method_list *methodList = category->instanceMethods; methodList != NULL; methodList = methodList->next) for (unsigned int i = 0; i < methodList->count; i++) objc_register_selector((struct objc_abi_selector *) &methodList->methods[i]); for (struct objc_abi_method_list *methodList = category->classMethods; methodList != NULL; methodList = methodList->next) for (unsigned int i = 0; i < methodList->count; i++) objc_register_selector((struct objc_abi_selector *) &methodList->methods[i]); } static void registerCategory(struct objc_abi_category *category) { struct objc_abi_category **categories; Class cls = objc_classname_to_class(category->className, false); if (categoriesMap == NULL) categoriesMap = objc_hashtable_new( objc_hash_string, objc_equal_string, 2); categories = (struct objc_abi_category **)objc_hashtable_get( categoriesMap, category->className); if (categories != NULL) { struct objc_abi_category **newCategories; size_t i; for (i = 0; categories[i] != NULL; i++); if ((newCategories = realloc(categories, (i + 2) * sizeof(struct objc_abi_category *))) == NULL) OBJC_ERROR("Not enough memory for category %s of " "class %s!", category->categoryName, category->className); newCategories[i] = category; newCategories[i + 1] = NULL; objc_hashtable_set(categoriesMap, category->className, newCategories); if (cls != Nil && cls->info & OBJC_CLASS_INFO_SETUP) { objc_update_dtable(cls); objc_update_dtable(cls->isa); } return; } if ((categories = malloc( 2 * sizeof(struct objc_abi_category *))) == NULL) OBJC_ERROR("Not enough memory for category %s of class %s!\n", category->categoryName, category->className); categories[0] = category; categories[1] = NULL; objc_hashtable_set(categoriesMap, category->className, categories); if (cls != Nil && cls->info & OBJC_CLASS_INFO_SETUP) { objc_update_dtable(cls); objc_update_dtable(cls->isa); } } void objc_register_all_categories(struct objc_abi_symtab *symtab) { struct objc_abi_category **categories = (struct objc_abi_category **)symtab->defs + symtab->classDefsCount; for (size_t i = 0; i < symtab->categoryDefsCount; i++) { registerSelectors(categories[i]); registerCategory(categories[i]); } } struct objc_category ** objc_categories_for_class(Class cls) { if (categoriesMap == NULL) return NULL; return (struct objc_category **)objc_hashtable_get(categoriesMap, cls->name); } void objc_unregister_all_categories(void) { if (categoriesMap == NULL) return; for (uint32_t i = 0; i < categoriesMap->size; i++) if (categoriesMap->data[i] != NULL) free((void *)categoriesMap->data[i]->object); objc_hashtable_free(categoriesMap); categoriesMap = NULL; } |