Differences From Artifact [46b4e85118]:
- File src/runtime/static-instances.m — part of check-in [0509d7a844] at 2019-01-03 19:13:03 on branch trunk — Update copyright (user: js, size: 2663) [annotate] [blame] [check-ins using]
To Artifact [e9f2e9fced]:
- File
src/runtime/static-instances.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: 2836) [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 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | #include <stdio.h> #include <stdlib.h> #import "ObjFW_RT.h" #import "private.h" static struct objc_abi_static_instances **staticInstancesList = NULL; static size_t staticInstancesCount = 0; void objc_init_static_instances(struct objc_abi_symtab *symtab) { struct objc_abi_static_instances **staticInstances; /* Check if the class for a static instance became available */ for (size_t i = 0; i < staticInstancesCount; i++) { Class cls = objc_lookUpClass( staticInstancesList[i]->className); if (cls != Nil) { for (id *instances = staticInstancesList[i]->instances; *instances != nil; instances++) object_setClass(*instances, cls); staticInstancesCount--; if (staticInstancesCount == 0) { free(staticInstancesList); staticInstancesList = NULL; break; } staticInstancesList[i] = staticInstancesList[staticInstancesCount]; staticInstancesList = realloc(staticInstancesList, sizeof(struct objc_abi_static_instances *) * staticInstancesCount); if (staticInstancesList == NULL) OBJC_ERROR("Not enough memory for list of " "static instances!"); /* * We moved the last entry to the current index, * therefore we need to run again for the current index. */ i--; } } staticInstances = (struct objc_abi_static_instances **) symtab->defs[symtab->classDefsCount + symtab->categoryDefsCount]; if (staticInstances == NULL) return; for (; *staticInstances != NULL; staticInstances++) { Class cls = objc_lookUpClass((*staticInstances)->className); if (cls != Nil) { for (id *instances = (*staticInstances)->instances; *instances != nil; instances++) object_setClass(*instances, cls); } else { staticInstancesList = realloc(staticInstancesList, sizeof(struct objc_abi_static_instances *) * (staticInstancesCount + 1)); if (staticInstancesList == NULL) OBJC_ERROR("Not enough memory for list of " "static instances!"); staticInstancesList[staticInstancesCount++] = *staticInstances; } } } void objc_forget_pending_static_instances() { free(staticInstancesList); staticInstancesList = NULL; staticInstancesCount = 0; } |