diff options
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | hash.c | 6 | ||||
-rw-r--r-- | test/ruby/test_hash.rb | 10 | ||||
-rw-r--r-- | version.h | 2 |
4 files changed, 18 insertions, 5 deletions
@@ -1,3 +1,8 @@ +Mon Aug 17 17:52:11 2015 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * hash.c (rb_any_hash): fix Float hash. rb_dbl_hash() returns a + Fixnum, but not a long. [Bug #9381] + Mon Aug 17 17:43:56 2015 Eric Wong <e@80x24.org> * io.c (rb_io_oflags_modestr): handle O_TRUNC correctly @@ -135,7 +135,7 @@ rb_any_hash(VALUE a) if (a == Qundef) return 0; if (FLONUM_P(a)) { /* prevent pathological behavior: [Bug #10761] */ - return rb_dbl_hash(rb_float_value(a)); + goto flt; } hnum = rb_objid_hash((st_index_t)a); } @@ -143,7 +143,9 @@ rb_any_hash(VALUE a) hnum = rb_str_hash(a); } else if (BUILTIN_TYPE(a) == T_FLOAT) { - return rb_dbl_hash(rb_float_value(a)); + flt: + hval = rb_dbl_hash(rb_float_value(a)); + hnum = FIX2LONG(hval); } else { hval = rb_hash(a); diff --git a/test/ruby/test_hash.rb b/test/ruby/test_hash.rb index 59000ad5d6..69783981d5 100644 --- a/test/ruby/test_hash.rb +++ b/test/ruby/test_hash.rb @@ -1262,8 +1262,14 @@ class TestHash < Test::Unit::TestCase end end - hash = {5 => bug9381} - assert_equal(bug9381, hash[wrapper.new(5)]) + bad = [ + 5, true, false, nil, + 0.0, 1.72723e-77, + ].select do |x| + hash = {x => bug9381} + hash[wrapper.new(x)] != bug9381 + end + assert_empty(bad, bug9381) end class TestSubHash < TestHash @@ -1,6 +1,6 @@ #define RUBY_VERSION "2.1.7" #define RUBY_RELEASE_DATE "2015-08-17" -#define RUBY_PATCHLEVEL 395 +#define RUBY_PATCHLEVEL 396 #define RUBY_RELEASE_YEAR 2015 #define RUBY_RELEASE_MONTH 8 |