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

ruby-changes:29123

From: charliesome <ko1@a...>
Date: Sat, 8 Jun 2013 19:48:45 +0900 (JST)
Subject: [ruby-changes:29123] charliesome:r41175 (trunk): * class.c (include_modules_at): invalidate method cache if included

charliesome	2013-06-08 19:48:33 +0900 (Sat, 08 Jun 2013)

  New Revision: 41175

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

  Log:
    * class.c (include_modules_at): invalidate method cache if included
      module contains constants
    
    * test/ruby/test_module.rb: add test

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

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 41174)
+++ ChangeLog	(revision 41175)
@@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Jun  8 19:47:00 2013  Charlie Somerville  <charliesome@r...>
+
+	* class.c (include_modules_at): invalidate method cache if included
+	  module contains constants
+
+	* test/ruby/test_module.rb: add test
+
 Sat Jun  8 19:31:00 2013  Charlie Somerville  <charliesome@r...>
 
 	* random.c (limited_big_rand): declare rnd, lim and mask as uint32_t
Index: class.c
===================================================================
--- class.c	(revision 41174)
+++ class.c	(revision 41175)
@@ -760,6 +760,8 @@ include_modules_at(const VALUE klass, VA https://github.com/ruby/ruby/blob/trunk/class.c#L760
 	}
 	if (RMODULE_M_TBL(module) && RMODULE_M_TBL(module)->num_entries)
 	    changed = 1;
+	if (RMODULE_CONST_TBL(module) && RMODULE_CONST_TBL(module)->num_entries)
+	    changed = 1;
       skip:
 	module = RCLASS_SUPER(module);
     }
Index: test/ruby/test_module.rb
===================================================================
--- test/ruby/test_module.rb	(revision 41174)
+++ test/ruby/test_module.rb	(revision 41175)
@@ -1759,6 +1759,26 @@ class TestModule < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_module.rb#L1759
     assert_raise(NoMethodError, bug8284) {Object.define_method}
   end
 
+  def test_include_module_with_constants_invalidates_method_cache
+    assert_in_out_err([], <<-RUBY, %w(123 456), [])
+      A = 123
+
+      class Foo
+        def self.a
+          A
+        end
+      end
+
+      module M
+        A = 456
+      end
+
+      puts Foo.a
+      Foo.send(:include, M)
+      puts Foo.a
+    RUBY
+  end
+
   private
 
   def assert_top_method_is_private(method)

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

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