Permalink
Browse files

Fixed crash when NSStackBlock was passed as an argument. Now converti…

…ng NSStackBlock to NSMallocBlock.
  • Loading branch information...
1 parent 1ab52f7 commit ccc0c3a30b23e24a3fe14f461680aff19f2561f7 @roustem roustem committed Jul 17, 2012
Showing with 10 additions and 5 deletions.
  1. +2 −0 Kiwi/KWMessagePattern.m
  2. +8 −5 Kiwi/KWStub.m
View
@@ -80,6 +80,8 @@ + (id)messagePatternFromInvocation:(NSInvocation *)anInvocation {
object = [KWValue valueWithBytes:[data bytes] objCType:type];
}
+
+ if (strcmp(type, "@?") == 0) object = [[object copy] autorelease]; // Converting NSStackBlock to NSMallocBlock
[argumentFilters addObject:(object != nil) ? object : [KWNull null]];
}
}
View
@@ -179,19 +179,22 @@ - (BOOL)processInvocation:(NSInvocation *)anInvocation {
if (block) {
NSUInteger numberOfArguments = [[anInvocation methodSignature] numberOfArguments];
- NSMutableArray *params = [NSMutableArray arrayWithCapacity:(numberOfArguments-2)];
+ NSMutableArray *args = [NSMutableArray arrayWithCapacity:(numberOfArguments-2)];
for (NSUInteger i = 2; i < numberOfArguments; ++i) {
- id param = [anInvocation getArgumentAtIndexAsObject:i];
- [params addObject:param];
+ id arg = [anInvocation getArgumentAtIndexAsObject:i];
+
+ const char *argType = [[anInvocation methodSignature] getArgumentTypeAtIndex:i];
+ if (strcmp(argType, "@?") == 0) arg = [[arg copy] autorelease];
+ [args addObject:arg];
}
- id newValue = block(params);
+ id newValue = block(args);
if (newValue != value) {
[value release];
value = [newValue retain];
}
- [params removeAllObjects]; // We don't want these objects to be in autorelease pool
+ [args removeAllObjects]; // We don't want these objects to be in autorelease pool
}
if (self.value == nil)

0 comments on commit ccc0c3a

Please sign in to comment.