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
This commit is contained in:
Mattt Thompson 2012-09-17 11:53:49 -07:00
parent f12c163df9
commit 8c536f5f8d
2 changed files with 20 additions and 41 deletions

View file

@ -40,20 +40,10 @@
#import <netdb.h> #import <netdb.h>
#endif #endif
// Does ARC support support GCD objects? // Workaround for management of dispatch_retain() / dispatch_release() by ARC with iOS 6 / Mac OS X 10.8
// It does if the minimum deployment target is iOS 6+ or Mac OS X 8+ #if (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && (!defined(__IPHONE_6_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_6_0)) || \
#if TARGET_OS_IPHONE (defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && (!defined(__MAC_10_8) || __MAC_OS_X_VERSION_MIN_REQUIRED < __MAC_10_8))
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 60000 // iOS 6.0 or later #define AF_DISPATCH_RETAIN_RELEASE 1
#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
#endif #endif
@interface AFMultipartFormData : NSObject <AFMultipartFormData> @interface AFMultipartFormData : NSObject <AFMultipartFormData>
@ -338,8 +328,7 @@ static const void * AFNetworkReachabilityRetainCallback(const void *info) {
return (__bridge_retained const void *)([(__bridge AFNetworkReachabilityStatusBlock)info copy]); return (__bridge_retained const void *)([(__bridge AFNetworkReachabilityStatusBlock)info copy]);
} }
static void AFNetworkReachabilityReleaseCallback(const void *info) { static void AFNetworkReachabilityReleaseCallback(const void *info) {}
}
- (void)startMonitoringNetworkReachability { - (void)startMonitoringNetworkReachability {
[self stopMonitoringNetworkReachability]; [self stopMonitoringNetworkReachability];
@ -563,7 +552,7 @@ static void AFNetworkReachabilityReleaseCallback(const void *info) {
completionBlock(operations); completionBlock(operations);
} }
}); });
#if NEEDS_DISPATCH_RETAIN_RELEASE #if AF_DISPATCH_RETAIN_RELEASE
dispatch_release(dispatchGroup); dispatch_release(dispatchGroup);
#endif #endif
}]; }];

View file

@ -23,27 +23,17 @@
#import "AFHTTPRequestOperation.h" #import "AFHTTPRequestOperation.h"
#import <objc/runtime.h> #import <objc/runtime.h>
// Workaround for change in imp_implementationWithBlock() // Workaround for change in imp_implementationWithBlock() with Xcode 4.5
#ifdef __IPHONE_6_0 #if defined(__IPHONE_6_0) || defined(__MAC_10_8)
#define AF_CAST_TO_BLOCK id #define AF_CAST_TO_BLOCK id
#else #else
#define AF_CAST_TO_BLOCK __bridge void * #define AF_CAST_TO_BLOCK __bridge void *
#endif #endif
// Does ARC support support GCD objects? // Workaround for management of dispatch_retain() / dispatch_release() by ARC with iOS 6 / Mac OS X 10.8
// It does if the minimum deployment target is iOS 6+ or Mac OS X 8+ #if (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && (!defined(__IPHONE_6_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_6_0)) || \
#if TARGET_OS_IPHONE (defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && (!defined(__MAC_10_8) || __MAC_OS_X_VERSION_MIN_REQUIRED < __MAC_10_8))
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 60000 // iOS 6.0 or later #define AF_DISPATCH_RETAIN_RELEASE 1
#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
#endif #endif
NSSet * AFContentTypesFromHTTPHeader(NSString *string) { NSSet * AFContentTypesFromHTTPHeader(NSString *string) {
@ -134,14 +124,14 @@ static NSString * AFStringFromIndexSet(NSIndexSet *indexSet) {
- (void)dealloc { - (void)dealloc {
if (_successCallbackQueue) { if (_successCallbackQueue) {
#if NEEDS_DISPATCH_RETAIN_RELEASE #if AF_DISPATCH_RETAIN_RELEASE
dispatch_release(_successCallbackQueue); dispatch_release(_successCallbackQueue);
#endif #endif
_successCallbackQueue = NULL; _successCallbackQueue = NULL;
} }
if (_failureCallbackQueue) { if (_failureCallbackQueue) {
#if NEEDS_DISPATCH_RETAIN_RELEASE #if AF_DISPATCH_RETAIN_RELEASE
dispatch_release(_failureCallbackQueue); dispatch_release(_failureCallbackQueue);
#endif #endif
_failureCallbackQueue = NULL; _failureCallbackQueue = NULL;
@ -224,14 +214,14 @@ static NSString * AFStringFromIndexSet(NSIndexSet *indexSet) {
- (void)setSuccessCallbackQueue:(dispatch_queue_t)successCallbackQueue { - (void)setSuccessCallbackQueue:(dispatch_queue_t)successCallbackQueue {
if (successCallbackQueue != _successCallbackQueue) { if (successCallbackQueue != _successCallbackQueue) {
if (_successCallbackQueue) { if (_successCallbackQueue) {
#if NEEDS_DISPATCH_RETAIN_RELEASE #if AF_DISPATCH_RETAIN_RELEASE
dispatch_release(_successCallbackQueue); dispatch_release(_successCallbackQueue);
#endif #endif
_successCallbackQueue = NULL; _successCallbackQueue = NULL;
} }
if (successCallbackQueue) { if (successCallbackQueue) {
#if NEEDS_DISPATCH_RETAIN_RELEASE #if AF_DISPATCH_RETAIN_RELEASE
dispatch_retain(successCallbackQueue); dispatch_retain(successCallbackQueue);
#endif #endif
_successCallbackQueue = successCallbackQueue; _successCallbackQueue = successCallbackQueue;
@ -242,14 +232,14 @@ static NSString * AFStringFromIndexSet(NSIndexSet *indexSet) {
- (void)setFailureCallbackQueue:(dispatch_queue_t)failureCallbackQueue { - (void)setFailureCallbackQueue:(dispatch_queue_t)failureCallbackQueue {
if (failureCallbackQueue != _failureCallbackQueue) { if (failureCallbackQueue != _failureCallbackQueue) {
if (_failureCallbackQueue) { if (_failureCallbackQueue) {
#if NEEDS_DISPATCH_RETAIN_RELEASE #if AF_DISPATCH_RETAIN_RELEASE
dispatch_release(_failureCallbackQueue); dispatch_release(_failureCallbackQueue);
#endif #endif
_failureCallbackQueue = NULL; _failureCallbackQueue = NULL;
} }
if (failureCallbackQueue) { if (failureCallbackQueue) {
#if NEEDS_DISPATCH_RETAIN_RELEASE #if AF_DISPATCH_RETAIN_RELEASE
dispatch_retain(failureCallbackQueue); dispatch_retain(failureCallbackQueue);
#endif #endif
_failureCallbackQueue = failureCallbackQueue; _failureCallbackQueue = failureCallbackQueue;