ruby-changes:37627
From: naruse <ko1@a...>
Date: Tue, 24 Feb 2015 10:31:28 +0900 (JST)
Subject: [ruby-changes:37627] naruse:r49708 (ruby_2_2): merge revision(s) 49685, 49687: [Backport #10885]
naruse 2015-02-24 10:31:16 +0900 (Tue, 24 Feb 2015) New Revision: 49708 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=49708 Log: merge revision(s) 49685,49687: [Backport #10885] * vm_insnhelper.c (rb_vm_rewrite_cref_stack): copy nd_refinements of orignal crefs. It fixes segmentation fault when calling refined method in duplicate module. [ruby-dev:48878] [Bug #10885] * vm_core.h, class.c: change accordingly. * test/ruby/test_refinement.rb: add a test for above. of original crefs. It fixes segmentation fault when calling Modified directories: branches/ruby_2_2/ Modified files: branches/ruby_2_2/ChangeLog branches/ruby_2_2/class.c branches/ruby_2_2/test/ruby/test_refinement.rb branches/ruby_2_2/version.h branches/ruby_2_2/vm_core.h branches/ruby_2_2/vm_insnhelper.c Index: ruby_2_2/ChangeLog =================================================================== --- ruby_2_2/ChangeLog (revision 49707) +++ ruby_2_2/ChangeLog (revision 49708) @@ -1,3 +1,13 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_2/ChangeLog#L1 +Tue Feb 24 10:30:59 2015 Kazuki Tsujimoto <kazuki@c...> + + * vm_insnhelper.c (rb_vm_rewrite_cref_stack): copy nd_refinements + of original crefs. It fixes segmentation fault when calling + refined method in duplicate module. [ruby-dev:48878] [Bug #10885] + + * vm_core.h, class.c: change accordingly. + + * test/ruby/test_refinement.rb: add a test for above. + Sun Feb 22 21:20:37 2015 Nobuyoshi Nakada <nobu@r...> * re.c (match_aref): RMatch::regexp is Qnil after matching by a Index: ruby_2_2/vm_core.h =================================================================== --- ruby_2_2/vm_core.h (revision 49707) +++ ruby_2_2/vm_core.h (revision 49708) @@ -1003,6 +1003,8 @@ void rb_gc_mark_machine_stack(rb_thread_ https://github.com/ruby/ruby/blob/trunk/ruby_2_2/vm_core.h#L1003 int rb_autoloading_value(VALUE mod, ID id, VALUE* value); +void rb_vm_rewrite_cref_stack(NODE *node, VALUE old_klass, VALUE new_klass, NODE **new_cref_ptr); + #define sysstack_error GET_VM()->special_exceptions[ruby_error_sysstack] #define RUBY_CONST_ASSERT(expr) (1/!!(expr)) /* expr must be a compile-time constant */ Index: ruby_2_2/class.c =================================================================== --- ruby_2_2/class.c (revision 49707) +++ ruby_2_2/class.c (revision 49708) @@ -229,25 +229,6 @@ rb_class_new(VALUE super) https://github.com/ruby/ruby/blob/trunk/ruby_2_2/class.c#L229 } static void -rewrite_cref_stack(NODE *node, VALUE old_klass, VALUE new_klass, NODE **new_cref_ptr) -{ - NODE *new_node; - while (node) { - if (node->nd_clss == old_klass) { - new_node = NEW_CREF(new_klass); - RB_OBJ_WRITE(new_node, &new_node->nd_next, node->nd_next); - *new_cref_ptr = new_node; - return; - } - new_node = NEW_CREF(node->nd_clss); - node = node->nd_next; - *new_cref_ptr = new_node; - new_cref_ptr = &new_node->nd_next; - } - *new_cref_ptr = NULL; -} - -static void clone_method(VALUE klass, ID mid, const rb_method_entry_t *me) { VALUE newiseqval; @@ -256,7 +237,7 @@ clone_method(VALUE klass, ID mid, const https://github.com/ruby/ruby/blob/trunk/ruby_2_2/class.c#L237 NODE *new_cref; newiseqval = rb_iseq_clone(me->def->body.iseq->self, klass); GetISeqPtr(newiseqval, iseq); - rewrite_cref_stack(me->def->body.iseq->cref_stack, me->klass, klass, &new_cref); + rb_vm_rewrite_cref_stack(me->def->body.iseq->cref_stack, me->klass, klass, &new_cref); RB_OBJ_WRITE(iseq->self, &iseq->cref_stack, new_cref); rb_add_method(klass, mid, VM_METHOD_TYPE_ISEQ, iseq, me->flag); RB_GC_GUARD(newiseqval); Index: ruby_2_2/version.h =================================================================== --- ruby_2_2/version.h (revision 49707) +++ ruby_2_2/version.h (revision 49708) @@ -1,10 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_2/version.h#L1 #define RUBY_VERSION "2.2.0" -#define RUBY_RELEASE_DATE "2015-02-23" -#define RUBY_PATCHLEVEL 77 +#define RUBY_RELEASE_DATE "2015-02-24" +#define RUBY_PATCHLEVEL 78 #define RUBY_RELEASE_YEAR 2015 #define RUBY_RELEASE_MONTH 2 -#define RUBY_RELEASE_DAY 23 +#define RUBY_RELEASE_DAY 24 #include "ruby/version.h" Index: ruby_2_2/vm_insnhelper.c =================================================================== --- ruby_2_2/vm_insnhelper.c (revision 49707) +++ ruby_2_2/vm_insnhelper.c (revision 49708) @@ -264,6 +264,27 @@ rb_vm_get_cref(const rb_iseq_t *iseq, co https://github.com/ruby/ruby/blob/trunk/ruby_2_2/vm_insnhelper.c#L264 return cref; } +void +rb_vm_rewrite_cref_stack(NODE *node, VALUE old_klass, VALUE new_klass, NODE **new_cref_ptr) +{ + NODE *new_node; + while (node) { + if (node->nd_clss == old_klass) { + new_node = NEW_CREF(new_klass); + COPY_CREF_OMOD(new_node, node); + RB_OBJ_WRITE(new_node, &new_node->nd_next, node->nd_next); + *new_cref_ptr = new_node; + return; + } + new_node = NEW_CREF(node->nd_clss); + COPY_CREF_OMOD(new_node, node); + node = node->nd_next; + *new_cref_ptr = new_node; + new_cref_ptr = &new_node->nd_next; + } + *new_cref_ptr = NULL; +} + static NODE * vm_cref_push(rb_thread_t *th, VALUE klass, int noex, rb_block_t *blockptr) { Index: ruby_2_2/test/ruby/test_refinement.rb =================================================================== --- ruby_2_2/test/ruby/test_refinement.rb (revision 49707) +++ ruby_2_2/test/ruby/test_refinement.rb (revision 49708) @@ -1387,6 +1387,34 @@ class TestRefinement < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/ruby_2_2/test/ruby/test_refinement.rb#L1387 :foo, bug10826) end + def test_call_refined_method_in_duplicate_module + bug10885 = '[ruby-dev:48878]' + assert_in_out_err([], <<-INPUT, [], [], bug10885) + module M + refine Object do + def raise + # do nothing + end + end + + class << self + using M + def m0 + raise + end + end + + using M + def M.m1 + raise + end + end + + M.dup.m0 + M.dup.m1 + INPUT + end + private def eval_using(mod, s) Property changes on: ruby_2_2 ___________________________________________________________________ Modified: svn:mergeinfo Merged /trunk:r49685,49687 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/