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

ruby-changes:25751

From: shirosaki <ko1@a...>
Date: Thu, 22 Nov 2012 23:55:50 +0900 (JST)
Subject: [ruby-changes:25751] shirosaki:r37808 (trunk): Fix cache validity check of require

shirosaki	2012-11-22 23:55:32 +0900 (Thu, 22 Nov 2012)

  New Revision: 37808

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

  Log:
    Fix cache validity check of require
    
    * array.c (rb_ary_shared_with_p): fix cache validity check.
      If #pop or #shift has been called against $: or $", the array will
      be still shared with the snapshot. We check array length for cache
      validity.
      [ruby-core:49518] [Bug #7383]
    
    * test/ruby/test_require.rb
      (TestRequire#test_require_with_array_pop,
       TestRequire#test_require_with_array_shift): add tests for above.

  Modified files:
    trunk/ChangeLog
    trunk/array.c
    trunk/test/ruby/test_require.rb

Index: array.c
===================================================================
--- array.c	(revision 37807)
+++ array.c	(revision 37808)
@@ -351,13 +351,16 @@
    e.g. rb_ary_replace) and check later whether the array has been
    modified from the snapshot.  The snapshot is cheap, though if
    something does modify the array it will pay the cost of copying
-   it. */
+   it.  If Array#pop or Array#shift has been called, the array will
+   be still shared with the snapshot, but the array length will
+   differ. */
 VALUE
 rb_ary_shared_with_p(VALUE ary1, VALUE ary2)
 {
-    if (!ARY_EMBED_P(ary1) && ARY_SHARED_P(ary1)
-     && !ARY_EMBED_P(ary2) && ARY_SHARED_P(ary2)
-     && RARRAY(ary1)->as.heap.aux.shared == RARRAY(ary2)->as.heap.aux.shared) {
+    if (!ARY_EMBED_P(ary1) && ARY_SHARED_P(ary1) &&
+	!ARY_EMBED_P(ary2) && ARY_SHARED_P(ary2) &&
+	RARRAY(ary1)->as.heap.aux.shared == RARRAY(ary2)->as.heap.aux.shared &&
+	RARRAY(ary1)->as.heap.len == RARRAY(ary2)->as.heap.len) {
 	return Qtrue;
     }
     return Qfalse;
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 37807)
+++ ChangeLog	(revision 37808)
@@ -1,3 +1,15 @@
+Thu Nov 22 23:45:18 2012  Hiroshi Shirosaki  <h.shirosaki@g...>
+
+	* array.c (rb_ary_shared_with_p): fix cache validity check.
+	  If #pop or #shift has been called against $: or $", the array will
+	  be still shared with the snapshot. We check array length for cache
+	  validity.
+	  [ruby-core:49518] [Bug #7383]
+
+	* test/ruby/test_require.rb
+	  (TestRequire#test_require_with_array_pop,
+	   TestRequire#test_require_with_array_shift): add tests for above.
+
 Thu Nov 22 21:48:48 2012  NAKAMURA Usaku  <usa@r...>
 
 	* common.mk, win32/Makefile.sub (probes.dmyh): now be made in current
Index: test/ruby/test_require.rb
===================================================================
--- test/ruby/test_require.rb	(revision 37807)
+++ test/ruby/test_require.rb	(revision 37808)
@@ -545,4 +545,35 @@
       }
     }
   end
+
+  def assert_require_with_shared_array_modified(add, del)
+    bug7383 = '[ruby-core:49518]'
+    Dir.mktmpdir {|tmp|
+      Dir.chdir(tmp) {
+        open("foo.rb", "w") {}
+        Dir.mkdir("a")
+        open(File.join("a", "bar.rb"), "w") {}
+        assert_in_out_err([], <<-INPUT, %w(:ok), [], bug7383)
+          $:.#{add} "#{tmp}"
+          $:.#{add} "#{tmp}/a"
+          require "foo"
+          $:.#{del}
+          # Expanded load path cache should be rebuilt.
+          begin
+            require "bar"
+          rescue LoadError
+            p :ok
+          end
+        INPUT
+      }
+    }
+  end
+
+  def test_require_with_array_pop
+    assert_require_with_shared_array_modified("push", "pop")
+  end
+
+  def test_require_with_array_shift
+    assert_require_with_shared_array_modified("unshift", "shift")
+  end
 end

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

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