ruby-changes:38538
From: nagachika <ko1@a...>
Date: Sun, 24 May 2015 02:01:39 +0900 (JST)
Subject: [ruby-changes:38538] nagachika:r50619 (ruby_2_2): merge revision(s) 49999, 50000: [Backport #10979]
nagachika 2015-05-24 02:01:17 +0900 (Sun, 24 May 2015) New Revision: 50619 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=50619 Log: merge revision(s) 49999,50000: [Backport #10979] * hash.c (rb_any_hash): use same hash values with Float#hash so that -0.0 and +0.0 will be identical. [ruby-core:68541] [Bug #10979] Modified directories: branches/ruby_2_2/ Modified files: branches/ruby_2_2/ChangeLog branches/ruby_2_2/hash.c branches/ruby_2_2/internal.h branches/ruby_2_2/numeric.c branches/ruby_2_2/test/ruby/test_float.rb branches/ruby_2_2/version.h Index: ruby_2_2/ChangeLog =================================================================== --- ruby_2_2/ChangeLog (revision 50618) +++ ruby_2_2/ChangeLog (revision 50619) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_2/ChangeLog#L1 +Sun May 24 02:01:07 2015 Nobuyoshi Nakada <nobu@r...> + + * hash.c (rb_any_hash): use same hash values with Float#hash so + that -0.0 and +0.0 will be identical. + [ruby-core:68541] [Bug #10979] + Thu May 21 01:34:48 2015 Nobuyoshi Nakada <nobu@r...> * gc.c (id2ref): prohibit from accessing internal objects. Index: ruby_2_2/hash.c =================================================================== --- ruby_2_2/hash.c (revision 50618) +++ ruby_2_2/hash.c (revision 50619) @@ -142,13 +142,16 @@ rb_any_hash(VALUE a) https://github.com/ruby/ruby/blob/trunk/ruby_2_2/hash.c#L142 } else if (FLONUM_P(a)) { /* prevent pathological behavior: [Bug #10761] */ - a = (st_index_t)rb_float_value(a); + return rb_dbl_hash(rb_float_value(a)); } hnum = rb_objid_hash((st_index_t)a); } else if (BUILTIN_TYPE(a) == T_STRING) { hnum = rb_str_hash(a); } + else if (BUILTIN_TYPE(a) == T_FLOAT) { + return rb_dbl_hash(rb_float_value(a)); + } else { hval = rb_hash(a); hnum = FIX2LONG(hval); Index: ruby_2_2/numeric.c =================================================================== --- ruby_2_2/numeric.c (revision 50618) +++ ruby_2_2/numeric.c (revision 50619) @@ -1137,10 +1137,14 @@ flo_eq(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/ruby_2_2/numeric.c#L1137 static VALUE flo_hash(VALUE num) { - double d; + return rb_dbl_hash(RFLOAT_VALUE(num)); +} + +VALUE +rb_dbl_hash(double d) +{ st_index_t hash; - d = RFLOAT_VALUE(num); /* normalize -0.0 to 0.0 */ if (d == 0.0) d = 0.0; hash = rb_memhash(&d, sizeof(d)); Index: ruby_2_2/internal.h =================================================================== --- ruby_2_2/internal.h (revision 50618) +++ ruby_2_2/internal.h (revision 50619) @@ -773,6 +773,7 @@ double ruby_float_mod(double x, double y https://github.com/ruby/ruby/blob/trunk/ruby_2_2/internal.h#L773 int rb_num_negative_p(VALUE); VALUE rb_int_succ(VALUE num); VALUE rb_int_pred(VALUE num); +VALUE rb_dbl_hash(double d); #if USE_FLONUM #define RUBY_BIT_ROTL(v, n) (((v) << (n)) | ((v) >> ((sizeof(v) * 8) - n))) Index: ruby_2_2/version.h =================================================================== --- ruby_2_2/version.h (revision 50618) +++ ruby_2_2/version.h (revision 50619) @@ -1,10 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_2/version.h#L1 #define RUBY_VERSION "2.2.3" -#define RUBY_RELEASE_DATE "2015-05-21" -#define RUBY_PATCHLEVEL 115 +#define RUBY_RELEASE_DATE "2015-05-24" +#define RUBY_PATCHLEVEL 116 #define RUBY_RELEASE_YEAR 2015 #define RUBY_RELEASE_MONTH 5 -#define RUBY_RELEASE_DAY 21 +#define RUBY_RELEASE_DAY 24 #include "ruby/version.h" Index: ruby_2_2/test/ruby/test_float.rb =================================================================== --- ruby_2_2/test/ruby/test_float.rb (revision 50618) +++ ruby_2_2/test/ruby/test_float.rb (revision 50619) @@ -672,4 +672,12 @@ class TestFloat < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_2/test/ruby/test_float.rb#L672 assert_equal(0.0, z) assert_equal(-Float::INFINITY, 1.0/z) end + + def test_hash_0 + bug10979 = '[ruby-core:68541] [Bug #10979]' + assert_equal(+0.0.hash, -0.0.hash) + assert_operator(+0.0, :eql?, -0.0) + h = {0.0 => bug10979} + assert_equal(bug10979, h[-0.0]) + end end Property changes on: ruby_2_2 ___________________________________________________________________ Modified: svn:mergeinfo Merged /trunk:r49999-50000 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/