ruby-changes:12562
From: nobu <ko1@a...>
Date: Sat, 25 Jul 2009 13:44:56 +0900 (JST)
Subject: [ruby-changes:12562] Ruby:r24270 (trunk): * complex.c (nucomp_hash), rational.c (nurat_hash): not to use
nobu 2009-07-25 13:44:36 +0900 (Sat, 25 Jul 2009) New Revision: 24270 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=24270 Log: * 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] Modified files: trunk/ChangeLog trunk/complex.c trunk/rational.c trunk/test/ruby/test_complex.rb trunk/test/ruby/test_rational.rb Index: complex.c =================================================================== --- complex.c (revision 24269) +++ complex.c (revision 24270) @@ -1156,15 +1156,14 @@ 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); } Index: ChangeLog =================================================================== --- ChangeLog (revision 24269) +++ ChangeLog (revision 24270) @@ -1,3 +1,9 @@ +Sat Jul 25 13:44:28 2009 Nobuyoshi Nakada <nobu@r...> + + * 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 <naruse@r...> * enc/big5.c: Fix EncLen_BIG5 for Big5-HKSCS. see [ruby-core:24390] Index: test/ruby/test_complex.rb =================================================================== --- test/ruby/test_complex.rb (revision 24269) +++ test/ruby/test_complex.rb (revision 24270) @@ -36,6 +36,9 @@ 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 Index: test/ruby/test_rational.rb =================================================================== --- test/ruby/test_rational.rb (revision 24269) +++ test/ruby/test_rational.rb (revision 24270) @@ -35,6 +35,10 @@ 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 Index: rational.c =================================================================== --- rational.c (revision 24269) +++ rational.c (revision 24270) @@ -1360,15 +1360,14 @@ 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); } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/