From 728fbdefd8f9f44ac552d0dab66815d527d11c02 Mon Sep 17 00:00:00 2001 From: Tim Burks Date: Sun, 19 Jun 2011 00:18:07 -0700 Subject: [PATCH] fixed some problems with recent ivar changes, merged NuAnywhere update from Jeff. --- Nukefile | 4 +- examples/NuAnywhere/NuConsole/Nukefile | 2 +- .../NuConsole/objc/NuInjectBundle.m | 1 + examples/NuAnywhere/NuInject/Nukefile | 2 +- objc/NuObject.m | 43 ++++++++++++------- tools/nuke | 3 +- 6 files changed, 33 insertions(+), 22 deletions(-) diff --git a/Nukefile b/Nukefile index d3dc041..f17ce02 100644 --- a/Nukefile +++ b/Nukefile @@ -113,10 +113,10 @@ END) (set @cflags (+ @cflags " -DHAVE_CONFIG_H")) (ifDarwin - (then (set @arch '("i386")))) ;; optionally add "ppc" or "ppc64" to the list + (then (set @arch '("x86_64")))) ;; optionally add "ppc" or "ppc64" to the list (if (or isSnowLeopard isLion) - (then (set @arch (append @arch '("x86_64"))))) + (then (set @arch (append @arch '("i386"))))) (set @includes ((@inc_dirs map: (do (inc) " -I#{inc}")) join)) diff --git a/examples/NuAnywhere/NuConsole/Nukefile b/examples/NuAnywhere/NuConsole/Nukefile index e877330..b08207f 100644 --- a/examples/NuAnywhere/NuConsole/Nukefile +++ b/examples/NuAnywhere/NuConsole/Nukefile @@ -11,7 +11,7 @@ (if (or (isSnowLeopard) (isLion)) (then (set @ldflags " -framework Cocoa -framework Nu -framework Carbon -framework mach_inject_bundle -all_load ") - (set @arch '("x86_64"))) + (set @arch '("x86_64" "i386"))) (else (set @ldflags " -framework Cocoa -framework Nu -framework Carbon -linject -L../libinject -all_load "))) diff --git a/examples/NuAnywhere/NuConsole/objc/NuInjectBundle.m b/examples/NuAnywhere/NuConsole/objc/NuInjectBundle.m index 99484fe..aff3e34 100644 --- a/examples/NuAnywhere/NuConsole/objc/NuInjectBundle.m +++ b/examples/NuAnywhere/NuConsole/objc/NuInjectBundle.m @@ -12,6 +12,7 @@ @implementation ConsoleInitializer - (id) run:(id) object { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + NSLog(@"starting"); NSBundle *bundle = [NSBundle bundleForClass:[self class]]; NSString *main_path = [bundle pathForResource:@"main" ofType:@"nu"]; if (main_path) { diff --git a/examples/NuAnywhere/NuInject/Nukefile b/examples/NuAnywhere/NuInject/Nukefile index 26e2c7d..aad1767 100644 --- a/examples/NuAnywhere/NuInject/Nukefile +++ b/examples/NuAnywhere/NuInject/Nukefile @@ -13,7 +13,7 @@ (then (set @cflags "-isysroot /Developer/SDKs/MacOSX10.6.sdk ")) (else (set @cflags "-isysroot /Developer/SDKs/MacOSX10.7.sdk "))) (set @ldflags " -framework Cocoa -framework Nu -framework Carbon -framework mach_inject_bundle") - (set @arch '("x86_64"))) + (set @arch '("x86_64" ))) (else ;; If not Snow Leopard, then use the included version of mach_star (set @includes " -I../libinject/objc") diff --git a/objc/NuObject.m b/objc/NuObject.m index c22768c..750ddb0 100644 --- a/objc/NuObject.m +++ b/objc/NuObject.m @@ -343,19 +343,11 @@ - (id) handleUnknownMessage:(id) message withContext:(NSMutableDictionary *) con int message_length = [message length]; if (message_length == 1) { // try to automatically get an ivar - @try - { - NSString *ivarName = [[message car] stringValue]; - //NSLog(@"looking for ivar %@", ivarName); - // ivar name is the first (only) token of the message + NSString *ivarName = [[message car] stringValue]; + if ([self hasValueForIvar:ivarName]) { id result = [self valueForIvar:ivarName]; - // NSLog(@"returning %@ = %@", ivarName, [result description]); return result; } - @catch (id error) { - //NSLog(@"skipping this error: %@", [error description]); - // no ivar, keep going - } } else if (message_length == 2) { // try to automatically set an ivar @@ -397,13 +389,9 @@ - (id) valueForIvar:(NSString *) name if (result) { return result; } else { - NSLog(@"NO VALUE"); + return Nu__null; } - } - [NSException raise:@"NuNoInstanceVariable" - format:@"Unable to get ivar named %@ for object %@", - name, self]; - + } return Nu__null; } void *location = (void *)&(((char *)self)[ivar_getOffset(v)]); @@ -411,6 +399,29 @@ - (id) valueForIvar:(NSString *) name return result; } +- (BOOL) hasValueForIvar:(NSString *) name +{ + Ivar v = class_getInstanceVariable([self class], [name cStringUsingEncoding:NSUTF8StringEncoding]); + if (!v) { + // look for sparse ivar storage + NSMutableDictionary *sparseIvars = [self associatedObjectForKey:@"__nuivars"]; + if (sparseIvars) { + // NSLog(@"sparse %@", [sparseIvars description]); + id result = [sparseIvars objectForKey:name]; + if (result) { + return YES; + } else { + return NO; + } + } + return NO; + } + void *location = (void *)&(((char *)self)[ivar_getOffset(v)]); + id result = get_nu_value_from_objc_value(location, ivar_getTypeEncoding(v)); + return YES; +} + + - (void) setValue:(id) value forIvar:(NSString *)name { Ivar v = class_getInstanceVariable([self class], [name cStringUsingEncoding:NSUTF8StringEncoding]); diff --git a/tools/nuke b/tools/nuke index 650d3a0..8970339 100755 --- a/tools/nuke +++ b/tools/nuke @@ -150,7 +150,6 @@ (ivar (id) action) ;; a block which performs the necessary build action (ivar (int) isFile) ;; if nonzero, task is a file task (ivar (id) result) ;; the result of executing the task - (ivar-accessors) ;; @discussion Create a task with a specified name. (- (id) initWithName:(id) name is @@ -856,7 +855,7 @@ END) ;; an instance method of a NukeProject; so all instance variables in a Nukefile ;; belong to the NukeProject instance. (class NukeProject is NSObject - (ivars) + (ivar (id) datamodels (id) tasks (id) framework_install_path ) ;; Get the dictionary of tasks managed by a project. (- (id) tasks is @tasks)