Overview
Comment: | OFBlock: Set (*dst)->forwarding after memcpy()
Setting it before the memcpy() meant it was effectively a nop. This also improves on the tests to catch this in the future. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
dbb706d21e6805c1755cf6dca3f6c547 |
User & Date: | js on 2016-10-15 13:49:18 |
Other Links: | manifest | tags |
Context
2016-10-15
| ||
20:47 | Use NSFoundationVersionNumber to detect Foundation check-in: ccd504e68d user: js tags: trunk | |
13:49 | OFBlock: Set (*dst)->forwarding after memcpy() check-in: dbb706d21e user: js tags: trunk | |
2016-10-09
| ||
16:04 | Add three missing #include <inttypes.h> check-in: 1b90782e78 user: js tags: trunk | |
Changes
Modified src/OFBlock.m from [a5bedf0289] to [ec9702862e].
︙ | ︙ | |||
257 258 259 260 261 262 263 | if ((*dst = malloc(src->size)) == NULL) { alloc_failed_exception.isa = [OFAllocFailedException class]; @throw (OFAllocFailedException*) &alloc_failed_exception; } | > > | < < | 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 | if ((*dst = malloc(src->size)) == NULL) { alloc_failed_exception.isa = [OFAllocFailedException class]; @throw (OFAllocFailedException*) &alloc_failed_exception; } memcpy(*dst, src, src->size); if (src == src->forwarding) (*dst)->forwarding = *dst; if (src->flags & OF_BLOCK_HAS_COPY_DISPOSE) src->byref_keep(*dst, src); } else *dst = src; (*dst)->flags++; |
︙ | ︙ |
Modified tests/OFBlockTests.m from [9b26ed0393] to [854568a763].
︙ | ︙ | |||
31 32 33 34 35 36 37 38 39 40 41 42 43 | static OFString *module = @"OFBlock"; extern void *_NSConcreteStackBlock; extern void *_NSConcreteGlobalBlock; extern void *_NSConcreteMallocBlock; static void (^g)() = ^ {}; @implementation TestsAppDelegate (OFBlockTests) - (void)blockTests { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; __block int x; | > > > > > > > > | | > > > > | 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 | static OFString *module = @"OFBlock"; extern void *_NSConcreteStackBlock; extern void *_NSConcreteGlobalBlock; extern void *_NSConcreteMallocBlock; static void (^g)() = ^ {}; static int (^returnStackBlock(void))(void) { __block int i = 0; return Block_copy(^ int { return ++i; }); } @implementation TestsAppDelegate (OFBlockTests) - (void)blockTests { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; __block int x; void (^s)(void) = ^ { x = 0; }; void (^m)(void); int (^v)(void); TEST(@"Class of stack block", (Class)&_NSConcreteStackBlock == objc_getClass("OFStackBlock") && [s isKindOfClass: [OFBlock class]]) TEST(@"Class of global block", (Class)&_NSConcreteGlobalBlock == objc_getClass("OFGlobalBlock") && [g isKindOfClass: [OFBlock class]]) TEST(@"Class of a malloc block", (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 using its variable", (v = returnStackBlock()) && v() == 1 && v() == 2 && v() == 3) TEST(@"Copying a global block", (id)g == [[g copy] autorelease]) TEST(@"Copying a malloc block", (id)m == [m copy] && [m retainCount] == 2) TEST(@"Autorelease a stack block", R([s autorelease])) |
︙ | ︙ |