Differences From Artifact [cfecc15e99]:
- File src/runtime/dtable.m — part of check-in [0509d7a844] at 2019-01-03 19:13:03 on branch trunk — Update copyright (user: js, size: 4333) [annotate] [blame] [check-ins using]
To Artifact [1fc547de44]:
- File
src/runtime/dtable.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: 4282) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
19 20 21 22 23 24 25 | #include <stdio.h> #include <stdlib.h> #import "ObjFW_RT.h" #import "private.h" | | | | < | < | | | | | | | | | | | | 19 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 | #include <stdio.h> #include <stdlib.h> #import "ObjFW_RT.h" #import "private.h" static struct objc_dtable_level2 *emptyLevel2 = NULL; #ifdef OF_SELUID24 static struct objc_dtable_level3 *emptyLevel3 = NULL; #endif static void init(void) { if ((emptyLevel2 = malloc(sizeof(struct objc_dtable_level2))) == NULL) OBJC_ERROR("Not enough memory to allocate dtable!"); #ifdef OF_SELUID24 if ((emptyLevel3 = malloc(sizeof(struct objc_dtable_level3))) == NULL) OBJC_ERROR("Not enough memory to allocate dtable!"); #endif #ifdef OF_SELUID24 for (uint_fast16_t i = 0; i < 256; i++) { emptyLevel2->buckets[i] = emptyLevel3; emptyLevel3->buckets[i] = (IMP)0; } #else for (uint_fast16_t i = 0; i < 256; i++) emptyLevel2->buckets[i] = (IMP)0; #endif } struct objc_dtable * objc_dtable_new(void) { struct objc_dtable *DTable; #ifdef OF_SELUID24 if (emptyLevel2 == NULL || emptyLevel3 == NULL) init(); #else if (emptyLevel2 == NULL) init(); #endif if ((DTable = malloc(sizeof(struct objc_dtable))) == NULL) OBJC_ERROR("Not enough memory to allocate dtable!"); for (uint_fast16_t i = 0; i < 256; i++) DTable->buckets[i] = emptyLevel2; return DTable; } void objc_dtable_copy(struct objc_dtable *dst, struct objc_dtable *src) { for (uint_fast16_t i = 0; i < 256; i++) { if (src->buckets[i] == emptyLevel2) continue; #ifdef OF_SELUID24 for (uint_fast16_t j = 0; j < 256; j++) { if (src->buckets[i]->buckets[j] == emptyLevel3) continue; for (uint_fast16_t k = 0; k < 256; k++) { IMP obj; uint32_t idx; obj = src->buckets[i]->buckets[j]->buckets[k]; |
︙ | ︙ | |||
123 124 125 126 127 128 129 | uint8_t j = idx >> 8; uint8_t k = idx; #else uint8_t i = idx >> 8; uint8_t j = idx; #endif | | | | | 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 | uint8_t j = idx >> 8; uint8_t k = idx; #else uint8_t i = idx >> 8; uint8_t j = idx; #endif if (dtable->buckets[i] == emptyLevel2) { struct objc_dtable_level2 *level2 = malloc(sizeof(struct objc_dtable_level2)); if (level2 == NULL) OBJC_ERROR("Not enough memory to insert into dtable!"); for (uint_fast16_t l = 0; l < 256; l++) #ifdef OF_SELUID24 level2->buckets[l] = emptyLevel3; #else level2->buckets[l] = (IMP)0; #endif dtable->buckets[i] = level2; } #ifdef OF_SELUID24 if (dtable->buckets[i]->buckets[j] == emptyLevel3) { struct objc_dtable_level3 *level3 = malloc(sizeof(struct objc_dtable_level3)); if (level3 == NULL) OBJC_ERROR("Not enough memory to insert into dtable!"); for (uint_fast16_t l = 0; l < 256; l++) |
︙ | ︙ | |||
164 165 166 167 168 169 170 | #endif } void objc_dtable_free(struct objc_dtable *dtable) { for (uint_fast16_t i = 0; i < 256; i++) { | | | | | | | | | | 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 | #endif } void objc_dtable_free(struct objc_dtable *dtable) { for (uint_fast16_t i = 0; i < 256; i++) { if (dtable->buckets[i] == emptyLevel2) continue; #ifdef OF_SELUID24 for (uint_fast16_t j = 0; j < 256; j++) if (dtable->buckets[i]->buckets[j] != emptyLevel3) free(dtable->buckets[i]->buckets[j]); #endif free(dtable->buckets[i]); } free(dtable); } void objc_dtable_cleanup(void) { if (emptyLevel2 != NULL) free(emptyLevel2); #ifdef OF_SELUID24 if (emptyLevel3 != NULL) free(emptyLevel3); #endif emptyLevel2 = NULL; #ifdef OF_SELUID24 emptyLevel3 = NULL; #endif } |