ruby-changes:47649
From: nobu <ko1@a...>
Date: Thu, 7 Sep 2017 12:24:15 +0900 (JST)
Subject: [ruby-changes:47649] nobu:r59765 (trunk): ruby.h: unnormalized Fixnum value
nobu 2017-09-07 12:24:08 +0900 (Thu, 07 Sep 2017) New Revision: 59765 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=59765 Log: ruby.h: unnormalized Fixnum value * include/ruby/ruby.h (ST2FIX): fix unnormalized Fixnum value bug on mingw/mswin. [ruby-core:82687] [Bug #13877] Modified files: trunk/ext/bigdecimal/bigdecimal.c trunk/ext/date/date_core.c trunk/ext/openssl/ossl_bn.c trunk/include/ruby/ruby.h trunk/internal.h trunk/test/bigdecimal/test_bigdecimal.rb trunk/test/date/test_date.rb trunk/test/openssl/test_bn.rb Index: test/openssl/test_bn.rb =================================================================== --- test/openssl/test_bn.rb (revision 59764) +++ test/openssl/test_bn.rb (revision 59765) @@ -270,6 +270,7 @@ class OpenSSL::TestBN < OpenSSL::TestCas https://github.com/ruby/ruby/blob/trunk/test/openssl/test_bn.rb#L270 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 Index: test/date/test_date.rb =================================================================== --- test/date/test_date.rb (revision 59764) +++ test/date/test_date.rb (revision 59765) @@ -129,6 +129,8 @@ class TestDate < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/date/test_date.rb#L129 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 Index: test/bigdecimal/test_bigdecimal.rb =================================================================== --- test/bigdecimal/test_bigdecimal.rb (revision 59764) +++ test/bigdecimal/test_bigdecimal.rb (revision 59765) @@ -549,6 +549,7 @@ class TestBigDecimal < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/test/bigdecimal/test_bigdecimal.rb#L549 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 Index: internal.h =================================================================== --- internal.h (revision 59764) +++ internal.h (revision 59765) @@ -372,8 +372,6 @@ ntz_intptr(uintptr_t x) https://github.com/ruby/ruby/blob/trunk/internal.h#L372 VALUE rb_int128t2big(int128_t n); #endif -#define ST2FIX(h) LONG2FIX((long)(h)) - static inline long rb_overflowed_fix_to_int(long x) { Index: ext/bigdecimal/bigdecimal.c =================================================================== --- ext/bigdecimal/bigdecimal.c (revision 59764) +++ ext/bigdecimal/bigdecimal.c (revision 59765) @@ -384,7 +384,7 @@ BigDecimal_hash(VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L384 hash ^= rb_memhash(p->frac, sizeof(BDIGIT)*p->Prec); hash += p->exponent; } - return INT2FIX(hash); + return ST2FIX(hash); } /* Index: ext/date/date_core.c =================================================================== --- ext/date/date_core.c (revision 59764) +++ ext/date/date_core.c (revision 59765) @@ -6444,7 +6444,7 @@ d_lite_hash(VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/date/date_core.c#L6444 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" Index: ext/openssl/ossl_bn.c =================================================================== --- ext/openssl/ossl_bn.c (revision 59764) +++ ext/openssl/ossl_bn.c (revision 59765) @@ -991,7 +991,7 @@ ossl_bn_hash(VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_bn.c#L991 ossl_raise(eBNError, NULL); } - hash = INT2FIX(rb_memhash(buf, len)); + hash = ST2FIX(rb_memhash(buf, len)); xfree(buf); return hash; Index: include/ruby/ruby.h =================================================================== --- include/ruby/ruby.h (revision 59764) +++ include/ruby/ruby.h (revision 59765) @@ -1575,6 +1575,9 @@ rb_num2char_inline(VALUE x) https://github.com/ruby/ruby/blob/trunk/include/ruby/ruby.h#L1575 #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))) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/