Project

General

Profile

Actions

Bug #926

closed

module_function中のsuperでSystemStackError

Added by wanabe (_ wanabe) over 15 years ago. Updated almost 13 years ago.

Status:
Closed
ruby -v:
Backport:
[ruby-dev:37587]

Description

=begin
ワナベと申します。

以下のスクリプトでSystemStackErrorになります。

$ ./ruby -ve '
module Foo
def foo
super
end
module_function :foo
end
Foo.foo
'
ruby 1.9.1 (2008-12-24 patchlevel-5000 trunk 20971) [i386-mingw32]
-e:4:in foo': stack level too deep (SystemStackError) from -e:4:in foo'
from -e:4:in foo' from -e:4:in foo'
from -e:4:in foo' from -e:4:in foo'
from -e:4:in foo' from -e:4:in foo'
from -e:4:in foo' ... 8720 levels... from -e:4:in foo'
from -e:4:in foo' from -e:4:in foo'
from -e:8:in `'

vm_search_normal_superclass() がスーパークラスを見つけられなかったときに
渡された元クラスをそのまま返しているのが原因のように思います。
この場合の適切なスーパークラスを決める方法がわからなかったので、
0を返すようにしてパッチを書いてみました。
副作用で [Bug #730] も SystemStackError にならなくなるようです。

Index: insns.def

--- insns.def (revision 20971)
+++ insns.def (working copy)
@@ -1015,13 +1015,15 @@
rb_block_t *blockptr = !(op_flag & VM_CALL_ARGS_BLOCKARG_BIT) ?
GET_BLOCK_PTR() : 0;
int num = caller_setup_args(th, GET_CFP(), op_flag, op_argc,
blockiseq, &blockptr);
VALUE recv, klass;

  • NODE *mn;
  • NODE *mn = 0;
    ID id;
    const VALUE flag = VM_CALL_SUPER_BIT | VM_CALL_FCALL_BIT;

    recv = GET_SELF();
    vm_search_superclass(GET_CFP(), GET_ISEQ(), recv, TOPN(num), &id, &klass);

  • mn = rb_method_node(klass, id);
  • if (klass) {

  • mn = rb_method_node(klass, id);

  • }

    CALL_METHOD(num, blockptr, flag, id, mn, recv);
    }
    Index: vm_insnhelper.c
    ===================================================================
    --- vm_insnhelper.c (revision 20971)
    +++ vm_insnhelper.c (working copy)
    @@ -1179,6 +1179,9 @@
    }
    k = RCLASS_SUPER(k);
    }

  • if (!k) {

  •  klass = 0;
    
  • }
    }
    return klass;
    }

--
ワナベ
=end

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0