From 8c536f5f8d9bc831cee224876ac7d883d2328d80 Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Mon, 17 Sep 2012 11:53:49 -0700 Subject: [PATCH] Refactoring macros for dispatch_release/retain fixes Fixing macro for changed method signature for imp_implementationWithBlock(), which actually depends on Xcode version (and thus a check for either __IPHONE_6_0 or __MAC_10_8 to be defined,regardless of the deployment target --- AFNetworking/AFHTTPClient.m | 23 +++++----------- AFNetworking/AFHTTPRequestOperation.m | 38 ++++++++++----------------- 2 files changed, 20 insertions(+), 41 deletions(-) diff --git a/AFNetworking/AFHTTPClient.m b/AFNetworking/AFHTTPClient.m index d4f1999..fe18b2c 100644 --- a/AFNetworking/AFHTTPClient.m +++ b/AFNetworking/AFHTTPClient.m @@ -40,20 +40,10 @@ #import #endif -// Does ARC support support GCD objects? -// It does if the minimum deployment target is iOS 6+ or Mac OS X 8+ -#if TARGET_OS_IPHONE -#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 60000 // iOS 6.0 or later -#define NEEDS_DISPATCH_RETAIN_RELEASE 0 -#else // iOS 5.X or earlier -#define NEEDS_DISPATCH_RETAIN_RELEASE 1 -#endif -#else -#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1080 // Mac OS X 10.8 or later -#define NEEDS_DISPATCH_RETAIN_RELEASE 0 -#else -#define NEEDS_DISPATCH_RETAIN_RELEASE 1 // Mac OS X 10.7 or earlier -#endif +// Workaround for management of dispatch_retain() / dispatch_release() by ARC with iOS 6 / Mac OS X 10.8 +#if (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && (!defined(__IPHONE_6_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_6_0)) || \ + (defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && (!defined(__MAC_10_8) || __MAC_OS_X_VERSION_MIN_REQUIRED < __MAC_10_8)) +#define AF_DISPATCH_RETAIN_RELEASE 1 #endif @interface AFMultipartFormData : NSObject @@ -338,8 +328,7 @@ static const void * AFNetworkReachabilityRetainCallback(const void *info) { return (__bridge_retained const void *)([(__bridge AFNetworkReachabilityStatusBlock)info copy]); } -static void AFNetworkReachabilityReleaseCallback(const void *info) { -} +static void AFNetworkReachabilityReleaseCallback(const void *info) {} - (void)startMonitoringNetworkReachability { [self stopMonitoringNetworkReachability]; @@ -563,7 +552,7 @@ static void AFNetworkReachabilityReleaseCallback(const void *info) { completionBlock(operations); } }); -#if NEEDS_DISPATCH_RETAIN_RELEASE +#if AF_DISPATCH_RETAIN_RELEASE dispatch_release(dispatchGroup); #endif }]; diff --git a/AFNetworking/AFHTTPRequestOperation.m b/AFNetworking/AFHTTPRequestOperation.m index 9aa34c9..95d0aa9 100644 --- a/AFNetworking/AFHTTPRequestOperation.m +++ b/AFNetworking/AFHTTPRequestOperation.m @@ -23,27 +23,17 @@ #import "AFHTTPRequestOperation.h" #import -// Workaround for change in imp_implementationWithBlock() -#ifdef __IPHONE_6_0 - #define AF_CAST_TO_BLOCK id +// Workaround for change in imp_implementationWithBlock() with Xcode 4.5 +#if defined(__IPHONE_6_0) || defined(__MAC_10_8) +#define AF_CAST_TO_BLOCK id #else - #define AF_CAST_TO_BLOCK __bridge void * +#define AF_CAST_TO_BLOCK __bridge void * #endif -// Does ARC support support GCD objects? -// It does if the minimum deployment target is iOS 6+ or Mac OS X 8+ -#if TARGET_OS_IPHONE - #if __IPHONE_OS_VERSION_MIN_REQUIRED >= 60000 // iOS 6.0 or later - #define NEEDS_DISPATCH_RETAIN_RELEASE 0 - #else // iOS 5.X or earlier - #define NEEDS_DISPATCH_RETAIN_RELEASE 1 - #endif -#else - #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1080 // Mac OS X 10.8 or later - #define NEEDS_DISPATCH_RETAIN_RELEASE 0 - #else - #define NEEDS_DISPATCH_RETAIN_RELEASE 1 // Mac OS X 10.7 or earlier - #endif +// Workaround for management of dispatch_retain() / dispatch_release() by ARC with iOS 6 / Mac OS X 10.8 +#if (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && (!defined(__IPHONE_6_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_6_0)) || \ + (defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && (!defined(__MAC_10_8) || __MAC_OS_X_VERSION_MIN_REQUIRED < __MAC_10_8)) +#define AF_DISPATCH_RETAIN_RELEASE 1 #endif NSSet * AFContentTypesFromHTTPHeader(NSString *string) { @@ -134,14 +124,14 @@ static NSString * AFStringFromIndexSet(NSIndexSet *indexSet) { - (void)dealloc { if (_successCallbackQueue) { -#if NEEDS_DISPATCH_RETAIN_RELEASE +#if AF_DISPATCH_RETAIN_RELEASE dispatch_release(_successCallbackQueue); #endif _successCallbackQueue = NULL; } if (_failureCallbackQueue) { -#if NEEDS_DISPATCH_RETAIN_RELEASE +#if AF_DISPATCH_RETAIN_RELEASE dispatch_release(_failureCallbackQueue); #endif _failureCallbackQueue = NULL; @@ -224,14 +214,14 @@ static NSString * AFStringFromIndexSet(NSIndexSet *indexSet) { - (void)setSuccessCallbackQueue:(dispatch_queue_t)successCallbackQueue { if (successCallbackQueue != _successCallbackQueue) { if (_successCallbackQueue) { -#if NEEDS_DISPATCH_RETAIN_RELEASE +#if AF_DISPATCH_RETAIN_RELEASE dispatch_release(_successCallbackQueue); #endif _successCallbackQueue = NULL; } if (successCallbackQueue) { -#if NEEDS_DISPATCH_RETAIN_RELEASE +#if AF_DISPATCH_RETAIN_RELEASE dispatch_retain(successCallbackQueue); #endif _successCallbackQueue = successCallbackQueue; @@ -242,14 +232,14 @@ static NSString * AFStringFromIndexSet(NSIndexSet *indexSet) { - (void)setFailureCallbackQueue:(dispatch_queue_t)failureCallbackQueue { if (failureCallbackQueue != _failureCallbackQueue) { if (_failureCallbackQueue) { -#if NEEDS_DISPATCH_RETAIN_RELEASE +#if AF_DISPATCH_RETAIN_RELEASE dispatch_release(_failureCallbackQueue); #endif _failureCallbackQueue = NULL; } if (failureCallbackQueue) { -#if NEEDS_DISPATCH_RETAIN_RELEASE +#if AF_DISPATCH_RETAIN_RELEASE dispatch_retain(failureCallbackQueue); #endif _failureCallbackQueue = failureCallbackQueue;