Skip to content

Commit

Permalink
revert to original version of MAFuture library and use no-arc setting…
Browse files Browse the repository at this point in the history
… during compile for those files
  • Loading branch information
Paul Colton committed Mar 25, 2014
1 parent 50e575d commit 47a5faf
Show file tree
Hide file tree
Showing 8 changed files with 170 additions and 98 deletions.
10 changes: 10 additions & 0 deletions src/Kernel/Third-Party/MAFuture/MABaseFuture.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ - (id)init
return self;
}

- (void)dealloc
{
[_value release];
[_lock release];

[super dealloc];
}

- (void)setFutureValue: (id)value
{
[_lock lock];
Expand All @@ -32,6 +40,8 @@ - (id)futureValue

- (void)setFutureValueUnlocked: (id)value
{
[value retain];
[_value release];
_value = value;
_resolved = YES;
[_lock broadcast];
Expand Down
17 changes: 11 additions & 6 deletions src/Kernel/Third-Party/MAFuture/MACompoundFuture.m
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ - (void)forwardInvocation: (NSInvocation *)invocation
if(type[0] == '^' && type[1] == '@')
{
// get the existing pointer-to-object
void **parameterValue;
id *parameterValue;
[invocation getArgument: &parameterValue atIndex: i];

// if it's NULL, then we don't need to do anything
Expand All @@ -109,7 +109,7 @@ - (void)forwardInvocation: (NSInvocation *)invocation

// allocate space to receive the final computed value
NSMutableData *newParameterSpace = [NSMutableData dataWithLength: sizeof(id)];
void **newParameterValue = [newParameterSpace mutableBytes];
id *newParameterValue = [newParameterSpace mutableBytes];

// set the parameter to point to the new space
[invocation setArgument: &newParameterValue atIndex: i];
Expand All @@ -127,6 +127,7 @@ - (void)forwardInvocation: (NSInvocation *)invocation
[parameterDatas self];
return (id)nil;
}];
[invocationFuture autorelease];
}
[parameterDatas addObject: newParameterSpace];

Expand All @@ -136,11 +137,14 @@ - (void)forwardInvocation: (NSInvocation *)invocation
// capture the NSMutableData to ensure that it stays live
// interior pointer problem
[newParameterSpace self];
return (__bridge id) *newParameterValue;
return *newParameterValue;
}];

// and now "return" it
*parameterValue = (__bridge void *)(parameterFuture);
*parameterValue = parameterFuture;

// memory management
[parameterFuture autorelease];
}
}
}
Expand All @@ -157,6 +161,7 @@ - (void)forwardInvocation: (NSInvocation *)invocation
}];
LOG(@"forwardInvocation: %p creating new compound future %p", invocation, returnFuture);
[invocation setReturnValue: &returnFuture];
[returnFuture release];
}
}

Expand All @@ -171,13 +176,13 @@ id MACompoundBackgroundFuture(id (^block)(void))
return [blockFuture resolveFuture];
}];

return compoundFuture;
return [compoundFuture autorelease];
}

#undef MACompoundLazyFuture
id MACompoundLazyFuture(id (^block)(void))
{
_MACompoundFuture *compoundFuture = [[_MACompoundFuture alloc] initWithBlock: block];

return compoundFuture;
return [compoundFuture autorelease];
}
32 changes: 20 additions & 12 deletions src/Kernel/Third-Party/MAFuture/MAFuture.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#import <dispatch/dispatch.h>
#import <Foundation/Foundation.h>
#import <objc/runtime.h>

#import "MABaseFuture.h"
#import "MAFuture.h"
Expand All @@ -24,7 +23,7 @@ - (id)forwardingTargetForSelector: (SEL)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", [self class]);
LOG(@"WARNING: [%@ resolveFuture] has returned nil. You must avoid to return nil objects from the block", NSStringFromClass(isa));
}
return resolvedFuture;
#else
Expand Down Expand Up @@ -86,12 +85,19 @@ - (id)initWithBlock: (id (^)(void))block
return self;
}

- (void)dealloc
{
[_block release];
[super dealloc];
}

- (id)resolveFuture
{
[_lock lock];
if(![self futureHasResolved])
{
[self setFutureValueUnlocked: _block()];
[_block release];
_block = nil;
}
[_lock unlock];
Expand All @@ -103,13 +109,13 @@ - (id)resolveFuture
#undef MABackgroundFuture
id MABackgroundFuture(id (^block)(void))
{
return [[_MABackgroundBlockFuture alloc] initWithBlock: block];
return [[[_MABackgroundBlockFuture alloc] initWithBlock: block] autorelease];
}

#undef MALazyFuture
id MALazyFuture(id (^block)(void))
{
return [[_MALazyBlockFuture alloc] initWithBlock: block];
return [[[_MALazyBlockFuture alloc] initWithBlock: block] autorelease];
}

#pragma mark -
Expand Down Expand Up @@ -153,7 +159,7 @@ - (void)setCountOfUsers:(NSInteger)newCountOfUsers {


- (id)futureValue {
return [super futureValue];
return [[[super futureValue] retain] autorelease];
}


Expand All @@ -174,6 +180,7 @@ - (void)setIsObservingUnlocked:(BOOL)newIsObserving {

- (void)dealloc {
[self setIsObservingUnlocked:NO];
[super dealloc];
}


Expand Down Expand Up @@ -202,7 +209,7 @@ - (void)processMemoryWarning {
- (void)processMemoryWarningUnlocked {
// TODO: must be checked when resolvation algorithm is changed.
_resolved = NO;
_value = nil;
[_value release], _value = nil;
}


Expand All @@ -217,7 +224,7 @@ - (void)invalidateUnlocked {
// TODO: must be checked when resolvation algorithm is changed.
[self setIsObservingUnlocked:NO];
_resolved = NO;
_value = nil;
[_value release], _value = nil;
}

@end
Expand All @@ -229,7 +236,7 @@ id IKMemoryAwareFutureCreate(id (^block)(void)) {

#undef IKMemoryAwareFuture
id IKMemoryAwareFuture(id (^block)(void)) {
return IKMemoryAwareFutureCreate(block);
return [IKMemoryAwareFutureCreate(block) autorelease];
}

void IKMemoryAwareFutureBeginContentAccess(id future) {
Expand All @@ -251,8 +258,8 @@ void IKInvalidateMemoryAwareFuture(id future) {
NSString* IKMemoryAwareFuturesDirectory() {
static NSString* FuturesDirectory = nil;
if (FuturesDirectory == nil) {
FuturesDirectory = [NSTemporaryDirectory() stringByAppendingPathComponent:@"futures"];
};
FuturesDirectory = [[NSTemporaryDirectory() stringByAppendingPathComponent:@"futures"] retain];
}
return FuturesDirectory;
}

Expand Down Expand Up @@ -294,6 +301,7 @@ - (void)dealloc {
#else
[[NSFileManager defaultManager] removeItemAtPath:IKMemoryAwareFuturePath(self) error:NULL];
#endif
[super dealloc];
}


Expand Down Expand Up @@ -336,7 +344,7 @@ - (BOOL)archiveValueUnlocked {


- (BOOL)unarchiveValueUnlocked {
id value = [NSKeyedUnarchiver unarchiveObjectWithFile:IKMemoryAwareFuturePath(self)];
id value = [[NSKeyedUnarchiver unarchiveObjectWithFile:IKMemoryAwareFuturePath(self)] retain];
if (value != nil) {
[self setFutureValueUnlocked:value];
}
Expand Down Expand Up @@ -364,7 +372,7 @@ id IKAutoArchivingMemoryAwareFutureCreate(id (^block)(void)) {

#undef IKAutoArchivingMemoryAwareFuture
id IKAutoArchivingMemoryAwareFuture(id (^block)(void)) {
return IKAutoArchivingMemoryAwareFutureCreate(block);
return [IKAutoArchivingMemoryAwareFutureCreate(block) autorelease];
}

#endif // __IPHONE_4_0
Expand Down
4 changes: 2 additions & 2 deletions src/Kernel/Third-Party/MAFuture/MAMethodSignatureCache.m
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ - (void)_clearCache
- (NSMethodSignature *)_searchAllClassesForSignature: (SEL)sel
{
int count = objc_getClassList(NULL, 0);
Class *classes = (Class *)malloc(sizeof(*classes) * count);
Class *classes = malloc(sizeof(*classes) * count);
objc_getClassList(classes, count);

NSMethodSignature *sig = nil;
Expand Down Expand Up @@ -116,7 +116,7 @@ - (NSMethodSignature *)cachedMethodSignatureForSelector: (SEL)sel
if(!sig)
sig = (id)[NSNull null];
#ifdef __IPHONE_4_0
CFDictionarySetValue(_cache, sel, (__bridge const void *)(sig));
CFDictionarySetValue(_cache, sel, sig);
#else
[_cache setObject: sig forKey: (id)sel];
#endif //__IPHONE_4_0
Expand Down
13 changes: 12 additions & 1 deletion src/Kernel/Third-Party/MAFuture/MAProxy.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
@interface MAProxy : NSObject
@interface MAProxy : NSObject
{
int32_t _refcountMinusOne;
}

//+ (id)alloc;
//- (void)dealloc;

- (void)finalize;
- (BOOL)isProxy;
- (id)retain;
- (void)release;
- (id)autorelease;
- (NSUInteger)retainCount;

@end

36 changes: 36 additions & 0 deletions src/Kernel/Third-Party/MAFuture/MAProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,46 @@ + (void)initialize
// runtime requires an implementation
}

//+ (id)alloc
//{
// return NSAllocateObject(self, 0, NULL);
//}
//
//- (void)dealloc
//{
// NSDeallocateObject(self);
//}

- (void)finalize
{
}

- (BOOL)isProxy
{
return YES;
}

- (id)retain
{
OSAtomicIncrement32(&_refcountMinusOne);
return self;
}

- (void)release
{
if(OSAtomicDecrement32(&_refcountMinusOne) == -1)
[self dealloc];
}

- (id)autorelease
{
[NSAutoreleasePool addObject: self];
return self;
}

- (NSUInteger)retainCount
{
return _refcountMinusOne + 1;
}

@end
Loading

0 comments on commit 47a5faf

Please sign in to comment.