--00c09f88cf33975b3704809a28d4
Content-Type: text/plain; charset=ISO-8859-1

I have found a small 1.8.7 bug that prevents proc_alloc from retrieving the
old Proc object if the Proc has a metaclass. Here's an example:

def foo
  yield
end

def bar(&block)
  puts Proc.new.object_id
  def block.foo() "FOO" end
  puts Proc.new.object_id
  baz(&block)
end

def baz(&block)
  puts Proc.new.object_id
  yield
end

foo { puts "HELLO" }
bar { puts "HELLO" }

Ruby 1.9, Rubinius and JRuby all return the same Proc object in all three
cases. Ruby 1.8.7 returns a different Proc object in each case, because of
the use of CLASS_OF in proc_alloc:

    if (!proc && ruby_block->block_obj && CLASS_OF(ruby_block->block_obj) klass) {
return ruby_block->block_obj;
    }

It seems this code is trying to make sure that MyProc.new doesn't return a
Proc object. The solution is a tiny patch to use rb_class_real:

index 8847ee5..54a0f46 100644
--- a/eval.c
+++ b/eval.c
@@ -8725,7 +8725,7 @@ proc_alloc(klass, proc)
        rb_warn("tried to create Proc object without a block");
     }

-    if (!proc && ruby_block->block_obj && CLASS_OF(ruby_block->block_obj)
klass) {
+    if (!proc && ruby_block->block_obj &&
rb_class_real(CLASS_OF(ruby_block->block_obj)) klass) {
        return ruby_block->block_obj;
     }
     block  ata_Make_Struct(klass, struct BLOCK, blk_mark, blk_free,
data);


Yehuda Katz
Developer | Engine Yard
(ph) 718.877.1325

--00c09f88cf33975b3704809a28d4
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div>I have found a small 1.8.7 bug that prevents        妣  庼򾼯 O  yield</div><div>end</div>

<div>/div><div>def bar(&amp;block)</div><div>  puts Proc.new.object_id</div><div>  def block.foo() &quot;FOO&quot; end</div><div>  puts Proc.new.object_id</div><div>  baz(&amp;block)</div><div>end</div><div>/div><div>

def baz(&amp;block)</div><div>  puts Proc.new.object_id</div><div>  yield</div><div>end</div><div>/div><div>foo { puts &quot;HELLO&quot;</div><div>bar { puts &quot;HELLO&quot; }</div><div><br></div><div>Ruby 1.9, Rubinius and JRuby all return the same Proc object in all three cases. Ruby 1.8.7 returns a different Proc object in each case, because of the usef CLASS_OF in proc_alloc:</div>

<div><br></div><div><div>    ¨  뭦  ƨ뭦    形墾	뭦껼
<div>    ¼򾼯                캼򾼯 嵮洶 

<div>--- a/eval.c</div><div>+++ b/eval.c</div><div>@@ -8725,7 +8725,7 @@ proc_alloc(klass, proc)</div><div>            }</div><div>/div><div>
-  ¨  뭦  ƨ뭦   <div>+  ¨  뭦  ƨ뭦ꩽ      뭦껼   }</div><div>   block = Data_Make_Struct(klass, struct BLOCK, blk_mark, blk_free, data);</div>

</div><div><br></div></div></div><br clear="all">Yehuda Katz<br>Developerngine Yard<br>(ph) 718.877.1325<br>

--00c09f88cf33975b3704809a28d4--