ruby-changes:33288
From: nobu <ko1@a...>
Date: Thu, 20 Mar 2014 12:31:35 +0900 (JST)
Subject: [ruby-changes:33288] nobu:r45367 (trunk): vm_method.c: fix infinite recursion
nobu 2014-03-20 12:31:28 +0900 (Thu, 20 Mar 2014) New Revision: 45367 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=45367 Log: vm_method.c: fix infinite recursion * vm_method.c (rb_method_entry_get_without_cache): get rid of infinite recursion at aliases in a subclass and a superclass. return actually defined class for other than singleton class. [ruby-core:60431] [Bug #9475] Modified files: trunk/ChangeLog trunk/test/ruby/test_alias.rb trunk/vm_method.c Index: ChangeLog =================================================================== --- ChangeLog (revision 45366) +++ ChangeLog (revision 45367) @@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Thu Mar 20 12:31:26 2014 Nobuyoshi Nakada <nobu@r...> + + * vm_method.c (rb_method_entry_get_without_cache): get rid of + infinite recursion at aliases in a subclass and a superclass. + return actually defined class for other than singleton class. + [ruby-core:60431] [Bug #9475] + Wed Mar 19 17:13:06 2014 Eric Wong <e@8...> * time.c (time_mload): freeze and preserve marshal-loaded time zone Index: vm_method.c =================================================================== --- vm_method.c (revision 45366) +++ vm_method.c (revision 45367) @@ -578,8 +578,15 @@ rb_method_entry_get_without_cache(VALUE https://github.com/ruby/ruby/blob/trunk/vm_method.c#L578 VALUE defined_class; rb_method_entry_t *me = search_method(klass, id, &defined_class); - if (me && RB_TYPE_P(me->klass, T_ICLASS)) - defined_class = me->klass; + if (me) { + switch (BUILTIN_TYPE(me->klass)) { + case T_CLASS: + if (RBASIC(klass)->flags & FL_SINGLETON) break; + /* fall through */ + case T_ICLASS: + defined_class = me->klass; + } + } if (ruby_running) { if (OPT_GLOBAL_METHOD_CACHE) { Index: test/ruby/test_alias.rb =================================================================== --- test/ruby/test_alias.rb (revision 45366) +++ test/ruby/test_alias.rb (revision 45367) @@ -132,4 +132,51 @@ class TestAlias < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_alias.rb#L132 GC.verify_internal_consistency } end + + def test_cyclic_zsuper + bug9475 = '[ruby-core:60431] [Bug #9475]' + + a = Module.new do + def foo + "A" + end + end + + b = Class.new do + include a + attr_reader :b + + def foo + @b ||= 0 + raise SystemStackError if (@b += 1) > 1 + # "foo from B" + super + "B" + end + end + + c = Class.new(b) do + alias orig_foo foo + + def foo + # "foo from C" + orig_foo + "C" + end + end + + b.class_eval do + alias orig_foo foo + attr_reader :b2 + + def foo + @b2 ||= 0 + raise SystemStackError if (@b2 += 1) > 1 + # "foo from B (again)" + orig_foo + "B2" + end + end + + assert_nothing_raised(SystemStackError, bug9475) do + assert_equal("ABC", c.new.foo, bug9475) + end + end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/