Differences From Artifact [739d0a98ef]:
- File src/runtime/selector.m — part of check-in [0509d7a844] at 2019-01-03 19:13:03 on branch trunk — Update copyright (user: js, size: 3470) [annotate] [blame] [check-ins using]
To Artifact [6c2deedb05]:
- File
src/runtime/selector.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: 3503) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
31 32 33 34 35 36 37 | # define SEL_SIZE 3 #else # define SEL_MAX 0xFFFF # define SEL_SIZE 2 #endif static struct objc_hashtable *selectors = NULL; | | | | | | | | | | | | 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 | # define SEL_SIZE 3 #else # define SEL_MAX 0xFFFF # define SEL_SIZE 2 #endif static struct objc_hashtable *selectors = NULL; static uint32_t selectorsCount = 0; static struct objc_sparsearray *selectorNames = NULL; static void **freeList = NULL; static size_t freeListCount = 0; void objc_register_selector(struct objc_abi_selector *sel) { struct objc_selector *rsel; const char *name; if (selectorsCount > SEL_MAX) OBJC_ERROR("Out of selector slots!"); if (selectors == NULL) selectors = objc_hashtable_new( objc_hash_string, objc_equal_string, 2); else if ((rsel = objc_hashtable_get(selectors, sel->name)) != NULL) { ((struct objc_selector *)sel)->UID = rsel->UID; return; } if (selectorNames == NULL) selectorNames = objc_sparsearray_new(SEL_SIZE); name = sel->name; rsel = (struct objc_selector *)sel; rsel->UID = selectorsCount++; objc_hashtable_set(selectors, name, rsel); objc_sparsearray_set(selectorNames, (uint32_t)rsel->UID, (void *)name); } SEL sel_registerName(const char *name) { const struct objc_abi_selector *rsel; struct objc_abi_selector *sel; |
︙ | ︙ | |||
84 85 86 87 88 89 90 | if ((sel = malloc(sizeof(struct objc_abi_selector))) == NULL) OBJC_ERROR("Not enough memory to allocate selector!"); if ((sel->name = of_strdup(name)) == NULL) OBJC_ERROR("Not enough memory to allocate selector!"); | | | | | | | | | | | | | | | | | | | | | | 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 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | if ((sel = malloc(sizeof(struct objc_abi_selector))) == NULL) OBJC_ERROR("Not enough memory to allocate selector!"); if ((sel->name = of_strdup(name)) == NULL) OBJC_ERROR("Not enough memory to allocate selector!"); sel->typeEncoding = NULL; if ((freeList = realloc(freeList, sizeof(void *) * (freeListCount + 2))) == NULL) OBJC_ERROR("Not enough memory to allocate selector!"); freeList[freeListCount++] = sel; freeList[freeListCount++] = (char *)sel->name; objc_register_selector(sel); objc_global_mutex_unlock(); return (SEL)sel; } void objc_register_all_selectors(struct objc_abi_symtab *symtab) { struct objc_abi_selector *sel; if (symtab->selectorRefs == NULL) return; for (sel = symtab->selectorRefs; sel->name != NULL; sel++) objc_register_selector(sel); } const char * sel_getName(SEL selector) { const char *ret; objc_global_mutex_lock(); ret = objc_sparsearray_get(selectorNames, (uint32_t)selector->UID); objc_global_mutex_unlock(); return ret; } bool sel_isEqual(SEL selector1, SEL selector2) { return (selector1->UID == selector2->UID); } void objc_unregister_all_selectors(void) { objc_hashtable_free(selectors); objc_sparsearray_free(selectorNames); if (freeList != NULL) { for (size_t i = 0; i < freeListCount; i++) free(freeList[i]); free(freeList); } selectors = NULL; selectorsCount = 0; selectorNames = NULL; freeList = NULL; freeListCount = 0; } |