[macruby-changes] [3048] MacRuby/trunk

source_changes at macosforge.org source_changes at macosforge.org
Tue Nov 24 22:53:36 PST 2009


Revision: 3048
          http://trac.macosforge.org/projects/ruby/changeset/3048
Author:   martinlagardette at apple.com
Date:     2009-11-24 22:53:32 -0800 (Tue, 24 Nov 2009)
Log Message:
-----------

 - Fixes #441 : Do not cache blocks for functions
 - Added a test-case for the VM

Modified Paths:
--------------
    MacRuby/trunk/dispatcher.cpp
    MacRuby/trunk/test_vm/block.rb

Modified: MacRuby/trunk/dispatcher.cpp
===================================================================
--- MacRuby/trunk/dispatcher.cpp	2009-11-25 04:00:22 UTC (rev 3047)
+++ MacRuby/trunk/dispatcher.cpp	2009-11-25 06:53:32 UTC (rev 3048)
@@ -1604,19 +1604,23 @@
     std::map<void *, rb_vm_block_t *>::iterator iter = blocks.find(key);
 
     rb_vm_block_t *b;
+    const int create_block_mask =
+	VM_BLOCK_ACTIVE | VM_BLOCK_PROC | VM_BLOCK_IFUNC;
 
-    if ((iter == blocks.end())
-	|| (iter->second->flags & (VM_BLOCK_ACTIVE | VM_BLOCK_PROC))) {
+    if ((iter == blocks.end()) || (iter->second->flags & create_block_mask)) {
+	const bool is_ifunc = (iter != blocks.end())
+	    && ((iter->second->flags & VM_BLOCK_IFUNC) == VM_BLOCK_IFUNC);
 
-	if (iter != blocks.end()) {
+	if (!is_ifunc && iter != blocks.end()) {
 	    rb_objc_release(iter->second);
 	}
-
 	b = (rb_vm_block_t *)xmalloc(sizeof(rb_vm_block_t)
 		+ (sizeof(VALUE *) * dvars_size));
-	rb_objc_retain(b);
+	if (!is_ifunc) {
+	    rb_objc_retain(b);
+	    blocks[key] = b;
+	}
 
-	blocks[key] = b;
 	*cached = false;
     }
     else {

Modified: MacRuby/trunk/test_vm/block.rb
===================================================================
--- MacRuby/trunk/test_vm/block.rb	2009-11-25 04:00:22 UTC (rev 3047)
+++ MacRuby/trunk/test_vm/block.rb	2009-11-25 06:53:32 UTC (rev 3048)
@@ -720,3 +720,12 @@
   end
   Y.new.foo { p :ok }
 }
+
+assert '[["1-1", "1-2", "1-3"], ["2-1", "2-2", "2-3"], ["3-1", "3-2", "3-3"]]', %{
+  arrays = (1..3).map do |i|
+    (1..3).map do |j|
+      '%d-%d' % [i, j]
+    end
+  end
+  p arrays
+}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20091124/4a70c8f7/attachment.html>


More information about the macruby-changes mailing list