diff --git a/Test/AssociatedObject.m b/Test/AssociatedObject.m new file mode 100644 index 0000000..cd9464e --- /dev/null +++ b/Test/AssociatedObject.m @@ -0,0 +1,26 @@ +#include "Test.h" + +static BOOL deallocCalled = NO; +static const char* objc_setAssociatedObjectKey = "objc_setAssociatedObjectKey"; + +@interface Associated : Test +@end + +@implementation Associated +-(void) dealloc +{ + deallocCalled = YES; + [super dealloc]; +} +@end + +int main(void) +{ + @autoreleasepool { + Associated *object = [Associated new]; + Test *holder = [[Test new] autorelease]; + objc_setAssociatedObject(object, &objc_setAssociatedObjectKey, holder, OBJC_ASSOCIATION_RETAIN); + [object release]; + } + assert(deallocCalled); +} diff --git a/Test/CMakeLists.txt b/Test/CMakeLists.txt index 2bace1a..7f69002 100644 --- a/Test/CMakeLists.txt +++ b/Test/CMakeLists.txt @@ -7,6 +7,7 @@ set(TESTS #alignTest.m AllocatePair.m + AssociatedObject.m BlockImpTest.m BlockTest_arc.m BoxedForeignException.m diff --git a/Test/Test.h b/Test/Test.h index 1288573..8647985 100644 --- a/Test/Test.h +++ b/Test/Test.h @@ -1,4 +1,5 @@ #import "../objc/runtime.h" +#import "../objc/objc-arc.h" #ifdef NDEBUG #undef NDEBUG #endif @@ -14,7 +15,7 @@ __attribute__((objc_root_class)) @interface Test { id isa; } @end @implementation Test -+ (id)class { return self; } ++ (Class)class { return self; } + (id)new { return class_createInstance(self, 0); @@ -23,4 +24,27 @@ __attribute__((objc_root_class)) { object_dispose(self); } +- (id)autorelease +{ + return objc_autorelease(self); +} +- (id)retain +{ + return objc_retain(self); +} +- (void)release +{ + objc_release(self); +} +- (void)_ARCCompliantRetainRelease {} +@end + +@interface NSAutoreleasePool : Test +@end +@implementation NSAutoreleasePool +- (void)_ARCCompatibleAutoreleasePool {} ++ (void)addObject:(id)anObject +{ + objc_autorelease(anObject); +} @end