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

ruby-changes:50115

From: nagachika <ko1@a...>
Date: Mon, 5 Feb 2018 23:05:59 +0900 (JST)
Subject: [ruby-changes:50115] nagachika:r62233 (ruby_2_4): merge revision(s) 60980, 60984: [Backport #14070]

nagachika	2018-02-05 23:05:52 +0900 (Mon, 05 Feb 2018)

  New Revision: 62233

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

  Log:
    merge revision(s) 60980,60984: [Backport #14070]
    
    Modules should not have subclasses.
    
    When refining a module, the module was set to the superclass of its refinement,
    and a segmentation fault occurred.
    The superclass of the refinement should be an iclass of the module.
    [ruby-core:83617] [Bug #14070]
    
    The superclass of a refinement should have BasicObject as its ancestor.
    
    Otherwise, VM_ASSERT(callable_method_entry_p(cme)) in
    prepare_callable_method_entry() fails if VM_CHECK_MODE is 2.

  Modified directories:
    branches/ruby_2_4/
  Modified files:
    branches/ruby_2_4/eval.c
    branches/ruby_2_4/test/ruby/test_refinement.rb
    branches/ruby_2_4/version.h
Index: ruby_2_4/version.h
===================================================================
--- ruby_2_4/version.h	(revision 62232)
+++ ruby_2_4/version.h	(revision 62233)
@@ -1,10 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_4/version.h#L1
 #define RUBY_VERSION "2.4.4"
-#define RUBY_RELEASE_DATE "2018-02-04"
-#define RUBY_PATCHLEVEL 233
+#define RUBY_RELEASE_DATE "2018-02-05"
+#define RUBY_PATCHLEVEL 234
 
 #define RUBY_RELEASE_YEAR 2018
 #define RUBY_RELEASE_MONTH 2
-#define RUBY_RELEASE_DAY 4
+#define RUBY_RELEASE_DAY 5
 
 #include "ruby/version.h"
 
Index: ruby_2_4/eval.c
===================================================================
--- ruby_2_4/eval.c	(revision 62232)
+++ ruby_2_4/eval.c	(revision 62233)
@@ -1144,6 +1144,18 @@ hidden_identity_hash_new(void) https://github.com/ruby/ruby/blob/trunk/ruby_2_4/eval.c#L1144
     return hash;
 }
 
+static VALUE
+refinement_superclass(VALUE superclass)
+{
+    if (RB_TYPE_P(superclass, T_MODULE)) {
+	/* FIXME: Should ancestors of superclass be used here? */
+	return rb_include_class_new(superclass, rb_cBasicObject);
+    }
+    else {
+	return superclass;
+    }
+}
+
 void
 rb_using_refinement(rb_cref_t *cref, VALUE klass, VALUE module)
 {
@@ -1171,6 +1183,7 @@ rb_using_refinement(rb_cref_t *cref, VAL https://github.com/ruby/ruby/blob/trunk/ruby_2_4/eval.c#L1183
 	}
     }
     FL_SET(module, RMODULE_IS_OVERLAID);
+    superclass = refinement_superclass(superclass);
     c = iclass = rb_include_class_new(module, superclass);
     RCLASS_REFINED_CLASS(c) = klass;
 
@@ -1260,6 +1273,7 @@ add_activated_refinement(VALUE activated https://github.com/ruby/ruby/blob/trunk/ruby_2_4/eval.c#L1273
 	}
     }
     FL_SET(refinement, RMODULE_IS_OVERLAID);
+    superclass = refinement_superclass(superclass);
     c = iclass = rb_include_class_new(refinement, superclass);
     RCLASS_REFINED_CLASS(c) = klass;
     refinement = RCLASS_SUPER(refinement);
@@ -1314,8 +1328,9 @@ rb_mod_refine(VALUE module, VALUE klass) https://github.com/ruby/ruby/blob/trunk/ruby_2_4/eval.c#L1328
     }
     refinement = rb_hash_lookup(refinements, klass);
     if (NIL_P(refinement)) {
+	VALUE superclass = refinement_superclass(klass);
 	refinement = rb_module_new();
-	RCLASS_SET_SUPER(refinement, klass);
+	RCLASS_SET_SUPER(refinement, superclass);
 	FL_SET(refinement, RMODULE_IS_REFINEMENT);
 	CONST_ID(id_refined_class, "__refined_class__");
 	rb_ivar_set(refinement, id_refined_class, klass);
Index: ruby_2_4/test/ruby/test_refinement.rb
===================================================================
--- ruby_2_4/test/ruby/test_refinement.rb	(revision 62232)
+++ ruby_2_4/test/ruby/test_refinement.rb	(revision 62233)
@@ -1961,6 +1961,25 @@ class TestRefinement < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/ruby_2_4/test/ruby/test_refinement.rb#L1961
     end
   end
 
+  def test_refining_module_repeatedly
+    bug14070 = '[ruby-core:83617] [Bug #14070]'
+    assert_in_out_err([], <<-INPUT, ["ok"], [], bug14070)
+      1000.times do
+        Class.new do
+          include Enumerable
+        end
+
+        Module.new do
+          refine Enumerable do
+            def foo
+            end
+          end
+        end
+      end
+      puts "ok"
+    INPUT
+  end
+
   private
 
   def eval_using(mod, s)
Index: ruby_2_4
===================================================================
--- ruby_2_4	(revision 62232)
+++ ruby_2_4	(revision 62233)

Property changes on: ruby_2_4
___________________________________________________________________
Modified: svn:mergeinfo
## -0,0 +0,1 ##
   Merged /trunk:r60980,60984

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

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