0001-Fix-cache-validity-check-of-require.patch

Hiroshi Shirosaki, 11/19/2012 10:55 PM

Download (2.57 KB)

View differences:

array.c
351 351
   e.g. rb_ary_replace) and check later whether the array has been
352 352
   modified from the snapshot.  The snapshot is cheap, though if
353 353
   something does modify the array it will pay the cost of copying
354
   it. */
354
   it.  If Array#pop or Array#shift has been called, the array will
355
   be still shared with the snapshot, but the array length will
356
   differ. */
355 357
VALUE
356 358
rb_ary_shared_with_p(VALUE ary1, VALUE ary2)
357 359
{
358
    if (!ARY_EMBED_P(ary1) && ARY_SHARED_P(ary1)
359
     && !ARY_EMBED_P(ary2) && ARY_SHARED_P(ary2)
360
     && RARRAY(ary1)->as.heap.aux.shared == RARRAY(ary2)->as.heap.aux.shared) {
360
    if (!ARY_EMBED_P(ary1) && ARY_SHARED_P(ary1) &&
361
	!ARY_EMBED_P(ary2) && ARY_SHARED_P(ary2) &&
362
	RARRAY(ary1)->as.heap.aux.shared == RARRAY(ary2)->as.heap.aux.shared &&
363
	RARRAY(ary1)->as.heap.len == RARRAY(ary2)->as.heap.len) {
361 364
	return Qtrue;
362 365
    }
363 366
    return Qfalse;
test/ruby/test_require.rb
545 545
      }
546 546
    }
547 547
  end
548

  
549
  def assert_require_with_shared_array(add, del)
550
    bug7383 = '[ruby-core:49518]'
551
    Dir.mktmpdir {|tmp|
552
      Dir.chdir(tmp) {
553
        open("foo.rb", "w") {}
554
        Dir.mkdir("a")
555
        open(File.join("a", "bar.rb"), "w") {}
556
        assert_in_out_err([], <<-INPUT, %w(:ok), [], bug7383)
557
          $:.#{add} "#{tmp}"
558
          $:.#{add} "#{tmp}/a"
559
          require "foo"
560
          $:.#{del}
561
          # Expanded load path cache should be rebuilt.
562
          begin
563
            require "bar"
564
          rescue LoadError
565
            p :ok
566
          end
567
        INPUT
568
      }
569
    }
570
  end
571

  
572
  def test_require_with_array_pop
573
    assert_require_with_shared_array("push", "pop")
574
  end
575

  
576
  def test_require_with_array_shift
577
    assert_require_with_shared_array("unshift", "shift")
578
  end
548 579
end
549
-