Overview
Comment: | OFBlocks: Forward stack block to copy when copied
While at it, also make things thread-safe. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
9dc0755178ad4276bc45b194581760ef |
User & Date: | js on 2016-10-16 20:01:21 |
Other Links: | manifest | tags |
Context
2016-12-21
| ||
16:22 | Make the readdir_r check an AC_TRY_COMPILE check check-in: 26971c2ea9 user: js tags: trunk | |
2016-10-16
| ||
20:01 | OFBlocks: Forward stack block to copy when copied check-in: 9dc0755178 user: js tags: trunk | |
2016-10-15
| ||
20:47 | Use NSFoundationVersionNumber to detect Foundation check-in: ccd504e68d user: js tags: trunk | |
Changes
Modified src/OFBlock.m from [ec9702862e] to [0d239bd3d6].
︙ | |||
153 154 155 156 157 158 159 | 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 | - + + | static struct { Class isa; } alloc_failed_exception; #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) |
︙ | |||
186 187 188 189 190 191 192 | 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 | - + - + | if (object_getClass((id)block) == (Class)&_NSConcreteMallocBlock) { #ifdef OF_HAVE_ATOMIC_OPS of_atomic_int_inc(&block->flags); #else unsigned hash = SPINLOCK_HASH(block); |
︙ | |||
213 214 215 216 217 218 219 | 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 | - + - + - + | block->descriptor->dispose_helper(block); free(block); } #else unsigned hash = SPINLOCK_HASH(block); |
︙ | |||
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 | 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 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 | + + - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + | 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); |
︙ | |||
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 | 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 | + + + + + + + + + + + + + + + + + + - + + | 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) obj->byref_dispose(obj); free(obj); } #else unsigned hash = SPINLOCK_HASH(obj); OF_ENSURE(of_spinlock_lock(&byrefSpinlocks[hash])); if ((--obj->flags & OF_BLOCK_REFCOUNT_MASK) == 0) { OF_ENSURE(of_spinlock_unlock(&byrefSpinlocks[hash])); if (obj->flags & OF_BLOCK_HAS_COPY_DISPOSE) obj->byref_dispose(obj); free(obj); } OF_ENSURE(of_spinlock_unlock(&byrefSpinlocks[hash])); #endif break; } } @implementation OFBlock + (void)load { #ifndef OF_HAVE_ATOMIC_OPS for (size_t i = 0; i < NUM_SPINLOCKS; i++) |
︙ |
Modified tests/OFBlockTests.m from [854568a763] to [d7ee6652ec].
︙ | |||
35 36 37 38 39 40 41 | 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 | - + + + + + + + + + + + + + + + | extern void *_NSConcreteMallocBlock; static void (^g)() = ^ {}; static int (^returnStackBlock(void))(void) { |
︙ | |||
65 66 67 68 69 70 71 | 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | + + + - - + + | (Class)&_NSConcreteMallocBlock == objc_getClass("OFMallocBlock")) TEST(@"Copying a stack block", (m = [[s copy] autorelease]) && [m class] == objc_getClass("OFMallocBlock") && [m isKindOfClass: [OFBlock class]]) TEST(@"Copying a stack block and referencing its variable", forwardTest() == 5) |
︙ |