Differences From Artifact [067d5d407d]:
- File
src/OFBlock.m
— part of check-in
[4e40a57efa]
at
2017-04-02 15:30:03
on branch trunk
— Make __objc_exec_class() take a void*
This is necessary for ObjC++ with GCC, as otherwise, this generates an
error. Since the objc_abi_module struct is private anyway, there is not
much reason to have the argument of that type. (user: js, size: 12431) [annotate] [blame] [check-ins using]
To Artifact [48fc4cece6]:
- File
src/OFBlock.m
— part of check-in
[4af49a13c3]
at
2017-05-07 20:10:13
on branch trunk
— Small code style change
Casts are now written like types in variable declarations. (user: js, size: 12464) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
39 40 41 42 43 44 45 | typedef struct of_block_byref_t of_block_byref_t; struct of_block_byref_t { Class isa; of_block_byref_t *forwarding; int flags; int size; void (*byref_keep)(void *dest, void *src); | | | 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | typedef struct of_block_byref_t of_block_byref_t; struct of_block_byref_t { Class isa; of_block_byref_t *forwarding; int flags; int size; void (*byref_keep)(void *dest, void *src); void (*byref_dispose)(void *); }; enum { OF_BLOCK_HAS_COPY_DISPOSE = (1 << 25), OF_BLOCK_HAS_CTOR = (1 << 26), OF_BLOCK_IS_GLOBAL = (1 << 28), OF_BLOCK_HAS_STRET = (1 << 29), |
︙ | ︙ | |||
67 68 69 70 71 72 73 | - retain; - (void)release; @end #ifdef OF_OBJFW_RUNTIME /* Begin of ObjC module */ static struct objc_abi_class _NSConcreteStackBlock_metaclass = { | | | | | | | | | | 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 | - retain; - (void)release; @end #ifdef OF_OBJFW_RUNTIME /* Begin of ObjC module */ static struct objc_abi_class _NSConcreteStackBlock_metaclass = { (struct objc_abi_class *)(void *)"OFBlock", "OFBlock", "OFStackBlock", 8, OBJC_CLASS_INFO_METACLASS, sizeof(struct objc_abi_class), NULL, NULL }; struct objc_abi_class _NSConcreteStackBlock = { &_NSConcreteStackBlock_metaclass, "OFBlock", "OFStackBlock", 8, OBJC_CLASS_INFO_CLASS, sizeof(of_block_literal_t), NULL, NULL }; static struct objc_abi_class _NSConcreteGlobalBlock_metaclass = { (struct objc_abi_class *)(void *)"OFBlock", "OFBlock", "OFGlobalBlock", 8, OBJC_CLASS_INFO_METACLASS, sizeof(struct objc_abi_class), NULL, NULL }; struct objc_abi_class _NSConcreteGlobalBlock = { &_NSConcreteGlobalBlock_metaclass, "OFBlock", "OFGlobalBlock", 8, OBJC_CLASS_INFO_CLASS, sizeof(of_block_literal_t), NULL, NULL }; static struct objc_abi_class _NSConcreteMallocBlock_metaclass = { (struct objc_abi_class *)(void *)"OFBlock", "OFBlock", "OFMallocBlock", 8, OBJC_CLASS_INFO_METACLASS, sizeof(struct objc_abi_class), NULL, NULL }; struct objc_abi_class _NSConcreteMallocBlock = { &_NSConcreteMallocBlock_metaclass, "OFBlock", "OFMallocBlock", 8, OBJC_CLASS_INFO_CLASS, sizeof(of_block_literal_t), NULL, NULL }; |
︙ | ︙ | |||
110 111 112 113 114 115 116 | { &_NSConcreteStackBlock, &_NSConcreteGlobalBlock, &_NSConcreteMallocBlock, NULL } }; static struct objc_abi_module module = { | | | | 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | { &_NSConcreteStackBlock, &_NSConcreteGlobalBlock, &_NSConcreteMallocBlock, NULL } }; static struct objc_abi_module module = { 8, sizeof(module), NULL, (struct objc_abi_symtab *)&symtab }; OF_CONSTRUCTOR() { __objc_exec_class(&module); } /* End of ObjC module */ #elif defined(OF_APPLE_RUNTIME) extern Class objc_initializeClassPair(Class, const char *, Class, Class); struct class { struct class *isa, *super_class; const char *name; long version, info, instance_size; struct ivar_list *ivars; struct method_list **methodLists; |
︙ | ︙ | |||
154 155 156 157 158 159 160 | #ifndef OF_HAVE_ATOMIC_OPS # define NUM_SPINLOCKS 8 /* needs to be a power of 2 */ # define SPINLOCK_HASH(p) ((uintptr_t)p >> 4) & (NUM_SPINLOCKS - 1) static of_spinlock_t blockSpinlocks[NUM_SPINLOCKS]; static of_spinlock_t byrefSpinlocks[NUM_SPINLOCKS]; #endif | | | | > | 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | #ifndef OF_HAVE_ATOMIC_OPS # define NUM_SPINLOCKS 8 /* needs to be a power of 2 */ # define SPINLOCK_HASH(p) ((uintptr_t)p >> 4) & (NUM_SPINLOCKS - 1) static of_spinlock_t blockSpinlocks[NUM_SPINLOCKS]; static of_spinlock_t byrefSpinlocks[NUM_SPINLOCKS]; #endif void * _Block_copy(const void *block_) { of_block_literal_t *block = (of_block_literal_t *)block_; if (object_getClass((id)block) == (Class)&_NSConcreteStackBlock) { of_block_literal_t *copy; if ((copy = malloc(block->descriptor->size)) == NULL) { alloc_failed_exception.isa = [OFAllocFailedException class]; @throw (OFAllocFailedException *) &alloc_failed_exception; } memcpy(copy, block, block->descriptor->size); object_setClass((id)copy, (Class)&_NSConcreteMallocBlock); copy->flags++; if (block->flags & OF_BLOCK_HAS_COPY_DISPOSE) |
︙ | ︙ | |||
196 197 198 199 200 201 202 | return block; } void _Block_release(const void *block_) { | | | 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 | return block; } void _Block_release(const void *block_) { of_block_literal_t *block = (of_block_literal_t *)block_; if (object_getClass((id)block) != (Class)&_NSConcreteMallocBlock) return; #ifdef OF_HAVE_ATOMIC_OPS if ((of_atomic_int_dec(&block->flags) & OF_BLOCK_REFCOUNT_MASK) == 0) { if (block->flags & OF_BLOCK_HAS_COPY_DISPOSE) |
︙ | ︙ | |||
237 238 239 240 241 242 243 | OF_BLOCK_FIELD_IS_OBJECT | OF_BLOCK_FIELD_IS_BYREF); if (src_ == NULL) return; switch (flags) { case OF_BLOCK_FIELD_IS_BLOCK: | | | | | | | | 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 | OF_BLOCK_FIELD_IS_OBJECT | OF_BLOCK_FIELD_IS_BYREF); if (src_ == NULL) return; switch (flags) { case OF_BLOCK_FIELD_IS_BLOCK: *(of_block_literal_t **)dst_ = _Block_copy(src_); break; case OF_BLOCK_FIELD_IS_OBJECT: if (!(flags_ & OF_BLOCK_BYREF_CALLER)) *(id *)dst_ = [(id)src_ retain]; break; case OF_BLOCK_FIELD_IS_BYREF:; of_block_byref_t *src = (of_block_byref_t *)src_; of_block_byref_t **dst = (of_block_byref_t **)dst_; src = src->forwarding; if ((src->flags & OF_BLOCK_REFCOUNT_MASK) == 0) { if ((*dst = malloc(src->size)) == NULL) { alloc_failed_exception.isa = [OFAllocFailedException class]; @throw (OFAllocFailedException *) &alloc_failed_exception; } memcpy(*dst, src, src->size); (*dst)->flags = ((*dst)->flags & ~OF_BLOCK_REFCOUNT_MASK) | 1; (*dst)->forwarding = *dst; if (src->flags & OF_BLOCK_HAS_COPY_DISPOSE) src->byref_keep(*dst, src); #ifdef OF_HAVE_ATOMIC_OPS if (!of_atomic_ptr_cmpswap((void **)&src->forwarding, src, *dst)) { src->byref_dispose(*dst); free(*dst); *dst = src->forwarding; } #else |
︙ | ︙ | |||
321 322 323 324 325 326 327 | _Block_release(obj_); break; case OF_BLOCK_FIELD_IS_OBJECT: if (!(flags_ & OF_BLOCK_BYREF_CALLER)) [(id)obj_ release]; break; case OF_BLOCK_FIELD_IS_BYREF:; | | | 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 | _Block_release(obj_); break; case OF_BLOCK_FIELD_IS_OBJECT: if (!(flags_ & OF_BLOCK_BYREF_CALLER)) [(id)obj_ release]; break; case OF_BLOCK_FIELD_IS_BYREF:; of_block_byref_t *obj = (of_block_byref_t *)obj_; obj = obj->forwarding; #ifdef OF_HAVE_ATOMIC_OPS if ((of_atomic_int_dec(&obj->flags) & OF_BLOCK_REFCOUNT_MASK) == 0) { if (obj->flags & OF_BLOCK_HAS_COPY_DISPOSE) |
︙ | ︙ | |||
430 431 432 433 434 435 436 | } - init { OF_INVALID_INIT_METHOD } | | > > > > > > | | | | > < < < < < < < | | 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 | } - init { OF_INVALID_INIT_METHOD } - (void *)allocMemoryWithSize: (size_t)size { OF_UNRECOGNIZED_SELECTOR } - (void *)allocMemoryWithSize: (size_t)size count: (size_t)count { OF_UNRECOGNIZED_SELECTOR } - (void *)resizeMemory: (void *)ptr size: (size_t)size { OF_UNRECOGNIZED_SELECTOR } - (void *)resizeMemory: (void *)ptr size: (size_t)size count: (size_t)count { OF_UNRECOGNIZED_SELECTOR } - (void)freeMemory: (void *)ptr { OF_UNRECOGNIZED_SELECTOR } - retain { if (object_getClass(self) == (Class)&_NSConcreteMallocBlock) |
︙ | ︙ | |||
483 484 485 486 487 488 489 | return self; } - (unsigned int)retainCount { if (object_getClass(self) == (Class)&_NSConcreteMallocBlock) | | | 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 | return self; } - (unsigned int)retainCount { if (object_getClass(self) == (Class)&_NSConcreteMallocBlock) return ((of_block_literal_t *)self)->flags & OF_BLOCK_REFCOUNT_MASK; return OF_RETAIN_COUNT_MAX; } - (void)release { |
︙ | ︙ |