Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix: use wrong deployment target guards

use CFMutableDictionary instead of NSMapTable for iOS
  • Loading branch information...
commit dc67e53fde83f501fb23de2f1f0367228fb7cbfa 1 parent 1774ed9
@Kentzo Kentzo authored
View
4 MACompoundFuture.h
@@ -1,9 +1,7 @@
-#if TARGET_OS_MAC && !TARGET_IPHONE_SIMULATOR
+
id MACompoundBackgroundFuture(id (^block)(void));
id MACompoundLazyFuture(id (^block)(void));
#define MACompoundBackgroundFuture(...) ((__typeof((__VA_ARGS__)()))MACompoundBackgroundFuture((id (^)(void))(__VA_ARGS__)))
#define MACompoundLazyFuture(...) ((__typeof((__VA_ARGS__)()))MACompoundLazyFuture((id (^)(void))(__VA_ARGS__)))
-
-#endif
View
4 MACompoundFuture.m
@@ -1,8 +1,6 @@
#import <Foundation/Foundation.h>
#import <objc/runtime.h>
-#if TARGET_OS_MAC && !TARGET_IPHONE_SIMULATOR
-
#import "MAFuture.h"
#import "MAFutureInternal.h"
#import "MAMethodSignatureCache.h"
@@ -187,5 +185,3 @@ id MACompoundLazyFuture(id (^block)(void))
return [compoundFuture autorelease];
}
-
-#endif
View
8 MAFuture.h
@@ -6,8 +6,8 @@ id MALazyFuture(id (^block)(void));
#define MALazyFuture(...) ((__typeof((__VA_ARGS__)()))MALazyFuture((id (^)(void))(__VA_ARGS__)))
-#ifdef __IPHONE_4_0
-#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_4_0
+#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED
+#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_4_0
id IKMemoryAwareFuture(id (^block)(void));
id IKMemoryAwareFutureCreate(id (^block)(void));
@@ -18,5 +18,5 @@ BOOL IKMemoryAwareFutureIsObserving(id future);
#define IKMemoryAwareFuture(...)((__typeof((__VA_ARGS__)()))IKMemoryAwareFuture((id (^)(void))(__VA_ARGS__)))
#define IKMemoryAwareFutureCreate(...)((__typeof((__VA_ARGS__)()))IKMemoryAwareFutureCreate((id (^)(void))(__VA_ARGS__)))
-#endif // __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_4_0
-#endif // __IPHONE_4_0
+#endif // __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_4_0
+#endif // __IPHONE_OS_VERSION_MIN_REQUIRED
View
18 MAFuture.m
@@ -20,18 +20,22 @@ @implementation _MASimpleFuture
- (id)forwardingTargetForSelector: (SEL)sel
{
LOG(@"%p forwardingTargetForSelector: %@, resolving future", self, NSStringFromSelector(sel));
+#if ENABLE_LOGGING
+ id resolvedFuture = [self resolveFuture];
+ if (resolvedFuture == nil) {
+ LOG(@"WARNING: [%@ resolveFuture] has returned nil. You must avoid to return nil objects from the block", NSStringFromClass(isa));
+ }
+ return resolvedFuture;
+#else
return [self resolveFuture];
+#endif
}
-#if TARGET_OS_MAC && !TARGET_IPHONE_SIMULATOR
-
- (NSMethodSignature *)methodSignatureForSelector: (SEL)sel
{
return [[MAMethodSignatureCache sharedCache] cachedMethodSignatureForSelector: sel];
}
-#endif
-
- (void)forwardInvocation: (NSInvocation *)inv
{
// this gets hit if the future resolves to nil
@@ -114,8 +118,8 @@ id MALazyFuture(id (^block)(void))
return [[[_MALazyBlockFuture alloc] initWithBlock: block] autorelease];
}
-#ifdef __IPHONE_4_0
-#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_4_0
+#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED
+#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_4_0
@implementation _IKMemoryAwareFuture
@dynamic isObserving;
@@ -201,5 +205,5 @@ BOOL IKMemoryAwareFutureIsObserving(id future) {
return [future isObserving];
}
-#endif // __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_4_0
+#endif // __IPHONE_OS_VERSION_MAX_ALLOWED < __IPHONE_4_0
#endif // __IPHONE_4_0
View
8 MAFutureInternal.h
@@ -15,8 +15,8 @@
@end
-#ifdef __IPHONE_4_0
-#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_4_0
+#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED
+#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_4_0
@interface _IKMemoryAwareFuture : _MALazyBlockFuture {
BOOL isObserving;
@@ -30,5 +30,5 @@
@end
-#endif // __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_4_0
-#endif // __IPHONE_4_0
+#endif // __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_4_0
+#endif // __IPHONE_OS_VERSION_MIN_REQUIRED
View
7 MAMethodSignatureCache.h
@@ -1,10 +1,13 @@
#import <Foundation/Foundation.h>
-#if TARGET_OS_MAC && !TARGET_IPHONE_SIMULATOR
@interface MAMethodSignatureCache : NSObject
{
+#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED
+ CFMutableDictionaryRef _cache;
+#else
NSMapTable *_cache;
+#endif
NSRecursiveLock *_lock;
}
@@ -12,5 +15,3 @@
- (NSMethodSignature *)cachedMethodSignatureForSelector: (SEL)sel;
@end
-
-#endif
View
23 MAMethodSignatureCache.m
@@ -2,7 +2,6 @@
#import "MAMethodSignatureCache.h"
-#if TARGET_OS_MAC && !TARGET_IPHONE_SIMULATOR
@interface NSRecursiveLock (BlockAdditions)
@@ -36,10 +35,14 @@ - (id)init
{
if((self = [super init]))
{
+#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED
+ _cache = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, NULL, &kCFTypeDictionaryValueCallBacks);
+#else
_cache = [[NSMapTable alloc]
initWithKeyOptions: NSPointerFunctionsOpaqueMemory | NSPointerFunctionsOpaquePersonality
valueOptions: NSPointerFunctionsStrongMemory | NSPointerFunctionsObjectPersonality
capacity: 0];
+#endif
_lock = [[NSRecursiveLock alloc] init];
[[NSNotificationCenter defaultCenter]
addObserver: self
@@ -52,7 +55,13 @@ - (id)init
- (void)_clearCache
{
- [_lock ma_do: ^{ [_cache removeAllObjects]; }];
+ [_lock ma_do: ^{
+#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED
+ CFDictionaryRemoveAllValues(_cache);
+#else
+ [_cache removeAllObjects];
+#endif
+ }];
}
- (NSMethodSignature *)_searchAllClassesForSignature: (SEL)sel
@@ -96,13 +105,21 @@ - (NSMethodSignature *)cachedMethodSignatureForSelector: (SEL)sel
{
__block NSMethodSignature *sig = nil;
[_lock ma_do: ^{
+#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED
+ sig = CFDictionaryGetValue(_cache, sel);
+#else
sig = [_cache objectForKey: (id)sel];
+#endif
if(!sig)
{
sig = [self _searchAllClassesForSignature: sel];
if(!sig)
sig = (id)[NSNull null];
+#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED
+ CFDictionarySetValue(_cache, sel, sig);
+#else
[_cache setObject: sig forKey: (id)sel];
+#endif
}
}];
if(sig == (id)[NSNull null])
@@ -111,5 +128,3 @@ - (NSMethodSignature *)cachedMethodSignatureForSelector: (SEL)sel
}
@end
-
-#endif
Please sign in to comment.
Something went wrong with that request. Please try again.