From d6ab828369b8ab6995b47abd9ab5982618c2d334 Mon Sep 17 00:00:00 2001 From: nobu Date: Sat, 25 Jul 2009 04:44:36 +0000 Subject: * complex.c (nucomp_hash), rational.c (nurat_hash): not to use hash value of class so that equality against subclasses can work. [ruby-dev:38850] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24270 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 6 ++++++ complex.c | 7 +++---- rational.c | 7 +++---- test/ruby/test_complex.rb | 3 +++ test/ruby/test_rational.rb | 4 ++++ 5 files changed, 19 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 80f35087f3..479a9c68af 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Sat Jul 25 13:44:28 2009 Nobuyoshi Nakada + + * complex.c (nucomp_hash), rational.c (nurat_hash): not to use + hash value of class so that equality against subclasses can + work. [ruby-dev:38850] + Sat Jul 25 01:05:59 2009 NARUSE, Yui * enc/big5.c: Fix EncLen_BIG5 for Big5-HKSCS. see [ruby-core:24390] diff --git a/complex.c b/complex.c index fcaf2d8216..ee281ba819 100644 --- a/complex.c +++ b/complex.c @@ -1156,15 +1156,14 @@ nucomp_numerator(VALUE self) static VALUE nucomp_hash(VALUE self) { - long v, h[3]; + long v, h[2]; VALUE n; get_dat1(self); - h[0] = rb_hash(rb_obj_class(self)); n = rb_hash(dat->real); - h[1] = NUM2LONG(n); + h[0] = NUM2LONG(n); n = rb_hash(dat->imag); - h[2] = NUM2LONG(n); + h[1] = NUM2LONG(n); v = rb_memhash(h, sizeof(h)); return LONG2FIX(v); } diff --git a/rational.c b/rational.c index e5ae7301fc..ee5c448776 100644 --- a/rational.c +++ b/rational.c @@ -1360,15 +1360,14 @@ nurat_to_r(VALUE self) static VALUE nurat_hash(VALUE self) { - long v, h[3]; + long v, h[2]; VALUE n; get_dat1(self); - h[0] = rb_hash(rb_obj_class(self)); n = rb_hash(dat->num); - h[1] = NUM2LONG(n); + h[0] = NUM2LONG(n); n = rb_hash(dat->den); - h[2] = NUM2LONG(n); + h[1] = NUM2LONG(n); v = rb_memhash(h, sizeof(h)); return LONG2FIX(v); } diff --git a/test/ruby/test_complex.rb b/test/ruby/test_complex.rb index ca26f45d21..6885294f84 100644 --- a/test/ruby/test_complex.rb +++ b/test/ruby/test_complex.rb @@ -36,6 +36,9 @@ class Complex_Test < Test::Unit::TestCase assert_instance_of(ComplexSub, c5) end + c1 = Complex(1) + assert_equal(c1.hash, c.hash, '[ruby-dev:38850]') + assert_equal([true, true], [c.eql?(c1), c1.eql?(c)]) end def test_eql_p diff --git a/test/ruby/test_rational.rb b/test/ruby/test_rational.rb index 85545fea6b..82313db6b2 100644 --- a/test/ruby/test_rational.rb +++ b/test/ruby/test_rational.rb @@ -35,6 +35,10 @@ class Rational_Test < Test::Unit::TestCase assert_equal(c, c5) assert_instance_of(RationalSub, c5) end + + c1 = Rational(1) + assert_equal(c1.hash, c.hash, '[ruby-dev:38850]') + assert_equal([true, true], [c.eql?(c1), c1.eql?(c)]) end def test_eql_p -- cgit v1.2.3