ruby-changes:33504
From: nobu <ko1@a...>
Date: Mon, 14 Apr 2014 17:20:18 +0900 (JST)
Subject: [ruby-changes:33504] nobu:r45585 (trunk): proc.c: use already included ancestor iclass
nobu 2014-04-14 17:20:10 +0900 (Mon, 14 Apr 2014) New Revision: 45585 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=45585 Log: proc.c: use already included ancestor iclass * proc.c (umethod_bind): use the ancestor iclass instead of new iclass to get rid of infinite recursion, if the defined module is already included. [ruby-core:62014] [Bug #9721] Modified files: trunk/ChangeLog trunk/proc.c trunk/test/ruby/test_super.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 45584) +++ ChangeLog (revision 45585) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Mon Apr 14 17:20:10 2014 Nobuyoshi Nakada <nobu@r...> + + * proc.c (umethod_bind): use the ancestor iclass instead of new + iclass to get rid of infinite recursion, if the defined module + is already included. [ruby-core:62014] [Bug #9721] + Sun Apr 13 12:46:58 2014 Tanaka Akira <akr@f...> * bignum.c (SIZEOF_BDIGIT): Renamed from SIZEOF_BDIGITS. Index: proc.c =================================================================== --- proc.c (revision 45584) +++ proc.c (revision 45585) @@ -2044,7 +2044,13 @@ umethod_bind(VALUE method, VALUE recv) https://github.com/ruby/ruby/blob/trunk/proc.c#L2044 if (bound->me->def) bound->me->def->alias_count++; rclass = CLASS_OF(recv); if (BUILTIN_TYPE(bound->defined_class) == T_MODULE) { - rclass = rb_include_class_new(methclass, rclass); + VALUE ic = rb_class_search_ancestor(rclass, bound->defined_class); + if (ic) { + rclass = ic; + } + else { + rclass = rb_include_class_new(methclass, rclass); + } } bound->recv = recv; bound->rclass = rclass; Index: test/ruby/test_super.rb =================================================================== --- test/ruby/test_super.rb (revision 45584) +++ test/ruby/test_super.rb (revision 45585) @@ -469,11 +469,28 @@ class TestSuper < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_super.rb#L469 end end - m = b.instance_method(:foo).bind(Object.new.extend(a)) + um = b.instance_method(:foo) + + m = um.bind(Object.new.extend(a)) result = [] assert_nothing_raised(NoMethodError, bug9721) do m.call(result) end assert_equal(%w[B A], result, bug9721) + + bug9740 = '[ruby-core:62017] [Bug #9740]' + + b.module_eval do + define_method(:foo) do |result| + um.bind(self).call(result) + end + end + + result.clear + o = Object.new.extend(a).extend(b) + assert_nothing_raised(NoMethodError, SystemStackError, bug9740) do + o.foo(result) + end + assert_equal(%w[B A], result, bug9721) end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/