[macruby-changes] [4971] MacRuby/trunk

source_changes at macosforge.org source_changes at macosforge.org
Thu Dec 2 19:27:09 PST 2010


Revision: 4971
          http://trac.macosforge.org/projects/ruby/changeset/4971
Author:   lsansonetti at apple.com
Date:     2010-12-02 19:27:04 -0800 (Thu, 02 Dec 2010)
Log Message:
-----------
compile C-level blocks in the autozone heap and emit a write barrier to the original ruby Proc object, to avoid premature garbage collection of the Proc when calling the C-level block

Modified Paths:
--------------
    MacRuby/trunk/compiler.cpp
    MacRuby/trunk/kernel.c

Modified: MacRuby/trunk/compiler.cpp
===================================================================
--- MacRuby/trunk/compiler.cpp	2010-12-02 23:22:39 UTC (rev 4970)
+++ MacRuby/trunk/compiler.cpp	2010-12-03 03:27:04 UTC (rev 4971)
@@ -5522,15 +5522,16 @@
 		    return funcptr;
 		}
 
-		// A C-level block. We allocate on the stack the literal
+		// A C-level block. We allocate on the auto heap the literal
 		// structure following the ABI, initialize it then pass
 		// a pointer to it.
-		Value *block_lit = new AllocaInst(BlockLiteralTy, "", bb);
+		Value *block_lit = compile_xmalloc(GET_CORE()->get_sizeof(BlockLiteralTy));
 		Value *args[] = {
 		    block_lit,
-		    funcptr
+		    funcptr,
+		    val
 		};
-		CallInst::Create(initBlockFunc, args, args + 2, "", bb);
+		CallInst::Create(initBlockFunc, args, args + 3, "", bb);
 		return new BitCastInst(block_lit, PtrTy, "", bb);
 	    }
 	    break;

Modified: MacRuby/trunk/kernel.c
===================================================================
--- MacRuby/trunk/kernel.c	2010-12-02 23:22:39 UTC (rev 4970)
+++ MacRuby/trunk/kernel.c	2010-12-03 03:27:04 UTC (rev 4971)
@@ -1055,22 +1055,25 @@
     int reserved;
     void *imp;
     struct ruby_block_descriptor *descriptor;
+    VALUE ruby_proc;
 };
 
 static struct ruby_block_descriptor ruby_block_descriptor_value = {
     0, sizeof(struct ruby_block_literal)
 };
 
-#if MAC_OS_X_VERSION_MAX_ALLOWED < 1070
-extern void *_NSConcreteStackBlock[32];
-#endif
+extern void *_NSConcreteAutoBlock[32];
 
+#define __MR_BLOCK_IS_GC		(1 << 27)
+#define __MR_BLOCK_HAS_DESCRIPTOR 	(1 << 29)
+
 PRIMITIVE void
-vm_init_c_block(struct ruby_block_literal *b, void *imp)
+vm_init_c_block(struct ruby_block_literal *b, void *imp, VALUE proc)
 {
-    b->isa = &_NSConcreteStackBlock;
-    b->flags = (1 << 29);
+    b->isa = &_NSConcreteAutoBlock;
+    b->flags = __MR_BLOCK_IS_GC | __MR_BLOCK_HAS_DESCRIPTOR;
     b->reserved = 0;
     b->imp = imp;
     b->descriptor = &ruby_block_descriptor_value;
+    GC_WB(&b->ruby_proc, proc);
 }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20101202/d99ae9be/attachment.html>


More information about the macruby-changes mailing list