diff options
author | nagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-03-19 17:30:19 +0000 |
---|---|---|
committer | nagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-03-19 17:30:19 +0000 |
commit | 58b2297da2c8b4975894c12e35a52c27bcf214aa (patch) | |
tree | 6f19d985c4eb3d3f13027fa1de82591aa3012534 | |
parent | 6423e5b4f34fbdc1750817e7b94188cbd53000e1 (diff) | |
download | ruby-58b2297da2c8b4975894c12e35a52c27bcf214aa.tar.gz |
merge revision(s) 61413: [Backport #14218]
force hash values fixable
* include/ruby/ruby.h (RB_ST2FIX): force fixable on LLP64 environment.
* hash.c (any_hash): ditto.
[ruby-core:84395] [Bug #14218]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_4@62849 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | hash.c | 10 | ||||
-rw-r--r-- | include/ruby/ruby.h | 4 | ||||
-rw-r--r-- | test/ruby/test_hash.rb | 7 | ||||
-rw-r--r-- | version.h | 2 |
4 files changed, 21 insertions, 2 deletions
@@ -198,8 +198,16 @@ any_hash(VALUE a, st_index_t (*other_func)(VALUE)) hnum = other_func(a); } out: +#if SIZEOF_LONG < SIZEOF_ST_INDEX_T + if (hnum > 0) + hnum &= (unsigned long)-1 >> 2; + else + hnum |= ~((unsigned long)-1 >> 2); +#else hnum <<= 1; - return (long)RSHIFT(hnum, 1); + hnum = RSHIFT(hnum, 1); +#endif + return (long)hnum; } static st_index_t diff --git a/include/ruby/ruby.h b/include/ruby/ruby.h index 43fe804337..ffec7050d3 100644 --- a/include/ruby/ruby.h +++ b/include/ruby/ruby.h @@ -1575,7 +1575,11 @@ rb_num2char_inline(VALUE x) #define NUM2CHR(x) RB_NUM2CHR(x) #define CHR2FIX(x) RB_CHR2FIX(x) +#if SIZEOF_LONG < SIZEOF_VALUE +#define RB_ST2FIX(h) RB_LONG2FIX((long)((h) > 0 ? (h) & (unsigned long)-1 >> 2 : (h) | ~((unsigned long)-1 >> 2))) +#else #define RB_ST2FIX(h) RB_LONG2FIX((long)(h)) +#endif #define ST2FIX(h) RB_ST2FIX(h) #define RB_ALLOC_N(type,n) ((type*)ruby_xmalloc2((size_t)(n),sizeof(type))) diff --git a/test/ruby/test_hash.rb b/test/ruby/test_hash.rb index 040d25e144..421e166801 100644 --- a/test/ruby/test_hash.rb +++ b/test/ruby/test_hash.rb @@ -1497,6 +1497,13 @@ class TestHash < Test::Unit::TestCase assert_equal(%w(1.0 2.1 3.2), y.values_at(:a, :b, :c)) end + def test_broken_hash_value + bug14218 = '[ruby-core:84395] [Bug #14218]' + + assert_equal(0, 1_000_000.times.count{a=Object.new.hash; b=Object.new.hash; a < 0 && b < 0 && a + b > 0}, bug14218) + assert_equal(0, 1_000_000.times.count{a=Object.new.hash; b=Object.new.hash; 0 + a + b != 0 + b + a}, bug14218) + end + class TestSubHash < TestHash class SubHash < Hash def reject(*) @@ -1,6 +1,6 @@ #define RUBY_VERSION "2.4.4" #define RUBY_RELEASE_DATE "2018-03-20" -#define RUBY_PATCHLEVEL 268 +#define RUBY_PATCHLEVEL 269 #define RUBY_RELEASE_YEAR 2018 #define RUBY_RELEASE_MONTH 3 |