From f2f8cc667b790dcd71709cb3a175944d38b1e78a Mon Sep 17 00:00:00 2001 From: Thomas Van Lenten Date: Tue, 3 Nov 2015 10:08:17 -0500 Subject: Keep GTM building after clang r251041 when targeting 10.6 --- AddressBook/GTMABAddressBook.m | 2 +- AppKit/GTMCarbonEvent.h | 2 +- AppKit/GTMWindowSheetController.h | 7 ++++--- AppKit/GTMWindowSheetController.m | 2 +- Foundation/GTMAbstractDOListener.h | 2 +- Foundation/GTMAbstractDOListener.m | 2 +- Foundation/GTMAbstractDOListenerTest.m | 2 +- Foundation/GTMFileSystemKQueue.h | 3 ++- Foundation/GTMFileSystemKQueueTest.m | 2 +- Foundation/GTMLightweightProxy.h | 3 ++- Foundation/GTMLogger+ASL.h | 2 +- Foundation/GTMNSObject+KeyValueObserving.m | 4 ++-- Foundation/GTMNSObject+KeyValueObservingTest.m | 6 +++--- Foundation/GTMSignalHandler.h | 3 ++- Foundation/GTMTransientRootProxy.h | 3 ++- GTMDefines.h | 27 ++++++++++++++++++++++++++ 16 files changed, 52 insertions(+), 20 deletions(-) diff --git a/AddressBook/GTMABAddressBook.m b/AddressBook/GTMABAddressBook.m index 8ddb247..d71aa91 100644 --- a/AddressBook/GTMABAddressBook.m +++ b/AddressBook/GTMABAddressBook.m @@ -52,7 +52,7 @@ typedef struct { @interface GTMABMultiValueEnumerator : NSEnumerator { @private - __weak ABMultiValueRef ref_; // ref_ cached from enumeree_ + GTM_WEAK ABMultiValueRef ref_; // ref_ cached from enumeree_ GTMABMultiValue *enumeree_; unsigned long mutations_; NSUInteger count_; diff --git a/AppKit/GTMCarbonEvent.h b/AppKit/GTMCarbonEvent.h index a234532..364be3a 100644 --- a/AppKit/GTMCarbonEvent.h +++ b/AppKit/GTMCarbonEvent.h @@ -235,7 +235,7 @@ GTM_EXTERN NSUInteger GTMCarbonToCocoaKeyModifiers(UInt32 inCarbonModifiers); // handler we are wrapping // lazily created in the eventHandler method EventHandlerRef eventHandler_; - __weak id delegate_; // Our delegate + GTM_WEAK id delegate_; // Our delegate // Does our delegate respond to the gtm_eventHandler:receivedEvent:handler: // selector? Cached for performance reasons. BOOL delegateRespondsToHandleEvent_; diff --git a/AppKit/GTMWindowSheetController.h b/AppKit/GTMWindowSheetController.h index 7991112..2ef0198 100644 --- a/AppKit/GTMWindowSheetController.h +++ b/AppKit/GTMWindowSheetController.h @@ -17,6 +17,7 @@ // #import +#import "GTMDefines.h" // A class to manage multiple sheets for a window. Use it for tab-style // interfaces, where each tab might need its own sheet. @@ -56,9 +57,9 @@ @interface GTMWindowSheetController : NSObject { @private - __weak NSWindow* window_; - __weak NSView* activeView_; - __weak id delegate_; + GTM_WEAK NSWindow* window_; + GTM_WEAK NSView* activeView_; + GTM_WEAK id delegate_; NSMutableDictionary* sheets_; // NSValue*(NSView*) -> SheetInfo* } diff --git a/AppKit/GTMWindowSheetController.m b/AppKit/GTMWindowSheetController.m index 7cfeaeb..8e2d13c 100644 --- a/AppKit/GTMWindowSheetController.m +++ b/AppKit/GTMWindowSheetController.m @@ -26,7 +26,7 @@ NSWindow* overlayWindow_; // delegate data - __weak id modalDelegate_; + GTM_WEAK id modalDelegate_; SEL didEndSelector_; void* contextInfo_; diff --git a/Foundation/GTMAbstractDOListener.h b/Foundation/GTMAbstractDOListener.h index 38e8db4..104ec05 100644 --- a/Foundation/GTMAbstractDOListener.h +++ b/Foundation/GTMAbstractDOListener.h @@ -35,7 +35,7 @@ @interface GTMAbstractDOListener : NSObject { @protected NSString *registeredName_; - __weak Protocol *protocol_; + GTM_WEAK Protocol *protocol_; NSConnection *connection_; BOOL isRunningInNewThread_; BOOL shouldShutdown_; diff --git a/Foundation/GTMAbstractDOListener.m b/Foundation/GTMAbstractDOListener.m index 0e221a8..4ac69bd 100644 --- a/Foundation/GTMAbstractDOListener.m +++ b/Foundation/GTMAbstractDOListener.m @@ -29,7 +29,7 @@ // message. This is only need on Tiger. #if MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4 @interface GTMReceivePortDelegate : NSObject { - __weak id delegate_; + GTM_WEAK id delegate_; } - (id)initWithDelegate:(id)delegate; - (void)handlePortMessage:(NSPortMessage *)message; diff --git a/Foundation/GTMAbstractDOListenerTest.m b/Foundation/GTMAbstractDOListenerTest.m index d26d4fc..6a5a90a 100644 --- a/Foundation/GTMAbstractDOListenerTest.m +++ b/Foundation/GTMAbstractDOListenerTest.m @@ -57,7 +57,7 @@ enum { @interface TestServer : GTMAbstractDOListener { @private - __weak id delegate_; + GTM_WEAK id delegate_; } - (void)setDelegate:(id)delegate; @end diff --git a/Foundation/GTMFileSystemKQueue.h b/Foundation/GTMFileSystemKQueue.h index a81d433..c167eea 100644 --- a/Foundation/GTMFileSystemKQueue.h +++ b/Foundation/GTMFileSystemKQueue.h @@ -17,6 +17,7 @@ // #import +#import "GTMDefines.h" #import // for kqueue() and kevent and the NOTE_* constants @@ -50,7 +51,7 @@ typedef unsigned int GTMFileSystemKQueueEvents; int fd_; GTMFileSystemKQueueEvents events_; BOOL acrossReplace_; - __weak id target_; + GTM_WEAK id target_; SEL action_; } diff --git a/Foundation/GTMFileSystemKQueueTest.m b/Foundation/GTMFileSystemKQueueTest.m index a8eec37..3919b86 100644 --- a/Foundation/GTMFileSystemKQueueTest.m +++ b/Foundation/GTMFileSystemKQueueTest.m @@ -39,7 +39,7 @@ @interface GTMFSKQTestHelper : NSObject { @private int writes_, renames_, deletes_; - __weak GTMFileSystemKQueue *queue_; + GTM_WEAK GTMFileSystemKQueue *queue_; } @end diff --git a/Foundation/GTMLightweightProxy.h b/Foundation/GTMLightweightProxy.h index 2e2a748..76ef66b 100644 --- a/Foundation/GTMLightweightProxy.h +++ b/Foundation/GTMLightweightProxy.h @@ -17,6 +17,7 @@ // #import +#import "GTMDefines.h" // // GTMLightweightProxy @@ -31,7 +32,7 @@ // @interface GTMLightweightProxy : NSProxy { @private - __weak id representedObject_; + GTM_WEAK id representedObject_; } // Initializes the object to represent |object|. diff --git a/Foundation/GTMLogger+ASL.h b/Foundation/GTMLogger+ASL.h index 87a513d..3b41e68 100644 --- a/Foundation/GTMLogger+ASL.h +++ b/Foundation/GTMLogger+ASL.h @@ -52,7 +52,7 @@ // @interface GTMLogASLWriter : NSObject { @private - __weak Class aslClientClass_; + GTM_WEAK Class aslClientClass_; NSString *facility_; } diff --git a/Foundation/GTMNSObject+KeyValueObserving.m b/Foundation/GTMNSObject+KeyValueObserving.m index 814419b..70f5310 100644 --- a/Foundation/GTMNSObject+KeyValueObserving.m +++ b/Foundation/GTMNSObject+KeyValueObserving.m @@ -62,10 +62,10 @@ @interface GTMKeyValueObservingHelper : NSObject { @private - __weak id observer_; + GTM_WEAK id observer_; SEL selector_; id userInfo_; - __weak id target_; + GTM_WEAK id target_; NSString* keyPath_; } diff --git a/Foundation/GTMNSObject+KeyValueObservingTest.m b/Foundation/GTMNSObject+KeyValueObservingTest.m index be3041b..ba59a96 100644 --- a/Foundation/GTMNSObject+KeyValueObservingTest.m +++ b/Foundation/GTMNSObject+KeyValueObservingTest.m @@ -34,7 +34,7 @@ @interface GTMNSObject_KeyValueObservingTest : GTMTestCase { int32_t count_; NSMutableDictionary *dict_; - __weak NSString *expectedValue_; + GTM_WEAK NSString *expectedValue_; } - (void)observeValueChange:(GTMKeyValueChangeNotification *)notification; @@ -133,8 +133,8 @@ @private id value_; id _value2; - __weak NSArray *value3_; - __weak NSString *value4; + GTM_WEAK NSArray *value3_; + GTM_WEAK NSString *value4; } - (NSString *)value4; @end diff --git a/Foundation/GTMSignalHandler.h b/Foundation/GTMSignalHandler.h index 6297197..ec21507 100644 --- a/Foundation/GTMSignalHandler.h +++ b/Foundation/GTMSignalHandler.h @@ -17,6 +17,7 @@ // #import +#import "GTMDefines.h" // GTMSignalHandler. // @@ -60,7 +61,7 @@ @interface GTMSignalHandler : NSObject { @private int signo_; - __weak id target_; + GTM_WEAK id target_; SEL action_; } diff --git a/Foundation/GTMTransientRootProxy.h b/Foundation/GTMTransientRootProxy.h index b5aa78a..3ebb501 100644 --- a/Foundation/GTMTransientRootProxy.h +++ b/Foundation/GTMTransientRootProxy.h @@ -17,6 +17,7 @@ // #import +#import "GTMDefines.h" // Handle (re-)connecting to a transient root proxy object via DO. // @@ -68,7 +69,7 @@ // @interface GTMTransientRootProxy : NSProxy { @protected - __weak Protocol *protocol_; + GTM_WEAK Protocol *protocol_; NSDistantObject *realProxy_; NSString *registeredName_; diff --git a/GTMDefines.h b/GTMDefines.h index d651bb3..2528d19 100644 --- a/GTMDefines.h +++ b/GTMDefines.h @@ -500,4 +500,31 @@ GTM_EXTERN void _GTMUnitTestDevLog(NSString *format, ...) NS_FORMAT_FUNCTION(1, #endif // DEBUG #endif // GTM_SEL_STRING +#ifndef GTM_WEAK + #if defined(__OBJC_GC__) + // In -fobjc-gc mode, __weak means "a reference not visible to the gargabe + // collector". __weak references are set to zero when their pointee is + // collected. __weak is not needed to prevent cycles because cycles + // are cleaned up fine by the garbage collector. + #define GTM_WEAK __weak + #elif __has_feature(objc_arc_weak) + // With ARC enabled, __weak means a reference that isn't implicitly + // retained. __weak objects are accessed through runtime functions, so + // they are zeroed out, but this requires OS X 10.7+. + // At clang r251041+, ARC-style zeroing weak references even work in + // non-ARC mode. + #define GTM_WEAK __weak + #elif __has_feature(objc_arc) + // ARC, but targeting 10.6 or older, where zeroing weak references don't + // exist. + #define GTM_WEAK __unsafe_unretained + #else + // With manual reference counting, __weak used to be silently ignored. + // clang r251041 gives it the ARC semantics instead. This means they + // now require a deployment target of 10.7, while some clients of GTM + // still target 10.6. In these cases, expand to __unsafe_unretained instead + #define GTM_WEAK + #endif +#endif + #endif // __OBJC__ -- cgit v1.2.3