Skip to content

Commit

Permalink
Merge pull request #532 from NDrive/master
Browse files Browse the repository at this point in the history
Non-Thread Safe Property Injection #530
  • Loading branch information
alexgarbarev authored Oct 3, 2016
2 parents 59b0cde + 58cffa1 commit 7b82e02
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 39 deletions.
22 changes: 12 additions & 10 deletions Source/Factory/Assembly/TyphoonAssembly.m
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,18 @@ + (BOOL)resolveInstanceMethod:(SEL)sel {


- (void)forwardInvocation:(NSInvocation *)anInvocation {
if (_factory) {
[_factory forwardInvocation:anInvocation];
}
else {
TyphoonRuntimeArguments *args = [TyphoonRuntimeArguments argumentsFromInvocation:anInvocation];
NSString *key = NSStringFromSelector(anInvocation.selector);
TyphoonDefinition *definition = [_definitionBuilder builtDefinitionForKey:key args:args];

[anInvocation retainArguments];
[anInvocation setReturnValue:&definition];
@synchronized (self) {
if (_factory) {
[_factory forwardInvocation:anInvocation];
}
else {
TyphoonRuntimeArguments *args = [TyphoonRuntimeArguments argumentsFromInvocation:anInvocation];
NSString *key = NSStringFromSelector(anInvocation.selector);
TyphoonDefinition *definition = [_definitionBuilder builtDefinitionForKey:key args:args];

[anInvocation retainArguments];
[anInvocation setReturnValue:&definition];
}
}
}

Expand Down
62 changes: 34 additions & 28 deletions Source/Factory/Internal/TyphoonBlockComponentFactory.m
Original file line number Diff line number Diff line change
Expand Up @@ -111,39 +111,45 @@ - (void)registerAllDefinitions:(TyphoonAssembly *)assembly

- (void)forwardInvocation:(NSInvocation *)invocation
{
NSString *componentKey = NSStringFromSelector([invocation selector]);
LogTrace(@"Component key: %@", componentKey);

TyphoonRuntimeArguments *args = [TyphoonRuntimeArguments argumentsFromInvocation:invocation];

NSInvocation *internalInvocation =
[NSInvocation invocationWithMethodSignature:[self methodSignatureForSelector:@selector(componentForKey:args:)]];
[internalInvocation setSelector:@selector(componentForKey:args:)];
[internalInvocation setArgument:&componentKey atIndex:2];
[internalInvocation setArgument:&args atIndex:3];
[internalInvocation invokeWithTarget:self];

void *returnValue;
[internalInvocation getReturnValue:&returnValue];
[invocation setReturnValue:&returnValue];
@synchronized (self) {

NSString *componentKey = NSStringFromSelector([invocation selector]);
LogTrace(@"Component key: %@", componentKey);

TyphoonRuntimeArguments *args = [TyphoonRuntimeArguments argumentsFromInvocation:invocation];

NSInvocation *internalInvocation =
[NSInvocation invocationWithMethodSignature:[self methodSignatureForSelector:@selector(componentForKey:args:)]];
[internalInvocation setSelector:@selector(componentForKey:args:)];
[internalInvocation setArgument:&componentKey atIndex:2];
[internalInvocation setArgument:&args atIndex:3];
[internalInvocation invokeWithTarget:self];

void *returnValue;
[internalInvocation getReturnValue:&returnValue];
[invocation setReturnValue:&returnValue];
}
}

- (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector
{
if ([self respondsToSelector:aSelector]) {
return [[self class] instanceMethodSignatureForSelector:aSelector];
}

NSString *componentKey = NSStringFromSelector(aSelector);
TyphoonDefinition *definition = [self definitionForKey:componentKey];
TyphoonAssembly *assembly = definition.assembly;

if (assembly) {
return [assembly methodSignatureForSelector:aSelector];
@synchronized (self) {

if ([self respondsToSelector:aSelector]) {
return [[self class] instanceMethodSignatureForSelector:aSelector];
}

NSString *componentKey = NSStringFromSelector(aSelector);
TyphoonDefinition *definition = [self definitionForKey:componentKey];
TyphoonAssembly *assembly = definition.assembly;

if (assembly) {
return [assembly methodSignatureForSelector:aSelector];
}

// Last resort.
return [TyphoonIntrospectionUtils methodSignatureWithArgumentsAndReturnValueAsObjectsFromSelector:aSelector];
}

// Last resort.
return [TyphoonIntrospectionUtils methodSignatureWithArgumentsAndReturnValueAsObjectsFromSelector:aSelector];
}

@end
2 changes: 1 addition & 1 deletion Source/Utils/TyphoonIntrospectionUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ + (TyphoonTypeDescriptor *)typeForPropertyNamed:(NSString *)propertyName inClass
return (NULL);
}

static char buffer[256];
char buffer[256];
const char *e = strchr(attributes, ',');
if (e == NULL) {
return (NULL);
Expand Down

0 comments on commit 7b82e02

Please sign in to comment.