Differences From Artifact [854568a763]:
- File
tests/OFBlockTests.m
— part of check-in
[dbb706d21e]
at
2016-10-15 13:49:18
on branch trunk
— 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. (user: js, size: 2349) [annotate] [blame] [check-ins using]
To Artifact [d7ee6652ec]:
- File
tests/OFBlockTests.m
— part of check-in
[9dc0755178]
at
2016-10-16 20:01:21
on branch trunk
— OFBlocks: Forward stack block to copy when copied
While at it, also make things thread-safe. (user: js, size: 2589) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
35 36 37 38 39 40 41 | extern void *_NSConcreteMallocBlock; static void (^g)() = ^ {}; static int (^returnStackBlock(void))(void) { | | > > > > > > > > > > > > > > | 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) { __block int i = 42; return Block_copy(^ int { return ++i; }); } static double forwardTest(void) { __block double d; void (^b)(void) = Block_copy(^ { d = 5; }); b(); Block_release(b); return d; } @implementation TestsAppDelegate (OFBlockTests) - (void)blockTests { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; __block int x; void (^s)(void) = ^ { x = 0; }; |
︙ | ︙ | |||
65 66 67 68 69 70 71 | (Class)&_NSConcreteMallocBlock == objc_getClass("OFMallocBlock")) TEST(@"Copying a stack block", (m = [[s copy] autorelease]) && [m class] == objc_getClass("OFMallocBlock") && [m isKindOfClass: [OFBlock class]]) | > > > | | | 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) TEST(@"Copying a stack block and using its copied variable", (v = returnStackBlock()) && v() == 43 && v() == 44 && v() == 45) 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])) |
︙ | ︙ |