From 3f7221ad3dbe89832e330079df4b80e633b016ef Mon Sep 17 00:00:00 2001 From: nobu Date: Tue, 30 Jan 2018 05:48:28 +0000 Subject: [PATCH] force fixable * complex.c (nucomp_hash): force hash values fixable. [ruby-core:85224] [Bug #14420] * rational.c (nurat_hash): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62107 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- complex.c | 2 +- rational.c | 2 +- test/ruby/test_complex.rb | 8 ++++++-- test/ruby/test_rational.rb | 4 +++- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/complex.c b/complex.c index 9b54d6bbc2..dc7e61a605 100644 --- a/complex.c +++ b/complex.c @@ -1253,7 +1253,7 @@ nucomp_hash(VALUE self) n = rb_hash(dat->imag); h[1] = NUM2LONG(n); v = rb_memhash(h, sizeof(h)); - return LONG2FIX(v); + return ST2FIX(v); } /* :nodoc: */ diff --git a/rational.c b/rational.c index 7491b81cf8..e38695ec43 100644 --- a/rational.c +++ b/rational.c @@ -1783,7 +1783,7 @@ nurat_hash(VALUE self) n = rb_hash(dat->den); h[1] = NUM2LONG(n); v = rb_memhash(h, sizeof(h)); - return LONG2FIX(v); + return ST2FIX(v); } static VALUE diff --git a/test/ruby/test_complex.rb b/test/ruby/test_complex.rb index ded316841a..316e3e21ff 100644 --- a/test/ruby/test_complex.rb +++ b/test/ruby/test_complex.rb @@ -48,8 +48,12 @@ class Complex_Test < Test::Unit::TestCase end def test_hash - assert_kind_of(Integer, Complex(1,2).hash) - assert_kind_of(Integer, Complex(1.0,2.0).hash) + h = Complex(1,2).hash + assert_kind_of(Integer, h) + assert_nothing_raised {h.to_s} + h = Complex(1.0,2.0).hash + assert_kind_of(Integer, h) + assert_nothing_raised {h.to_s} h = {} h[Complex(0)] = 0 diff --git a/test/ruby/test_rational.rb b/test/ruby/test_rational.rb index 5ca5478f24..74fbbb49ec 100644 --- a/test/ruby/test_rational.rb +++ b/test/ruby/test_rational.rb @@ -42,7 +42,9 @@ class Rational_Test < Test::Unit::TestCase end def test_hash - assert_kind_of(Integer, Rational(1,2).hash) + h = Rational(1,2).hash + assert_kind_of(Integer, h) + assert_nothing_raised {h.to_s} h = {} h[Rational(0)] = 0