1/* 2 * Copyright (c) 2010 Apple Inc. All rights reserved. 3 * 4 * @APPLE_LLVM_LICENSE_HEADER@ 5 */ 6 7// test non-GC -release of block-captured objects 8 9// TEST_CONFIG MEM=mrc 10// TEST_CFLAGS -framework Foundation 11 12#import <Foundation/Foundation.h> 13#import <Block_private.h> 14#import "test.h" 15 16int global = 0; 17 18@interface TestObject : NSObject 19@end 20@implementation TestObject 21- (oneway void)release { 22 global = 1; 23 [super release]; 24} 25@end 26 27int main() { 28 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 29 30 TestObject *to = [[TestObject alloc] init]; 31 void (^b)(void) = ^{ printf("to is at %p\n", to); abort(); }; 32 33 // verify that b has a copy/dispose helper 34 struct Block_layout *layout = (struct Block_layout *)(void *)b; 35 if (!(layout->flags & BLOCK_HAS_COPY_DISPOSE)) { 36 fail("Whoops, no copy dispose!"); 37 } 38 struct Block_descriptor_2 *desc = 39 (struct Block_descriptor_2 *)(layout->descriptor + 1); 40 if (!(desc->dispose)) { 41 fail("Whoops, no block dispose helper function!"); 42 } 43 desc->dispose(b); 44 if (global != 1) { 45 fail("Whoops, helper routine didn't release captive object"); 46 } 47 [pool drain]; 48 49 succeed(__FILE__); 50} 51