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

ruby-changes:40569

From: ko1 <ko1@a...>
Date: Wed, 18 Nov 2015 23:00:16 +0900 (JST)
Subject: [ruby-changes:40569] ko1:r52648 (trunk): * vm_method.c (rb_class_clear_method_cache): should clear all

ko1	2015-11-18 22:59:57 +0900 (Wed, 18 Nov 2015)

  New Revision: 52648

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

  Log:
    * vm_method.c (rb_class_clear_method_cache): should clear all
      RCLASS_CALLABLE_M_TBLs of all sub-classes (T_ICLASS).
    
      RCLASS_CALLABLE_M_TBL() caches complemented method entries.
      It should be cleared when the modules are cleared.
      On previous version clears only for direct children.
      It is enough for normal modules because corresponding T_ICLASSes
      are direct children.
    
      However, refinements create complex data structure. So that
      we need to clear all children (and descendants).
      [ruby-core:71423] [Bug #11672]
    
    * vm_method.c (rb_clear_method_cache_by_class): rb_mKernel
      doesn't call rb_class_clear_method_cache, so that
      clear child T_ICLASSes.
    
    * test/ruby/test_refinement.rb: enable disabled test.

  Modified files:
    trunk/ChangeLog
    trunk/test/ruby/test_refinement.rb
    trunk/vm_method.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 52647)
+++ ChangeLog	(revision 52648)
@@ -1,3 +1,24 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Nov 18 22:50:43 2015  Koichi Sasada  <ko1@a...>
+
+	* vm_method.c (rb_class_clear_method_cache): should clear all
+	  RCLASS_CALLABLE_M_TBLs of all sub-classes (T_ICLASS).
+
+	  RCLASS_CALLABLE_M_TBL() caches complemented method entries.
+	  It should be cleared when the modules are cleared.
+	  On previous version clears only for direct children.
+	  It is enough for normal modules because corresponding T_ICLASSes
+	  are direct children.
+
+	  However, refinements create complex data structure. So that
+	  we need to clear all children (and descendants).
+	  [ruby-core:71423] [Bug #11672]
+
+	* vm_method.c (rb_clear_method_cache_by_class): rb_mKernel
+	  doesn't call rb_class_clear_method_cache, so that
+	  clear child T_ICLASSes.
+
+	* test/ruby/test_refinement.rb: enable disabled test.
+
 Wed Nov 18 21:09:08 2015  Koichi Sasada  <ko1@a...>
 
 	* vm_method.c (prepare_callable_method_entry): use
Index: vm_method.c
===================================================================
--- vm_method.c	(revision 52647)
+++ vm_method.c	(revision 52648)
@@ -62,6 +62,20 @@ static void https://github.com/ruby/ruby/blob/trunk/vm_method.c#L62
 rb_class_clear_method_cache(VALUE klass, VALUE arg)
 {
     RCLASS_SERIAL(klass) = rb_next_class_serial();
+
+    if (RB_TYPE_P(klass, T_ICLASS)) {
+	struct rb_id_table *table = RCLASS_CALLABLE_M_TBL(klass);
+	if (table) {
+	    rb_id_table_clear(table);
+	}
+    }
+    else {
+	if (RCLASS_CALLABLE_M_TBL(klass) != 0) {
+	    rb_obj_info_dump(klass);
+	    rb_bug("RCLASS_CALLABLE_M_TBL(klass) != 0");
+	}
+    }
+
     rb_class_foreach_subclass(klass, rb_class_clear_method_cache, arg);
 }
 
@@ -93,14 +107,14 @@ rb_clear_method_cache_by_class(VALUE kla https://github.com/ruby/ruby/blob/trunk/vm_method.c#L107
 	else {
 	    rb_class_clear_method_cache(klass, Qnil);
 	}
+    }
 
-	if (RB_TYPE_P(klass, T_MODULE)) {
-	    rb_subclass_entry_t *entry = RCLASS_EXT(klass)->subclasses;
+    if (klass == rb_mKernel) {
+	rb_subclass_entry_t *entry = RCLASS_EXT(klass)->subclasses;
 
-	    for (; entry != NULL; entry = entry->next) {
-		struct rb_id_table *table = RCLASS_CALLABLE_M_TBL(entry->klass);
-		if (table)rb_id_table_clear(table);
-	    }
+	for (; entry != NULL; entry = entry->next) {
+	    struct rb_id_table *table = RCLASS_CALLABLE_M_TBL(entry->klass);
+	    if (table)rb_id_table_clear(table);
 	}
     }
 }
Index: test/ruby/test_refinement.rb
===================================================================
--- test/ruby/test_refinement.rb	(revision 52647)
+++ test/ruby/test_refinement.rb	(revision 52648)
@@ -1495,7 +1495,6 @@ class TestRefinement < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/test/ruby/test_refinement.rb#L1495
   end
 
   def test_reopen_refinement_module
-    flag = false
     assert_separately([], <<-"end;")
       $VERBOSE = nil
       class C
@@ -1522,11 +1521,6 @@ class TestRefinement < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/test/ruby/test_refinement.rb#L1521
 
       assert_equal(:bar, C.new.m, "[ruby-core:71423] [Bug #11672]")
     end;
-    flag = true
-  rescue MiniTest::Assertion
-    skip 'expected to fail'
-  ensure
-    raise MiniTest::Assertion, 'this test is expected to fail' if flag
   end
 
   private

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

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