From 218d1f5e1e2377b237c294e871bd3bfd6abf6633 Mon Sep 17 00:00:00 2001 From: nobu Date: Tue, 3 Dec 2013 13:32:24 +0000 Subject: hash.c: same hash value for similar constructs * hash.c (rb_hash_recursive): make similar (recursive) constructs return same hash value. execute recursively, and rewind to the topmost frame with an object which .eql? to the recursive object, if recursion is detected. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43981 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_array.rb | 1 + test/ruby/test_thread.rb | 13 +++++++++++++ 2 files changed, 14 insertions(+) (limited to 'test/ruby') diff --git a/test/ruby/test_array.rb b/test/ruby/test_array.rb index d53b345898..0235f00471 100644 --- a/test/ruby/test_array.rb +++ b/test/ruby/test_array.rb @@ -2053,6 +2053,7 @@ class TestArray < Test::Unit::TestCase assert_not_equal([[1]].hash, [[2]].hash) a = [] a << a + assert_equal([[a]].hash, a.hash) assert_not_equal([a, 1].hash, [a, 2].hash) assert_not_equal([a, a].hash, a.hash) # Implementation dependent end diff --git a/test/ruby/test_thread.rb b/test/ruby/test_thread.rb index f74c4ec9cb..ab1b81a8fe 100644 --- a/test/ruby/test_thread.rb +++ b/test/ruby/test_thread.rb @@ -467,6 +467,19 @@ class TestThread < Test::Unit::TestCase m.unlock end + def test_recursive_outer + arr = [] + obj = Struct.new(:foo, :visited).new(arr, false) + arr << obj + def obj.hash + self[:visited] = true + super + raise "recursive_outer should short circuit intermediate calls" + end + assert_nothing_raised {arr.hash} + assert(obj[:visited], "obj.hash was not called") + end + def test_thread_instance_variable bug4389 = '[ruby-core:35192]' assert_in_out_err([], <<-INPUT, %w(), [], bug4389) -- cgit v1.2.3