block-weakblockassign.C [plain text]
#import <Foundation/Foundation.h>
int GotCalled = 0;
void objc_assign_weak(id value, id * location) {
++GotCalled;
*location = value;
}
int recovered = 0;
@interface TestObject : NSObject {
}
@end
@implementation TestObject
- (id)retain {
printf("Whoops, retain called!\n");
exit(1);
}
- (void)finalize {
++recovered;
[super finalize];
}
- (void)dealloc {
++recovered;
[super dealloc];
}
@end
void testRR() {
TestObject *to = [[TestObject alloc] init];
__block TestObject *__weak testObject = to;
testObject = [NSObject new]; }
int main(int argc, char *argv[]) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
GotCalled = 0;
testRR();
if (GotCalled == 0) {
printf("didn't call out to support function on assignment\n");
return 1;
}
printf("%s: Success\n", argv[0]);
return 0;
}