<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -81,7 +81,10 @@ END)
 (set @cc &quot;gcc&quot;)
 (set @leopard &quot;&quot;)
 (set @sdk
-     (cond ((NSFileManager directoryExistsNamed:&quot;/Developer/SDKs/MacOSX10.5.sdk&quot;)
+     (cond ((NSFileManager directoryExistsNamed:&quot;/Developer/SDKs/MacOSX10.6.sdk&quot;)
+            (set @leopard &quot;-DLEOPARD_OBJC2 -D__OBJC2__&quot;)
+            (&quot;-isysroot /Developer/SDKs/MacOSX10.6.sdk&quot;))
+           ((NSFileManager directoryExistsNamed:&quot;/Developer/SDKs/MacOSX10.5.sdk&quot;)
             (set @leopard &quot;-DLEOPARD_OBJC2 -D__OBJC2__&quot;)
             (&quot;-isysroot /Developer/SDKs/MacOSX10.5.sdk&quot;))
            ((NSFileManager directoryExistsNamed:&quot;/Developer/SDKs/MacOSX10.4u.sdk&quot;)
@@ -90,7 +93,7 @@ END)
 
 (ifDarwin
          (then (set @cflags &quot;-Wall -g -O2 -DDARWIN -DMACOSX #{@sdk} #{@leopard} -std=gnu99&quot;)
-               (set @mflags &quot;-fobjc-exceptions&quot;)) ;; Want to try Apple's new GC? Add this: &quot;-fobjc-gc&quot;
+               (set @mflags &quot;-fobjc-exceptions&quot;)) ;; To use garbage collection, add this flag: &quot;-fobjc-gc&quot;
          (else (set @cflags &quot;-Wall -DLINUX -g -std=gnu99 -fPIC&quot;)
                ;; (set @mflags &quot;-fobjc-exceptions -fconstant-string-class=NSConstantString&quot;)
                (set @mflags ((NSString stringWithShellCommand:&quot;gnustep-config --objc-flags&quot;) chomp))))
@@ -120,7 +123,7 @@ END)
      join))
 
 (ifDarwin
-         (set @public_headers (filelist &quot;include/Nu/Nu.h&quot;)))
+         (set @public_headers (filelist &quot;^include/Nu/Nu.h&quot;)))
 
 ;; Setup the tasks for compilation and framework-building.
 ;; These are defined in the nuke application source file.</diff>
      <filename>Nukefile</filename>
    </modified>
    <modified>
      <diff>@@ -1055,25 +1055,25 @@ id nu_calling_objc_method_handler(id target, Method_t m, NSMutableArray *args)
         }
         if (success) {
             result = get_nu_value_from_objc_value(result_value, &amp;return_type_buffer[0]);
-	    // NSLog(@&quot;result is %@&quot;, result);
-	    // NSLog(@&quot;retain count %d&quot;, [result retainCount]);
+            // NSLog(@&quot;result is %@&quot;, result);
+            // NSLog(@&quot;retain count %d&quot;, [result retainCount]);
             // Return values should not require a release.
             // Either they are owned by an existing object or are autoreleased.
             // Since these methods create new objects that aren't autoreleased, we autorelease them.
             // But we must never release placeholders.
-#ifdef DARWIN
+            #ifdef DARWIN
             bool already_retained =               // see Anguish/Buck/Yacktman, p. 104
                 (s == @selector(alloc)) || (s == @selector(allocWithZone:))
                 || (s == @selector(copy)) || (s == @selector(copyWithZone:))
                 || (s == @selector(mutableCopy)) || (s == @selector(mutableCopyWithZone:))
                 || (s == @selector(new));
-#else
+            #else
             bool already_retained =               // see Anguish/Buck/Yacktman, p. 104
                 sel_eq(s, @selector(alloc)) || sel_eq(s, @selector(allocWithZone:))
                 || sel_eq(s, @selector(copy)) || sel_eq(s, @selector(copyWithZone:))
                 || sel_eq(s, @selector(mutableCopy)) || sel_eq(s, @selector(mutableCopyWithZone:))
                 || sel_eq(s, @selector(new));
-#endif
+            #endif
             //NSLog(@&quot;already retained? %d&quot;, already_retained);
             if (already_retained) {
                 // Make sure this isn't an instance of a placeholder class.
@@ -1115,20 +1115,6 @@ id nu_calling_objc_method_handler(id target, Method_t m, NSMutableArray *args)
     return result;
 }
 
-@interface NSAutoreleasePool (UndocumentedInterface)
-+ (BOOL) autoreleasePoolExists;
-@end
-
-#ifdef LINUX
-@implementation NSAutoreleasePool (UndocumentedInterface)
-+ (BOOL) autoreleasePoolExists
-{
-    return true;                                  // this is wrong. Fix it later.
-}
-
-@end
-#endif
-
 @interface NSMethodSignature (UndocumentedInterface)
 + (id) signatureWithObjCTypes:(const char*)types;
 @end
@@ -1139,9 +1125,10 @@ static void objc_calling_nu_method_handler(ffi_cif* cif, void* returnvalue, void
     id rcv = *((id*)args[0]);                     // this is the object getting the message
     // unused: SEL sel = *((SEL*)args[1]);
 
-    // we might need an autorelease pool (added for detachNewThreadSelector:toTarget:withObject:)
-    NSAutoreleasePool *pool = [NSAutoreleasePool autoreleasePoolExists] ? 0 : [[NSAutoreleasePool alloc] init];
-
+    // in rare cases, we need an autorelease pool (specifically detachNewThreadSelector:toTarget:withObject:)
+    // previously we used a private api to verify that one existed before creating a new one. Now we just make one. 
+    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+    
     NuBlock *block = ((NuBlock **)userdata)[1];
     //NSLog(@&quot;----------------------------------------&quot;);
     //NSLog(@&quot;calling block %@&quot;, [block stringValue]);
@@ -1161,10 +1148,10 @@ static void objc_calling_nu_method_handler(ffi_cif* cif, void* returnvalue, void
     char *resultType = (((char **)userdata)[0])+1;// skip the first character, it's a flag
     set_objc_value_from_nu_value(returnvalue, result, resultType);
     #ifdef __ppc__
-	// It appears that at least on PowerPC architectures, small values (short, char, ushort, uchar) passed in via 
-	// the ObjC runtime use their actual type while function return values are coerced up to integers. 
-	// I suppose this is because values are passed as arguments in memory and returned in registers.  
-	// This may also be the case on x86 but is unobserved because x86 is little endian.
+    // It appears that at least on PowerPC architectures, small values (short, char, ushort, uchar) passed in via
+    // the ObjC runtime use their actual type while function return values are coerced up to integers.
+    // I suppose this is because values are passed as arguments in memory and returned in registers.
+    // This may also be the case on x86 but is unobserved because x86 is little endian.
     switch (resultType[0]) {
         case 'C':
         {
@@ -1188,12 +1175,19 @@ static void objc_calling_nu_method_handler(ffi_cif* cif, void* returnvalue, void
         }
     }
     #endif
+
     if (((char **)userdata)[0][0] == '!') {
         //NSLog(@&quot;retaining result for object %@, count = %d&quot;, *(id *)returnvalue, [*(id *)returnvalue retainCount]);
         [*((id *)returnvalue) retain];
     }
     [arguments release];
-    [pool release];
+    if (pool) {
+        if (resultType[0] == '@')
+            [*((id *)returnvalue) retain];
+        [pool release];
+        if (resultType[0] == '@')
+            [*((id *)returnvalue) autorelease];
+    }
 }
 
 char **generate_userdata(SEL sel, NuBlock *block, const char *signature)
@@ -1311,11 +1305,11 @@ id add_method_to_class(Class c, NSString *methodName, NSString *signature, NuBlo
     if (!nu_block_table) nu_block_table = st_init_numtable();
     // watch for problems caused by these ugly casts...
     st_insert(nu_block_table, (long) imp, (long) block);
-#ifdef DARWIN
-#ifndef IPHONE
+    #ifdef DARWIN
+    #ifndef IPHONE
     [[NSGarbageCollector defaultCollector] disableCollectorForPointer: block];
-#endif
-#endif
+    #endif
+    #endif
     // insert the method handler in the class method table
     nu_class_replaceMethod(c, selector, imp, signature_str);
     #ifdef DARWIN
@@ -1333,7 +1327,8 @@ id add_method_to_class(Class c, NSString *methodName, NSString *signature, NuBlo
 
 @implementation NuBridgedFunction
 
-- (void) dealloc {
+- (void) dealloc
+{
     free(name);
     free(signature);
     [super dealloc];</diff>
      <filename>objc/bridge.m</filename>
    </modified>
    <modified>
      <diff>@@ -274,10 +274,12 @@ void NuInit()
         [NSView exchangeInstanceMethod:@selector(retain) withMethod:@selector(nuRetain)];
 
         // Enable support for protocols in Nu.  Apple doesn't have an API for this, so we use our own.
+	#ifndef __DARWIN_10_6_AND_LATER
         extern void nu_initProtocols();
         nu_initProtocols();
         // if you don't like making Protocol a subclass of NSObject (see nu_initProtocols), you can do this instead.
         // transplant_nu_methods([Protocol class], [NSObject class]);
+	#endif
 
         #ifndef MININUSH
         // Load some standard files</diff>
      <filename>objc/nu.m</filename>
    </modified>
    <modified>
      <diff>@@ -159,8 +159,9 @@ limitations under the License.
     return Nu__null;
 }
 
+
 - (id) sendMessage:(id)cdr withContext:(NSMutableDictionary *)context
-{
+{   
     // By themselves, Objective-C objects evaluate to themselves.
     if (!cdr || (cdr == Nu__null))
         return self;</diff>
      <filename>objc/object.m</filename>
    </modified>
    <modified>
      <diff>@@ -41,6 +41,7 @@ struct objc_method_description_list
 #endif
 
 #ifndef IPHONE
+#ifndef __DARWIN_10_6_AND_LATER
 #ifndef __x86_64__
 
 @interface Protocol : NSObject
@@ -345,3 +346,4 @@ void nu_initProtocols()
 @end
 #endif
 #endif
+#endif</diff>
      <filename>objc/protocol.m</filename>
    </modified>
    <modified>
      <diff>@@ -205,7 +205,7 @@ static int add_to_array(st_data_t k, st_data_t v, st_data_t d)
     if (valueInContext)
         return valueInContext;
 
-    #if false
+    #if 0
     // if it's not there, try the next context up
     id parentContext = [context objectForKey:@&quot;context&quot;];
     if (parentContext) {</diff>
      <filename>objc/symbol.m</filename>
    </modified>
    <modified>
      <diff>@@ -46,8 +46,8 @@
 
 (class TestClassMethodMissing is NuTestCase
      (- (id) testCustomSubclassClassMethodMissing is
-        (assert_equal &quot;Handling message (hello)&quot; (MySampleClass hello) )
-        (assert_equal &quot;Handling message (nu: \&quot;rocks\&quot;)&quot; (MySampleClass nu:&quot;rocks&quot;) ))
+        (assert_equal &quot;Handling message (hello)&quot; (MySampleClass hello))
+        (assert_equal &quot;Handling message (nu: \&quot;rocks\&quot;)&quot; (MySampleClass nu:&quot;rocks&quot;)))
      
      (if (eq (uname) &quot;Darwin&quot;)
          (- (id) testNSWorkspaceSingletonRemoval is</diff>
      <filename>test/test_classes.nu</filename>
    </modified>
    <modified>
      <diff>@@ -4,24 +4,27 @@
 ;;  Copyright (c) 2007 Tim Burks, Neon Design Technology, Inc.
 
 (if (eq (uname) &quot;Darwin&quot;)
-    
-    (class TestProtocols is NuTestCase
-         
-         (imethod (id) testSimple is
-              ;; first define a class with two methods
-              (class Foo is NSObject
-                   (- hello is &quot;hello&quot;)
-                   (- goodbye is &quot;goodbye&quot;))
-              ;; make sure that both methods work
-              (set foo ((Foo alloc) init))
-              (assert_equal &quot;hello&quot; (foo hello))
-              (assert_equal &quot;goodbye&quot; (foo goodbye))
-              ;; now declare a protocol that includes only one of them
-              (protocol DontSayGoodbye
-                   (- (id) hello))
-              (assert_equal 1 ((DontSayGoodbye methodDescriptions) count))
-              ;; give the instance and protocol to a protocol checker
-              (set bar ((NSProtocolChecker alloc) initWithTarget:foo protocol:DontSayGoodbye))
-              ;; try the two methods; only the one in the protocol should be allowed
-              (assert_equal &quot;hello&quot; (bar hello))
-              (assert_throws &quot;NuUnknownMessage&quot; (bar goodbye)))))
+    (set version (NSString stringWithShellCommand:&quot;uname -r&quot;))
+    (set v (((version componentsSeparatedByString:&quot;.&quot;) 0) intValue))
+    (if (&lt; v 10) ;; We can't do this in Snow Leopard
+        
+        (class TestProtocols is NuTestCase
+             
+             (imethod (id) testSimple is
+                  ;; first define a class with two methods
+                  (class Foo is NSObject
+                       (- hello is &quot;hello&quot;)
+                       (- goodbye is &quot;goodbye&quot;))
+                  ;; make sure that both methods work
+                  (set foo ((Foo alloc) init))
+                  (assert_equal &quot;hello&quot; (foo hello))
+                  (assert_equal &quot;goodbye&quot; (foo goodbye))
+                  ;; now declare a protocol that includes only one of them
+                  (protocol DontSayGoodbye
+                       (- (id) hello))
+                  (assert_equal 1 ((DontSayGoodbye methodDescriptions) count))
+                  ;; give the instance and protocol to a protocol checker
+                  (set bar ((NSProtocolChecker alloc) initWithTarget:foo protocol:DontSayGoodbye))
+                  ;; try the two methods; only the one in the protocol should be allowed
+                  (assert_equal &quot;hello&quot; (bar hello))
+                  (assert_throws &quot;NuUnknownMessage&quot; (bar goodbye))))))</diff>
      <filename>test/test_protocols.nu</filename>
    </modified>
    <modified>
      <diff>@@ -45,27 +45,28 @@
             
             ;; tie Shannon's shoes.
             (u beginUndoGrouping)
-            (u prepareWithInvocationTarget:shannon)
-            (u tieShoes)
+            ;; Beginning with Mac OS 10.6, prepareWithInvocationTarget returns a proxy object
+            (set p (u prepareWithInvocationTarget:shannon))
+            (p tieShoes)
             (u endUndoGrouping)
             
             ;; tickle her again.
             (u beginUndoGrouping)
-            (u prepareWithInvocationTarget:shannon)
-            (u tickle:3)
+            (set p (u prepareWithInvocationTarget:shannon))
+            (p tickle:3)
             (u endUndoGrouping)
             
             ;; tickle her.
             (u beginUndoGrouping)
-            (u prepareWithInvocationTarget:shannon)
+            (set p (u prepareWithInvocationTarget:shannon))
             (set one 1)
-            (u tickle:(+ one one one))
+            (p tickle:(+ one one one))
             (u endUndoGrouping)
             
             ;; first, tie Shannon's shoes.
             (u beginUndoGrouping)
-            (u prepareWithInvocationTarget:shannon)
-            (u tieShoes)
+            (set p (u prepareWithInvocationTarget:shannon))
+            (p tieShoes)
             (u endUndoGrouping)
             
             (assert_equal 1 (u canUndo))</diff>
      <filename>test/test_undo.nu</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>d834fb508eac1a2fa48de4ca8a4507d812b94c79</id>
    </parent>
  </parents>
  <author>
    <name>Tim Burks</name>
    <email>tim@neontology.com</email>
  </author>
  <url>http://github.com/timburks/nu/commit/eac09709c37e57c7bb676989d230f0373e2a9189</url>
  <id>eac09709c37e57c7bb676989d230f0373e2a9189</id>
  <committed-date>2009-08-29T19:47:28-07:00</committed-date>
  <authored-date>2009-08-29T19:47:28-07:00</authored-date>
  <message>Snow Leopard updates.

- the new Objective-C runtime prevents us from creating and modifying protocols.
- NSUndoManager behaves differently (only affects test/test_undo.nu)
- Nu code called from ObjC is always wrapped in an autorelease pool.
- A problem with returning objects out of these autorelease pools was fixed.
- Minor compilation-related fixes.</message>
  <tree>25233d86f18ca5a2b70160d7bad238adec76e508</tree>
  <committer>
    <name>Tim Burks</name>
    <email>tim@neontology.com</email>
  </committer>
</commit>
