[前][次][番号順一覧][スレッド一覧]

ruby-changes:37914

From: nagachika <ko1@a...>
Date: Wed, 18 Mar 2015 02:34:31 +0900 (JST)
Subject: [ruby-changes:37914] nagachika:r49995 (ruby_2_1): merge revision(s) r49685, r49687: [Backport #10885]

nagachika	2015-03-18 02:34:01 +0900 (Wed, 18 Mar 2015)

  New Revision: 49995

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=49995

  Log:
    merge revision(s) r49685,r49687: [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_1/
  Modified files:
    branches/ruby_2_1/ChangeLog
    branches/ruby_2_1/class.c
    branches/ruby_2_1/test/ruby/test_refinement.rb
    branches/ruby_2_1/version.h
    branches/ruby_2_1/vm_core.h
    branches/ruby_2_1/vm_insnhelper.c
Index: ruby_2_1/ChangeLog
===================================================================
--- ruby_2_1/ChangeLog	(revision 49994)
+++ ruby_2_1/ChangeLog	(revision 49995)
@@ -1,3 +1,13 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/ChangeLog#L1
+Wed Mar 18 02:03:02 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.
+
 Wed Mar 18 01:58:18 2015  Nobuyoshi Nakada  <nobu@r...>
 
 	* ext/sdbm/_sdbm.c: include ruby/ruby.h for PRIdPTRDIFF when a
Index: ruby_2_1/vm_core.h
===================================================================
--- ruby_2_1/vm_core.h	(revision 49994)
+++ ruby_2_1/vm_core.h	(revision 49995)
@@ -896,6 +896,8 @@ void rb_gc_mark_machine_stack(rb_thread_ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/vm_core.h#L896
 
 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_1/class.c
===================================================================
--- ruby_2_1/class.c	(revision 49994)
+++ ruby_2_1/class.c	(revision 49995)
@@ -233,25 +233,6 @@ rb_class_new(VALUE super) https://github.com/ruby/ruby/blob/trunk/ruby_2_1/class.c#L233
 }
 
 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;
@@ -260,7 +241,7 @@ clone_method(VALUE klass, ID mid, const https://github.com/ruby/ruby/blob/trunk/ruby_2_1/class.c#L241
 	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_1/version.h
===================================================================
--- ruby_2_1/version.h	(revision 49994)
+++ ruby_2_1/version.h	(revision 49995)
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/version.h#L1
 #define RUBY_VERSION "2.1.5"
 #define RUBY_RELEASE_DATE "2015-03-18"
-#define RUBY_PATCHLEVEL 316
+#define RUBY_PATCHLEVEL 317
 
 #define RUBY_RELEASE_YEAR 2015
 #define RUBY_RELEASE_MONTH 3
Index: ruby_2_1/vm_insnhelper.c
===================================================================
--- ruby_2_1/vm_insnhelper.c	(revision 49994)
+++ ruby_2_1/vm_insnhelper.c	(revision 49995)
@@ -278,6 +278,27 @@ rb_vm_get_cref(const rb_iseq_t *iseq, co https://github.com/ruby/ruby/blob/trunk/ruby_2_1/vm_insnhelper.c#L278
     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_1/test/ruby/test_refinement.rb
===================================================================
--- ruby_2_1/test/ruby/test_refinement.rb	(revision 49994)
+++ ruby_2_1/test/ruby/test_refinement.rb	(revision 49995)
@@ -1358,6 +1358,34 @@ class TestRefinement < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/ruby_2_1/test/ruby/test_refinement.rb#L1358
                    :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_1
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /trunk:r49685,49687


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]