Bug #3786

instance_execにメソッドをわたした場合の挙動

Added by at_akada (Takada Atsushi) over 1 year ago. Updated about 1 year ago.

[redmine4ruby-lang:289]
Status:Closed Start date:09/05/2010
Priority:Normal Due date:
Assignee:ko1 (Koichi Sasada) % Done:

100%

Category:YARV
Target version:1.9.2
ruby -v:ruby 1.9.2p0 (2010-08-18 revision 29036) [i686-linux]

Description

はじめまして。Ruby1.9.2のバグらしきものを発見したので報告します。
以下のコードを実行すると、エラーで落ちます。

バージョンは以下。ちなみに1.9.1では再現しませんでした。
$ /usr/klab/app/ruby-1.9.2/bin/ruby -v
ruby 1.9.2p0 (2010-08-18 revision 29036) [i686-linux]      


class Cl
    def metho
        p self
    end
end

i = Cl::new
metho = i.method(:metho)
1.upto(30) do
    "".instance_exec(&metho)
end


出力は以下の通りです。
bug.rb:10: [BUG] vm_get_cref: unreachable                  
ruby 1.9.2p0 (2010-08-18 revision 29036) [i686-linux]      

-- control frame ----------                                
c:0007 p:---- s:0019 b:0019 l:000018 d:000018 CFUNC  :instance_exec
c:0006 p:0013 s:0016 b:0016 l:0022dc d:000015 BLOCK  bug.rb:10
c:0005 p:---- s:0014 b:0014 l:000013 d:000013 FINISH       
c:0004 p:---- s:0012 b:0012 l:000011 d:000011 CFUNC  :upto 
c:0003 p:0056 s:0008 b:0008 l:0022dc d:00093c EVAL   bug.rb:9
c:0002 p:---- s:0004 b:0004 l:000003 d:000003 FINISH        
c:0001 p:0000 s:0002 b:0002 l:0022dc d:0022dc TOP          
---------------------------                                
-- Ruby level backtrace information ----------------------------------------
bug.rb:9:in `<main>'                                        
bug.rb:9:in `upto'                                         
bug.rb:10:in `block in <main>'                             
bug.rb:10:in `instance_exec'   

-- C level backtrace information -------------------------------------------
/usr/app/ruby-1.9.2/bin/ruby(rb_vm_bugreport+0xbd) [0x816d68d]
/usr/app/ruby-1.9.2/bin/ruby [0x81ae41e]              
/usr/app/ruby-1.9.2/bin/ruby(rb_bug+0x28) [0x81ae4b8] 
/usr/app/ruby-1.9.2/bin/ruby [0x816972c]              
/usr/app/ruby-1.9.2/bin/ruby [0x815846d]              
/usr/app/ruby-1.9.2/bin/ruby [0x8160542]              
/usr/app/ruby-1.9.2/bin/ruby [0x8161c64]              
/usr/app/ruby-1.9.2/bin/ruby [0x81672f4]              
/usr/app/ruby-1.9.2/bin/ruby(rb_yield+0x4f) [0x8168a6f]
/usr/app/ruby-1.9.2/bin/ruby [0x808f559]              
/usr/app/ruby-1.9.2/bin/ruby [0x8160542]              
/usr/app/ruby-1.9.2/bin/ruby [0x8161c64]              
/usr/app/ruby-1.9.2/bin/ruby [0x81672f4]              
/usr/app/ruby-1.9.2/bin/ruby(rb_iseq_eval_main+0x1d3) [0x8167643]
/usr/app/ruby-1.9.2/bin/ruby [0x805e2c2]              
/usr/app/ruby-1.9.2/bin/ruby(ruby_run_node+0x32) [0x805fb72]
/usr/app/ruby-1.9.2/bin/ruby(main+0x60) [0x805d580]   
/lib/i686/cmov/libc.so.6(__libc_start_main+0xe5) [0xb7d6ab55]
/usr/app/ruby-1.9.2/bin/ruby [0x805d481]

Related issues

duplicates ruby-trunk - Bug #3860: VM aborts when calling instance_eval on a Method converte... Closed 09/23/2010
duplicated by Backport92 - Backport #3868: Segfault in 1.9.2 when using instance_eval with a Method ... Closed 09/24/2010
duplicated by Backport92 - Backport #3957: instance_exec and instance_eval crash ruby when passed '&... Closed 10/17/2010

Associated revisions

Revision 29318
Added by nobu (Nobuyoshi Nakada) over 1 year ago

* vm_insnhelper.c (vm_cref_push): no outer cref is needed for proc from method. Bug #3786, Bug #3860, [ruby-core:32501]

Revision 29318
Added by nobu (Nobuyoshi Nakada) over 1 year ago

* vm_insnhelper.c (vm_cref_push): no outer cref is needed for proc from method. Bug #3786, Bug #3860, [ruby-core:32501]

History

Updated by naruse (Yui NARUSE) over 1 year ago

  • Category set to YARV
  • Status changed from Open to Assigned
  • Assignee set to ko1 (Koichi Sasada)
  • Target version set to 1.9.2
  • ruby -v set to ruby 1.9.2p0 (2010-08-18 revision 29036) [i686-linux]
trunk でも再現しますね

Updated by wanabe (_ wanabe) over 1 year ago

ワナベと申します。

vm_get_cref が C レベルの iseq を想定していないように見えます。
これでどうでしょうか。

diff --git a/vm_insnhelper.c b/vm_insnhelper.c
index 985a2fb..063e2bf 100644
--- a/vm_insnhelper.c
+++ b/vm_insnhelper.c
@@ -1059,7 +1059,11 @@ vm_get_cref(const rb_iseq_t *iseq, const VALUE *lfp, const VALUE *dfp)
     while (1) {
        if (lfp == dfp) {
-           cref = iseq->cref_stack;
+           if (RUBY_VM_NORMAL_ISEQ_P(iseq)) {
+               cref = iseq->cref_stack;
+           } else {
+               cref = NEW_BLOCK(0);
+           }
            break;
        }
        else if (dfp[-1] != Qnil) {

Updated by nobu (Nobuyoshi Nakada) over 1 year ago

  • Status changed from Assigned to Closed
  • % Done changed from 0 to 100
This issue was solved with changeset r29318.
Takada, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.

Also available in: Atom PDF