8000 merge revision(s) 51423,51425: [Backport #9381] · github/ruby@170f64d · GitHub
[go: up one dir, main page]

Skip to content

Commit 170f64d

Browse files
committed
merge revision(s) 51423,51425: [Backport ruby#9381]
test_hash.rb: add assertions * test/ruby/test_hash.rb (test_wrapper_of_special_const): test other special obejcts. [Bug ruby#9381] * hash.c (rb_any_hash): fix Float hash. rb_dbl_hash() returns a Fixnum, but not a long. [Bug ruby#9381] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_1@51613 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent 445954a commit 170f64d

File tree

4 files changed

+18
-5
lines changed

4 files changed

+18
-5
lines changed

ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
Mon Aug 17 17:52:11 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
2+
3+
* hash.c (rb_any_hash): fix Float hash. rb_dbl_hash() returns a
4+
Fixnum, but not a long. [Bug #9381]
5+
16
Mon Aug 17 17:43:56 2015 Eric Wong <e@80x24.org>
27

38
* io.c (rb_io_oflags_modestr): handle O_TRUNC correctly

hash.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,17 @@ rb_any_hash(VALUE a)
135135
if (a == Qundef) return 0;
136136
if (FLONUM_P(a)) {
137137
/* prevent pathological behavior: [Bug #10761] */
138-
return rb_dbl_hash(rb_float_value(a));
138+
goto flt;
139139
}
140140
hnum = rb_objid_hash((st_index_t)a);
141141
}
142142
else if (BUILTIN_TYPE(a) == T_STRING) {
143143
hnum = rb_str_hash(a);
144144
}
145145
else if (BUILTIN_TYPE(a) == T_FLOAT) {
146-
return rb_dbl_hash(rb_float_value(a));
146+
flt:
147+
hval = rb_dbl_hash(rb_float_value(a));
148+
hnum = FIX2LONG(hval);
147149
}
148150
else {
149151
hval = rb_hash(a);

test/ruby/test_hash.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,8 +1262,14 @@ def eql?(other)
12621262
end
12631263
end
12641264

1265-
hash = {5 => bug9381}
1266-
assert_equal(bug9381, hash[wrapper.new(5)])
1265+
bad = [
1266+
5, true, false, nil,
1267+
0.0, 1.72723e-77,
1268+
].select do |x|
1269+
hash = {x => bug9381}
1270+
hash[wrapper.new(x)] != bug9381
1271+
end
1272+
assert_empty(bad, bug9381)
12671273
end
12681274

12691275
class TestSubHash < TestHash

version.h

Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#define RUBY_VERSION "2.1.7"
22
#define RUBY_RELEASE_DATE "2015-08-17"
3-
#define RUBY_PATCHLEVEL 395
3+
#define RUBY_PATCHLEVEL 396
44

55
#define RUBY_RELEASE_YEAR 2015
66
#define RUBY_RELEASE_MONTH 8