From b019719301b068bfc5fdfdbcba4559f0fc6b966c Mon Sep 17 00:00:00 2001 From: nobu Date: Thu, 7 Sep 2017 03:24:08 +0000 Subject: ruby.h: unnormalized Fixnum value * include/ruby/ruby.h (ST2FIX): fix unnormalized Fixnum value bug on mingw/mswin. [ruby-core:82687] [Bug #13877] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59765 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/bigdecimal/bigdecimal.c | 2 +- ext/date/date_core.c | 2 +- ext/openssl/ossl_bn.c | 2 +- include/ruby/ruby.h | 3 +++ internal.h | 2 -- test/bigdecimal/test_bigdecimal.rb | 1 + test/date/test_date.rb | 2 ++ test/openssl/test_bn.rb | 1 + 8 files changed, 10 insertions(+), 5 deletions(-) diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c index 301cd71bc0..d6bc8bdaa7 100644 --- a/ext/bigdecimal/bigdecimal.c +++ b/ext/bigdecimal/bigdecimal.c @@ -384,7 +384,7 @@ BigDecimal_hash(VALUE self) hash ^= rb_memhash(p->frac, sizeof(BDIGIT)*p->Prec); hash += p->exponent; } - return INT2FIX(hash); + return ST2FIX(hash); } /* diff --git a/ext/date/date_core.c b/ext/date/date_core.c index 99e06cfc45..dce0bf99ec 100644 --- a/ext/date/date_core.c +++ b/ext/date/date_core.c @@ -6444,7 +6444,7 @@ d_lite_hash(VALUE self) h[2] = m_df(dat); h[3] = m_sf(dat); v = rb_memhash(h, sizeof(h)); - return LONG2FIX(v); + return ST2FIX(v); } #include "date_tmx.h" diff --git a/ext/openssl/ossl_bn.c b/ext/openssl/ossl_bn.c index 94ef6fd6f7..d337d50961 100644 --- a/ext/openssl/ossl_bn.c +++ b/ext/openssl/ossl_bn.c @@ -991,7 +991,7 @@ ossl_bn_hash(VALUE self) ossl_raise(eBNError, NULL); } - hash = INT2FIX(rb_memhash(buf, len)); + hash = ST2FIX(rb_memhash(buf, len)); xfree(buf); return hash; diff --git a/include/ruby/ruby.h b/include/ruby/ruby.h index 43a5f6fdeb..ff1c463a29 100644 --- a/include/ruby/ruby.h +++ b/include/ruby/ruby.h @@ -1575,6 +1575,9 @@ rb_num2char_inline(VALUE x) #define NUM2CHR(x) RB_NUM2CHR(x) #define CHR2FIX(x) RB_CHR2FIX(x) +#define RB_ST2FIX(h) RB_LONG2FIX((long)(h)) +#define ST2FIX(h) RB_ST2FIX(h) + #define RB_ALLOC_N(type,n) ((type*)ruby_xmalloc2((size_t)(n),sizeof(type))) #define RB_ALLOC(type) ((type*)ruby_xmalloc(sizeof(type))) #define RB_ZALLOC_N(type,n) ((type*)ruby_xcalloc((size_t)(n),sizeof(type))) diff --git a/internal.h b/internal.h index 5f85909461..2994c6e742 100644 --- a/internal.h +++ b/internal.h @@ -372,8 +372,6 @@ ntz_intptr(uintptr_t x) VALUE rb_int128t2big(int128_t n); #endif -#define ST2FIX(h) LONG2FIX((long)(h)) - static inline long rb_overflowed_fix_to_int(long x) { diff --git a/test/bigdecimal/test_bigdecimal.rb b/test/bigdecimal/test_bigdecimal.rb index 7b720f4926..1becaf8093 100644 --- a/test/bigdecimal/test_bigdecimal.rb +++ b/test/bigdecimal/test_bigdecimal.rb @@ -549,6 +549,7 @@ class TestBigDecimal < Test::Unit::TestCase a.each_with_index do |x, i| assert_equal(i, h[x]) end + assert_instance_of(String, b.hash.to_s) end def test_marshal diff --git a/test/date/test_date.rb b/test/date/test_date.rb index 531495d87e..03e935e299 100644 --- a/test/date/test_date.rb +++ b/test/date/test_date.rb @@ -129,6 +129,8 @@ class TestDate < Test::Unit::TestCase assert_equal(3, h.size) assert_equal(9, h[Date.new(1999,5,25)]) assert_equal(9, h[DateTime.new(1999,5,25)]) + + assert_instance_of(String, Date.new(1999,5,25).hash.to_s) end def test_freeze diff --git a/test/openssl/test_bn.rb b/test/openssl/test_bn.rb index 7739028611..274afba3bb 100644 --- a/test/openssl/test_bn.rb +++ b/test/openssl/test_bn.rb @@ -270,6 +270,7 @@ class OpenSSL::TestBN < OpenSSL::TestCase assert_equal(1, @e1.cmp(-999)) assert_equal(0, @e1.ucmp(999)) assert_equal(0, @e1.ucmp(-999)) + assert_instance_of(String, @e1.hash.to_s) end end -- cgit v1.2.3