ruby-changes:38101
From: nobu <ko1@a...>
Date: Wed, 8 Apr 2015 13:01:26 +0900 (JST)
Subject: [ruby-changes:38101] nobu:r50182 (trunk): hash.c: compare symbols by identities
nobu 2015-04-08 13:01:06 +0900 (Wed, 08 Apr 2015) New Revision: 50182 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=50182 Log: hash.c: compare symbols by identities * hash.c (rb_any_hash): Symbols are compared by the identities always. [ruby-core:68767] [Bug #11035] Modified files: trunk/ChangeLog trunk/hash.c trunk/test/ruby/test_symbol.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 50181) +++ ChangeLog (revision 50182) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Wed Apr 8 13:01:06 2015 Nobuyoshi Nakada <nobu@r...> + + * hash.c (rb_any_hash): Symbols are compared by the identities + always. [ruby-core:68767] [Bug #11035] + Tue Apr 7 10:22:51 2015 SHIBATA Hiroshi <shibata.hiroshi@g...> * internal.h: fix typo. Patch by @sferik [fix GH-865] Index: hash.c =================================================================== --- hash.c (revision 50181) +++ hash.c (revision 50182) @@ -149,6 +149,9 @@ rb_any_hash(VALUE a) https://github.com/ruby/ruby/blob/trunk/hash.c#L149 else if (BUILTIN_TYPE(a) == T_STRING) { hnum = rb_str_hash(a); } + else if (BUILTIN_TYPE(a) == T_SYMBOL) { + hnum = rb_objid_hash((st_index_t)a); + } else if (BUILTIN_TYPE(a) == T_FLOAT) { return rb_dbl_hash(rb_float_value(a)); } Index: test/ruby/test_symbol.rb =================================================================== --- test/ruby/test_symbol.rb (revision 50181) +++ test/ruby/test_symbol.rb (revision 50182) @@ -238,4 +238,23 @@ class TestSymbol < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_symbol.rb#L238 200_000.times { |i| i.to_s.to_sym } end; end + + def test_hash_redefinition + assert_separately([], <<-'end;') + bug11035 = '[ruby-core:68767] [Bug #11035]' + class Symbol + def hash + raise + end + end + + h = {} + assert_nothing_raised(RuntimeError, bug11035) { + h[:foo] = 1 + } + assert_nothing_raised(RuntimeError, bug11035) { + h['bar'.to_sym] = 2 + } + end + end; end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/