mirror of
https://github.com/ruby/ruby.git
synced 2025-09-16 17:14:01 +02:00
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] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_2@50619 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
c5a6913232
commit
c758d63138
6 changed files with 28 additions and 6 deletions
|
@ -1,3 +1,9 @@
|
||||||
|
Sun May 24 02:01:07 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* 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@ruby-lang.org>
|
Thu May 21 01:34:48 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* gc.c (id2ref): prohibit from accessing internal objects.
|
* gc.c (id2ref): prohibit from accessing internal objects.
|
||||||
|
|
5
hash.c
5
hash.c
|
@ -142,13 +142,16 @@ rb_any_hash(VALUE a)
|
||||||
}
|
}
|
||||||
else if (FLONUM_P(a)) {
|
else if (FLONUM_P(a)) {
|
||||||
/* prevent pathological behavior: [Bug #10761] */
|
/* 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);
|
hnum = rb_objid_hash((st_index_t)a);
|
||||||
}
|
}
|
||||||
else if (BUILTIN_TYPE(a) == T_STRING) {
|
else if (BUILTIN_TYPE(a) == T_STRING) {
|
||||||
hnum = rb_str_hash(a);
|
hnum = rb_str_hash(a);
|
||||||
}
|
}
|
||||||
|
else if (BUILTIN_TYPE(a) == T_FLOAT) {
|
||||||
|
return rb_dbl_hash(rb_float_value(a));
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
hval = rb_hash(a);
|
hval = rb_hash(a);
|
||||||
hnum = FIX2LONG(hval);
|
hnum = FIX2LONG(hval);
|
||||||
|
|
|
@ -773,6 +773,7 @@ double ruby_float_mod(double x, double y);
|
||||||
int rb_num_negative_p(VALUE);
|
int rb_num_negative_p(VALUE);
|
||||||
VALUE rb_int_succ(VALUE num);
|
VALUE rb_int_succ(VALUE num);
|
||||||
VALUE rb_int_pred(VALUE num);
|
VALUE rb_int_pred(VALUE num);
|
||||||
|
VALUE rb_dbl_hash(double d);
|
||||||
|
|
||||||
#if USE_FLONUM
|
#if USE_FLONUM
|
||||||
#define RUBY_BIT_ROTL(v, n) (((v) << (n)) | ((v) >> ((sizeof(v) * 8) - n)))
|
#define RUBY_BIT_ROTL(v, n) (((v) << (n)) | ((v) >> ((sizeof(v) * 8) - n)))
|
||||||
|
|
|
@ -1137,10 +1137,14 @@ flo_eq(VALUE x, VALUE y)
|
||||||
static VALUE
|
static VALUE
|
||||||
flo_hash(VALUE num)
|
flo_hash(VALUE num)
|
||||||
{
|
{
|
||||||
double d;
|
return rb_dbl_hash(RFLOAT_VALUE(num));
|
||||||
|
}
|
||||||
|
|
||||||
|
VALUE
|
||||||
|
rb_dbl_hash(double d)
|
||||||
|
{
|
||||||
st_index_t hash;
|
st_index_t hash;
|
||||||
|
|
||||||
d = RFLOAT_VALUE(num);
|
|
||||||
/* normalize -0.0 to 0.0 */
|
/* normalize -0.0 to 0.0 */
|
||||||
if (d == 0.0) d = 0.0;
|
if (d == 0.0) d = 0.0;
|
||||||
hash = rb_memhash(&d, sizeof(d));
|
hash = rb_memhash(&d, sizeof(d));
|
||||||
|
|
|
@ -672,4 +672,12 @@ class TestFloat < Test::Unit::TestCase
|
||||||
assert_equal(0.0, z)
|
assert_equal(0.0, z)
|
||||||
assert_equal(-Float::INFINITY, 1.0/z)
|
assert_equal(-Float::INFINITY, 1.0/z)
|
||||||
end
|
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
|
end
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
#define RUBY_VERSION "2.2.3"
|
#define RUBY_VERSION "2.2.3"
|
||||||
#define RUBY_RELEASE_DATE "2015-05-21"
|
#define RUBY_RELEASE_DATE "2015-05-24"
|
||||||
#define RUBY_PATCHLEVEL 115
|
#define RUBY_PATCHLEVEL 116
|
||||||
|
|
||||||
#define RUBY_RELEASE_YEAR 2015
|
#define RUBY_RELEASE_YEAR 2015
|
||||||
#define RUBY_RELEASE_MONTH 5
|
#define RUBY_RELEASE_MONTH 5
|
||||||
#define RUBY_RELEASE_DAY 21
|
#define RUBY_RELEASE_DAY 24
|
||||||
|
|
||||||
#include "ruby/version.h"
|
#include "ruby/version.h"
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue