Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ set(TESTS
ProtocolCreation.m
ResurrectInDealloc_arc.m
RuntimeTest.m
StackBlockRetain_arc.m
SuperMethodMissing.m
WeakBlock_arc.m
WeakRefLoad.m
Expand Down
37 changes: 37 additions & 0 deletions Test/StackBlockRetain_arc.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include "Test.h"

// A block that captures a stack block copies it when it is copied itself,
// and releases that copy when it goes away. What the captured block
// captured must go with it.

static int deallocs;

@interface Captured : Test
@end
@implementation Captured
- (void)dealloc
{
deallocs++;
}
@end

static id kept;

static void keep(void (^block)(void))
{
kept = ^{ block(); };
}

int main(void)
{
@autoreleasepool
{
Captured *captured = [Captured new];
keep(^{ (void)captured; });
captured = nil;
assert(deallocs == 0);
kept = nil;
}
assert(deallocs == 1);
return 0;
}
4 changes: 4 additions & 0 deletions arc.mm
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,10 @@ static inline id retain(id obj, BOOL isWeak)
Class cls = obj->isa;
if (UNLIKELY(objc_test_class_flag(cls, objc_class_flag_is_block)))
{
if (cls == static_cast<void*>(&_NSConcreteStackBlock))
{
return obj;
}
return Block_copy(obj);
}
if (objc_test_class_flag(cls, objc_class_flag_fast_arc))
Expand Down