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

ruby-changes:27184

From: nobu <ko1@a...>
Date: Thu, 14 Feb 2013 11:08:51 +0900 (JST)
Subject: [ruby-changes:27184] nobu:r39236 (trunk): class.c: cyclic prepend

nobu	2013-02-14 11:08:31 +0900 (Thu, 14 Feb 2013)

  New Revision: 39236

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

  Log:
    class.c: cyclic prepend
    
    * class.c (include_modules_at): detect cyclic prepend with original
      method table.  [ruby-core:52205] [Bug #7841]

  Modified files:
    trunk/ChangeLog
    trunk/class.c
    trunk/test/ruby/test_module.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 39235)
+++ ChangeLog	(revision 39236)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Thu Feb 14 11:08:15 2013  Nobuyoshi Nakada  <nobu@r...>
+
+	* class.c (include_modules_at): detect cyclic prepend with original
+	  method table.  [ruby-core:52205] [Bug #7841]
+
 Thu Feb 14 10:30:41 2013  Nobuyoshi Nakada  <nobu@r...>
 
 	* vm_method.c: call method_removed hook on called class, not on
Index: class.c
===================================================================
--- class.c	(revision 39235)
+++ class.c	(revision 39236)
@@ -681,7 +681,7 @@ rb_include_class_new(VALUE module, VALUE https://github.com/ruby/ruby/blob/trunk/class.c#L681
     return (VALUE)klass;
 }
 
-static int include_modules_at(VALUE klass, VALUE c, VALUE module);
+static int include_modules_at(const VALUE klass, VALUE c, VALUE module);
 
 void
 rb_include_module(VALUE klass, VALUE module)
@@ -713,17 +713,18 @@ add_refined_method_entry_i(st_data_t key https://github.com/ruby/ruby/blob/trunk/class.c#L713
 }
 
 static int
-include_modules_at(VALUE klass, VALUE c, VALUE module)
+include_modules_at(const VALUE klass, VALUE c, VALUE module)
 {
     VALUE p;
     int changed = 0;
+    const st_table *const klass_m_tbl = RCLASS_M_TBL(RCLASS_ORIGIN(klass));
 
     while (module) {
 	int superclass_seen = FALSE;
 
 	if (RCLASS_ORIGIN(module) != module)
 	    goto skip;
-	if (RCLASS_M_TBL(klass) && RCLASS_M_TBL(klass) == RCLASS_M_TBL(module))
+	if (klass_m_tbl && klass_m_tbl == RCLASS_M_TBL(module))
 	    return -1;
 	/* ignore if the module included already in superclasses */
 	for (p = RCLASS_SUPER(klass); p; p = RCLASS_SUPER(p)) {
Index: test/ruby/test_module.rb
===================================================================
--- test/ruby/test_module.rb	(revision 39235)
+++ test/ruby/test_module.rb	(revision 39236)
@@ -1465,6 +1465,16 @@ class TestModule < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_module.rb#L1465
     assert_equal([:m1], Class.new(Class.new{def m2;end}){ prepend Module.new; def m1; end }.instance_methods(false), bug6660)
   end
 
+  def test_cyclic_prepend
+    bug7841 = '[ruby-core:52205] [Bug #7841]'
+    m1 = Module.new
+    m2 = Module.new
+    m1.instance_eval { prepend(m2) }
+    assert_raise(ArgumentError, bug7841) do
+      m2.instance_eval { prepend(m1) }
+    end
+  end
+
   def test_class_variables
     m = Module.new
     m.class_variable_set(:@@foo, 1)

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

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