ruby-changes:25196
From: tenderlove <ko1@a...>
Date: Thu, 18 Oct 2012 09:24:25 +0900 (JST)
Subject: [ruby-changes:25196] tenderlove:r37248 (trunk): * hash.c (initialize_copy): duping should rehash the hash.
tenderlove 2012-10-18 09:24:00 +0900 (Thu, 18 Oct 2012) New Revision: 37248 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=37248 Log: * hash.c (initialize_copy): duping should rehash the hash. * test/ruby/test_hash.rb: added a test to ensure rehash. Modified files: trunk/ChangeLog trunk/hash.c trunk/test/ruby/test_hash.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 37247) +++ ChangeLog (revision 37248) @@ -1,3 +1,9 @@ +Thu Oct 18 09:23:03 2012 Aaron Patterson <aaron@t...> + + * hash.c (initialize_copy): duping should rehash the hash. + + * test/ruby/test_hash.rb: added a test to ensure rehash. + Wed Oct 17 21:16:47 2012 Hiroshi Shirosaki <h.shirosaki@g...> * common.mk (WPROGRAM): need same dependencies as PROGRAM. Index: hash.c =================================================================== --- hash.c (revision 37247) +++ hash.c (revision 37248) @@ -1187,8 +1187,11 @@ { Check_Type(hash2, T_HASH); - if (!RHASH_EMPTY_P(hash2)) + if (!RHASH_EMPTY_P(hash2)) { RHASH(hash)->ntbl = st_copy(RHASH(hash2)->ntbl); + rb_hash_rehash(hash); + } + if (FL_TEST(hash2, HASH_PROC_DEFAULT)) { FL_SET(hash, HASH_PROC_DEFAULT); } Index: test/ruby/test_hash.rb =================================================================== --- test/ruby/test_hash.rb (revision 37247) +++ test/ruby/test_hash.rb (revision 37248) @@ -100,6 +100,15 @@ assert_raises(TypeError) { h.dup } end + def test_dup_will_rehash + set1 = { } + set2 = { set1 => true} + + set1[set1] = true + + assert_equal set2, set2.dup + end + def test_s_AREF h = @cls["a" => 100, "b" => 200] assert_equal(100, h['a']) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/