Skip to content

Commit

Permalink
Build against latest.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jasper Blues committed Feb 3, 2013
1 parent 7ad3f44 commit 6eba3ff
Show file tree
Hide file tree
Showing 14 changed files with 465 additions and 465 deletions.
18 changes: 18 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Xcode
build/*
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
!default.xcworkspace
xcuserdata
profile
*.moved-aside
DerivedData


.DS_Store
Binary file modified External/.DS_Store
Binary file not shown.
6 changes: 3 additions & 3 deletions External/Typhoon/Component/TyphoonDefinition.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

typedef enum
{
TyphoonComponentLifeCycleSingleton,
TyphoonComponentLifeCyclePrototype
TyphoonComponentLifeCyclePrototype,
TyphoonComponentLifeCycleSingleton
} TyphoonComponentLifecycle;


Expand All @@ -31,7 +31,7 @@ typedef enum

@property(nonatomic, readonly) Class type;
@property(nonatomic, strong) NSString* key;
@property(nonatomic, strong, readonly) NSString* factoryComponent;
@property(nonatomic, strong) NSString* factoryComponent;
@property(nonatomic, strong) TyphoonInitializer* initializer;
@property(nonatomic) SEL beforePropertyInjection;
@property(nonatomic) SEL afterPropertyInjection;
Expand Down
9 changes: 1 addition & 8 deletions External/Typhoon/Component/TyphoonDefinition.m
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,7 @@ - (NSSet*)propertiesInjectedByReference
/* ============================================================ Utility Methods ========================================================= */
- (NSString*)description
{
NSMutableString* description = [NSMutableString stringWithFormat:@"<%@: ", NSStringFromClass([self class])];
[description appendFormat:@"self.injectedProperties=%@", self.injectedProperties];
[description appendFormat:@", self.type=%@", self.type];
[description appendFormat:@", self.key=%@", self.key];
[description appendFormat:@", self.initializer=%@", self.initializer];
[description appendFormat:@", self.lifecycle=%@", self.lifecycle == TyphoonComponentLifeCycleSingleton ? @"Singleton" : @"Prototype"];
[description appendString:@">"];
return description;
return [NSString stringWithFormat:@"Definition: class='%@'", NSStringFromClass(_type)];
}

- (void)dealloc
Expand Down
1 change: 1 addition & 0 deletions External/Typhoon/Factory/Block/TyphoonAssembly.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@


static NSString * const TYPHOON_BEFORE_ADVICE_SUFFIX = @"__typhoonBeforeAdvice";
static NSMutableArray* resolveStack;

@interface TyphoonAssembly : NSObject
{
Expand Down
19 changes: 19 additions & 0 deletions External/Typhoon/Factory/Block/TyphoonAssembly.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ + (BOOL)resolveInstanceMethod:(SEL)sel
id cached = [[me cachedSelectors] objectForKey:key];
if (cached == nil)
{
[resolveStack addObject:key];
if ([resolveStack count] > 100)
{
NSString* bottom = [resolveStack objectAtIndex:0];
NSString* top = [resolveStack objectAtIndex:[resolveStack count] -1];
if ([top isEqualToString:bottom])
{
NSLog(@"Resolve stack: %@", resolveStack);
[NSException raise:NSInternalInconsistencyException format:@"Circular dependency detected."];
}
}

[[self class] typhoon_swizzleMethod:sel withMethod:NSSelectorFromString(key) error:nil];
cached = objc_msgSend(me, sel);
if (cached && [cached isKindOfClass:[TyphoonDefinition class]])
Expand All @@ -56,6 +68,7 @@ + (BOOL)resolveInstanceMethod:(SEL)sel
}
[[self class] typhoon_swizzleMethod:NSSelectorFromString(key) withMethod:sel error:nil];
}
[resolveStack removeAllObjects];
return cached;

}));
Expand All @@ -70,6 +83,12 @@ + (BOOL)selectorReserved:(SEL)selector
return selector == @selector(init) || selector == @selector(cachedSelectors) || selector == NSSelectorFromString(@".cxx_destruct");
}

+ (void)load
{
[super load];
resolveStack = [[NSMutableArray alloc] init];
}

/* ============================================================ Initializers ============================================================ */
- (id)init
{
Expand Down
68 changes: 41 additions & 27 deletions External/Typhoon/Factory/Block/TyphoonBlockComponentFactory.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

static NSMutableArray* swizzleRegistry;

@interface TyphoonAssembly (NanoFactoryFriend)
@interface TyphoonAssembly (BlockFactoryFriend)

+ (BOOL)selectorReserved:(SEL)selector;

Expand Down Expand Up @@ -48,13 +48,17 @@ + (BOOL)resolveInstanceMethod:(SEL)sel
+ (void)initialize
{
[super initialize];
swizzleRegistry = [[NSMutableArray alloc] init];
@synchronized (self)
{
swizzleRegistry = [[NSMutableArray alloc] init];
}
}


/* ============================================================ Initializers ============================================================ */
- (id)initWithAssembly:(TyphoonAssembly*)assembly;
{
NSLog(@"Building assembly: %@", NSStringFromClass([assembly class]));
if (![assembly isKindOfClass:[TyphoonAssembly class]])
{
[NSException raise:NSInvalidArgumentException format:@"Class '%@' is not a sub-class of %@", NSStringFromClass([assembly class]),
Expand All @@ -65,6 +69,7 @@ - (id)initWithAssembly:(TyphoonAssembly*)assembly;
{
[self applyBeforeAdviceToAssemblyMethods:assembly];
NSArray* definitions = [self populateCache:assembly];
NSLog(@"Definitions: %@", definitions);
for (TyphoonDefinition* definition in definitions)
{
[self register:definition];
Expand All @@ -76,47 +81,56 @@ - (id)initWithAssembly:(TyphoonAssembly*)assembly;
/* ============================================================ Private Methods ========================================================= */
- (NSArray*)populateCache:(TyphoonAssembly*)assembly
{
unsigned int methodCount;
Method* methodList = class_copyMethodList([assembly class], &methodCount);
for (int i = 0; i < methodCount; i++)
@synchronized (self)
{
Method method = methodList[i];

int argumentCount = method_getNumberOfArguments(method);
if (argumentCount == 2)
unsigned int methodCount;
Method* methodList = class_copyMethodList([assembly class], &methodCount);
for (int i = 0; i < methodCount; i++)
{
SEL methodSelector = method_getName(method);
if (![[assembly class] selectorReserved:methodSelector])
Method method = methodList[i];
// NSLog(@"Selector: %@", NSStringFromSelector(method_getName(method)));

int argumentCount = method_getNumberOfArguments(method);
if (argumentCount == 2)
{
objc_msgSend(assembly, methodSelector);
SEL methodSelector = method_getName(method);
if (![[assembly class] selectorReserved:methodSelector])
{
objc_msgSend(assembly, methodSelector);
}
}
}
NSMutableDictionary* dictionary = [assembly cachedSelectors];
free(methodList);
return [dictionary allValues];
}
NSMutableDictionary* dictionary = [assembly cachedSelectors];
return [dictionary allValues];
}

- (void)applyBeforeAdviceToAssemblyMethods:(TyphoonAssembly*)assembly
{
if (![swizzleRegistry containsObject:[TyphoonAssembly class]])
@synchronized (self)
{
[swizzleRegistry addObject:[TyphoonAssembly class]];
unsigned int methodCount;
Method* methodList = class_copyMethodList([assembly class], &methodCount);
for (int i = 0; i < methodCount; i++)
if (![swizzleRegistry containsObject:[assembly class]])
{
Method method = methodList[i];
int argumentCount = method_getNumberOfArguments(method);
if (argumentCount == 2)
[swizzleRegistry addObject:[assembly class]];
unsigned int methodCount;
Method* methodList = class_copyMethodList([assembly class], &methodCount);
for (int i = 0; i < methodCount; i++)
{
SEL methodSelector = method_getName(method);
if ([TyphoonAssembly selectorReserved:methodSelector] == NO)
Method method = methodList[i];
int argumentCount = method_getNumberOfArguments(method);
if (argumentCount == 2)
{
SEL swizzled = NSSelectorFromString(
[NSStringFromSelector(methodSelector) stringByAppendingString:TYPHOON_BEFORE_ADVICE_SUFFIX]);
[[assembly class] typhoon_swizzleMethod:methodSelector withMethod:swizzled error:nil];
SEL methodSelector = method_getName(method);
if ([TyphoonAssembly selectorReserved:methodSelector] == NO)
{
SEL swizzled = NSSelectorFromString(
[NSStringFromSelector(methodSelector) stringByAppendingString:TYPHOON_BEFORE_ADVICE_SUFFIX]);
[[assembly class] typhoon_swizzleMethod:methodSelector withMethod:swizzled error:nil];
}
}
}
free(methodList);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,19 @@ - (id)buildInstanceWithDefinition:(TyphoonDefinition*)definition
}

[self injectPropertyDependenciesOn:instance withDefinition:definition];
if (definition.factoryComponent || definition.initializer.isClassMethod)
{
int retainCount = objc_msgSend(instance, NSSelectorFromString(@"retainCount"));
NSLog(@"Instance of class '%@' returned from factory. Retain count: %i", NSStringFromClass([instance class]), retainCount);
objc_msgSend(instance, NSSelectorFromString(@"retain"));
}
return instance;
}





/* ============================================================ Private Methods ========================================================= */
- (id)invokeInitializerOn:(id)instanceOrClass withDefinition:(TyphoonDefinition*)definition
{
Expand Down
2 changes: 1 addition & 1 deletion External/Typhoon/Factory/TyphoonComponentFactory.m
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ - (id)componentForKey:(NSString*)key
{
[NSException raise:NSInvalidArgumentException format:@"No component matching id '%@'.", key];
}
id returnValue = [self objectForDefinition:definition];
__autoreleasing id returnValue = [self objectForDefinition:definition];
[_currentlyResolvingReferences removeAllObjects];
return returnValue;
}
Expand Down
1 change: 1 addition & 0 deletions External/Typhoon/Typhoon.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@
#import "TyphoonDefinition+BlockAssembly.h"

#import "TyphoonAutowire.h"
#import "TyphoonShorthand.h"


4 changes: 0 additions & 4 deletions External/Typhoon/TyphoonAutowire.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,3 @@
} \
return TyphoonAutoWiredProperties(self, autoInjectProperties); \
}

#ifdef typhoon_shorthand
#define autoWire typhoon_autoWire
#endif
21 changes: 21 additions & 0 deletions External/Typhoon/TyphoonShorthand.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
////////////////////////////////////////////////////////////////////////////////
//
// JASPER BLUES
// Copyright 2013 Jasper Blues
// All Rights Reserved.
//
// NOTICE: Jasper Blues permits you to use, modify, and distribute this file
// in accordance with the terms of the license agreement accompanying it.
//
////////////////////////////////////////////////////////////////////////////////

#ifdef typhoon_shorthand

#define autoWire typhoon_autoWire

#define Singleton TyphoonComponentLifecycleSingleton

#define Prototype TyphoonComponentLifecyclePrototype

#endif

Loading

0 comments on commit 6eba3ff

Please sign in to comment.