block-implicit-byref.C [plain text]
#import <Foundation/Foundation.h>
void * _NSConcreteStackBlock;
enum {
BLOCK_NEEDS_FREE = (1 << 24),
BLOCK_HAS_COPY_DISPOSE = (1 << 25),
BLOCK_NO_COPY = (1 << 26), BLOCK_IS_GC = (1 << 27),
};
struct Block_basic {
void *isa;
int Block_flags; int Block_size; void (*Block_invoke)(void *);
void (*Block_copy)(void *dst, void *src);
void (*Block_dispose)(void *);
};
@interface TestObject : NSObject {
@public
id aSlot;
}
- (int) testVerbosely:(int)verbose;
@end
@implementation TestObject
- (int) testVerbosely:(int)verbose
{
aSlot = [[NSObject alloc] init];
void (^myBlock)(void) = ^{
printf("[aSlot retainCount] == %d\n", (int)[aSlot retainCount]);
};
struct Block_basic *basic = (struct Block_basic *)(void *)myBlock;
if (basic->Block_flags & BLOCK_NO_COPY)
abort ();
return 0;
}
@end
int main(int argc, char *argv[]) {
TestObject *to = [[TestObject alloc] init];
[to testVerbosely:1];
return 0;
}