[前][次][番号順一覧][スレッド一覧]

ruby-changes:39344

From: nobu <ko1@a...>
Date: Wed, 29 Jul 2015 14:53:53 +0900 (JST)
Subject: [ruby-changes:39344] nobu:r51425 (trunk): hash.c: fix float hash

nobu	2015-07-29 14:53:35 +0900 (Wed, 29 Jul 2015)

  New Revision: 51425

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=51425

  Log:
    hash.c: fix float hash
    
    * hash.c (rb_any_hash): fix Float hash.  rb_dbl_hash() returns a
      Fixnum, but not a long.  [Bug #9381]

  Modified files:
    trunk/ChangeLog
    trunk/hash.c
    trunk/test/ruby/test_hash.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 51424)
+++ ChangeLog	(revision 51425)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Jul 29 14:53:32 2015  Nobuyoshi Nakada  <nobu@r...>
+
+	* hash.c (rb_any_hash): fix Float hash.  rb_dbl_hash() returns a
+	  Fixnum, but not a long.  [Bug #9381]
+
 Wed Jul 29 11:07:10 2015  Nobuyoshi Nakada  <nobu@r...>
 
 	* internal.h (LIKELY, UNLIKELY): make a boolean to enforce 1 or 0.
Index: hash.c
===================================================================
--- hash.c	(revision 51424)
+++ hash.c	(revision 51425)
@@ -142,7 +142,7 @@ rb_any_hash(VALUE a) https://github.com/ruby/ruby/blob/trunk/hash.c#L142
 	}
 	else 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);
     }
@@ -153,7 +153,9 @@ rb_any_hash(VALUE a) https://github.com/ruby/ruby/blob/trunk/hash.c#L153
 	return RSYMBOL(a)->hashval;
     }
     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);
Index: test/ruby/test_hash.rb
===================================================================
--- test/ruby/test_hash.rb	(revision 51424)
+++ test/ruby/test_hash.rb	(revision 51425)
@@ -1281,6 +1281,7 @@ class TestHash < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_hash.rb#L1281
 
     bad = [
       5, true, false, nil,
+      0.0, 1.72723e-77,
     ].select do |x|
       hash = {x => bug9381}
       hash[wrapper.new(x)] != bug9381

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]