ruby-changes:24599
From: shugo <ko1@a...>
Date: Tue, 7 Aug 2012 11:44:48 +0900 (JST)
Subject: [ruby-changes:24599] shugo:r36650 (trunk): * vm_method.c (rb_redefine_opt_method): use RCLASS_ORIGIN to avoid
shugo 2012-08-07 11:44:24 +0900 (Tue, 07 Aug 2012) New Revision: 36650 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=36650 Log: * vm_method.c (rb_redefine_opt_method): use RCLASS_ORIGIN to avoid SEGV when a module-prepended class is refined. Modified files: trunk/ChangeLog trunk/test/ruby/test_refinement.rb trunk/vm_method.c Index: ChangeLog =================================================================== --- ChangeLog (revision 36649) +++ ChangeLog (revision 36650) @@ -1,3 +1,8 @@ +Tue Aug 7 11:35:37 2012 Shugo Maeda <shugo@r...> + + * vm_method.c (rb_redefine_opt_method): use RCLASS_ORIGIN to avoid + SEGV when a module-prepended class is refined. + Tue Aug 7 10:46:37 2012 NAKAMURA Usaku <usa@r...> * test/ruby/test_file_exhaustive.rb Index: vm_method.c =================================================================== --- vm_method.c (revision 36649) +++ vm_method.c (revision 36650) @@ -1415,13 +1415,14 @@ { st_data_t data; rb_method_entry_t *me = 0; + VALUE origin = RCLASS_ORIGIN(klass); - if (!st_lookup(RCLASS_M_TBL(klass), mid, &data) || + if (!st_lookup(RCLASS_M_TBL(origin), mid, &data) || !(me = (rb_method_entry_t *)data) || (!me->def || me->def->type == VM_METHOD_TYPE_UNDEF)) { return; } - rb_vm_check_redefinition_opt_method(me, klass); + rb_vm_check_redefinition_opt_method(me, origin); } void Index: test/ruby/test_refinement.rb =================================================================== --- test/ruby/test_refinement.rb (revision 36649) +++ test/ruby/test_refinement.rb (revision 36650) @@ -300,5 +300,29 @@ assert_equal("m2#bar", m.call_bar("abc")) assert_equal("m3#baz", m.call_baz("abc")) end + + def test_refine_prepended_class + m1 = Module.new { + def foo + super << :m1 + end + } + c = Class.new { + prepend m1 + + def foo + [:c] + end + } + m2 = Module.new { + refine c do + def foo + super << :m2 + end + end + } + obj = c.new + assert_equal([:c, :m1, :m2], m2.module_eval { obj.foo }) + end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/