Conditionally compile __unsafe_unretained

Addresses, and hopefully fixes, issue #77.
This commit is contained in:
Phil Nash 2012-04-28 12:29:52 +01:00
parent 8fdf7f3a09
commit 861a1e79cf
4 changed files with 57 additions and 43 deletions

View File

@ -33,27 +33,29 @@ void arcSafeRelease( NSObject* obj );
id performOptionalSelector( id obj, SEL sel ); id performOptionalSelector( id obj, SEL sel );
#if !CATCH_ARC_ENABLED #if !CATCH_ARC_ENABLED
inline void arcSafeRelease( NSObject* obj ) inline void arcSafeRelease( NSObject* obj )
{ {
[obj release]; [obj release];
} }
inline id performOptionalSelector( id obj, SEL sel ) inline id performOptionalSelector( id obj, SEL sel )
{ {
if( [obj respondsToSelector: sel] ) if( [obj respondsToSelector: sel] )
return [obj performSelector: sel]; return [obj performSelector: sel];
return nil; return nil;
} }
#define CATCH_UNSAFE_UNRETAINED
#else #else
inline void arcSafeRelease( NSObject* ){} inline void arcSafeRelease( NSObject* ){}
inline id performOptionalSelector( id obj, SEL sel ) inline id performOptionalSelector( id obj, SEL sel )
{ {
#pragma clang diagnostic push #pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks" #pragma clang diagnostic ignored "-Warc-performSelector-leaks"
if( [obj respondsToSelector: sel] ) if( [obj respondsToSelector: sel] )
return [obj performSelector: sel]; return [obj performSelector: sel];
#pragma clang diagnostic pop #pragma clang diagnostic pop
return nil; return nil;
} }
#define CATCH_UNSAFE_UNRETAINED __unsafe_unretained
#endif #endif
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@ -171,7 +173,7 @@ namespace Catch
size_t noTestMethods = 0; size_t noTestMethods = 0;
int noClasses = objc_getClassList( NULL, 0 ); int noClasses = objc_getClassList( NULL, 0 );
Class* classes = (__unsafe_unretained Class *)malloc( sizeof(Class) * noClasses); Class* classes = (CATCH_UNSAFE_UNRETAINED Class *)malloc( sizeof(Class) * noClasses);
objc_getClassList( classes, noClasses ); objc_getClassList( classes, noClasses );
for( int c = 0; c < noClasses; c++ ) for( int c = 0; c < noClasses; c++ )

View File

@ -38,6 +38,7 @@
4A63D2C314E454CC00F615CB /* OCTest.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = OCTest.mm; sourceTree = "<group>"; }; 4A63D2C314E454CC00F615CB /* OCTest.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = OCTest.mm; sourceTree = "<group>"; };
4A63D2C414E454CC00F615CB /* TestObj.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TestObj.h; sourceTree = "<group>"; }; 4A63D2C414E454CC00F615CB /* TestObj.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TestObj.h; sourceTree = "<group>"; };
4A63D2C514E454CC00F615CB /* TestObj.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TestObj.m; sourceTree = "<group>"; }; 4A63D2C514E454CC00F615CB /* TestObj.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TestObj.m; sourceTree = "<group>"; };
4AA0D951154C0A7A004B4193 /* catch_objc.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = catch_objc.hpp; path = ../../../include/internal/catch_objc.hpp; sourceTree = "<group>"; };
/* End PBXFileReference section */ /* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */ /* Begin PBXFrameworksBuildPhase section */
@ -55,6 +56,7 @@
4A63D29A14E3C1A900F615CB = { 4A63D29A14E3C1A900F615CB = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
4AA0D94F154C0A63004B4193 /* Catch */,
4A63D2BF14E4544700F615CB /* Foundation.framework */, 4A63D2BF14E4544700F615CB /* Foundation.framework */,
4A63D2A814E3C1A900F615CB /* OCTest */, 4A63D2A814E3C1A900F615CB /* OCTest */,
4A63D2A614E3C1A900F615CB /* Products */, 4A63D2A614E3C1A900F615CB /* Products */,
@ -83,6 +85,14 @@
path = OCTest; path = OCTest;
sourceTree = "<group>"; sourceTree = "<group>";
}; };
4AA0D94F154C0A63004B4193 /* Catch */ = {
isa = PBXGroup;
children = (
4AA0D951154C0A7A004B4193 /* catch_objc.hpp */,
);
name = Catch;
sourceTree = "<group>";
};
/* End PBXGroup section */ /* End PBXGroup section */
/* Begin PBXNativeTarget section */ /* Begin PBXNativeTarget section */

View File

@ -8,7 +8,7 @@
// Distributed under the Boost Software License, Version 1.0. (See accompanying // Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#import <Cocoa/Cocoa.h> #import <Foundation/Foundation.h>
@interface TestObj : NSObject { @interface TestObj : NSObject {

View File

@ -3063,27 +3063,29 @@ void arcSafeRelease( NSObject* obj );
id performOptionalSelector( id obj, SEL sel ); id performOptionalSelector( id obj, SEL sel );
#if !CATCH_ARC_ENABLED #if !CATCH_ARC_ENABLED
inline void arcSafeRelease( NSObject* obj ) inline void arcSafeRelease( NSObject* obj )
{ {
[obj release]; [obj release];
} }
inline id performOptionalSelector( id obj, SEL sel ) inline id performOptionalSelector( id obj, SEL sel )
{ {
if( [obj respondsToSelector: sel] ) if( [obj respondsToSelector: sel] )
return [obj performSelector: sel]; return [obj performSelector: sel];
return nil; return nil;
} }
#define CATCH_UNSAFE_UNRETAINED
#else #else
inline void arcSafeRelease( NSObject* ){} inline void arcSafeRelease( NSObject* ){}
inline id performOptionalSelector( id obj, SEL sel ) inline id performOptionalSelector( id obj, SEL sel )
{ {
#pragma clang diagnostic push #pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks" #pragma clang diagnostic ignored "-Warc-performSelector-leaks"
if( [obj respondsToSelector: sel] ) if( [obj respondsToSelector: sel] )
return [obj performSelector: sel]; return [obj performSelector: sel];
#pragma clang diagnostic pop #pragma clang diagnostic pop
return nil; return nil;
} }
#define CATCH_UNSAFE_UNRETAINED __unsafe_unretained
#endif #endif
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@ -3201,7 +3203,7 @@ namespace Catch
size_t noTestMethods = 0; size_t noTestMethods = 0;
int noClasses = objc_getClassList( NULL, 0 ); int noClasses = objc_getClassList( NULL, 0 );
Class* classes = (__unsafe_unretained Class *)malloc( sizeof(Class) * noClasses); Class* classes = (CATCH_UNSAFE_UNRETAINED Class *)malloc( sizeof(Class) * noClasses);
objc_getClassList( classes, noClasses ); objc_getClassList( classes, noClasses );
for( int c = 0; c < noClasses; c++ ) for( int c = 0; c < noClasses; c++ )