[前][次][番号順一覧][スレッド一覧]

ruby-changes:66157

From: =E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3 <ko1@a...>
Date: Wed, 12 May 2021 10:31:08 +0900 (JST)
Subject: [ruby-changes:66157] e1eff837cf (master): cdhash_cmp: recursively apply

https://git.ruby-lang.org/ruby.git/commit/?id=e1eff837cf

From e1eff837cf12a8e813de9d4ff2db50c9b68b86b5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3?=
 <shyouhei@r...>
Date: Fri, 7 May 2021 13:31:15 +0900
Subject: cdhash_cmp: recursively apply

For instance a rational's numerator can be a bignum.  Comparison using
C's == can be insufficient.
---
 compile.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/compile.c b/compile.c
index d9894d2..056b487 100644
--- a/compile.c
+++ b/compile.c
@@ -2008,12 +2008,12 @@ cdhash_cmp(VALUE val, VALUE lit) https://github.com/ruby/ruby/blob/trunk/compile.c#L2008
     else if (tlit == T_RATIONAL) {
         const struct RRational *rat1 = RRATIONAL(val);
         const struct RRational *rat2 = RRATIONAL(lit);
-        return (rat1->num == rat2->num) && (rat1->den == rat2->den);
+        return cdhash_cmp(rat1->num, rat2->num) && cdhash_cmp(rat1->den, rat2->den);
     }
     else if (tlit == T_COMPLEX) {
         const struct RComplex *comp1 = RCOMPLEX(val);
         const struct RComplex *comp2 = RCOMPLEX(lit);
-        return (comp1->real == comp2->real) && (comp1->imag == comp2->imag);
+        return cdhash_cmp(comp1->real, comp2->real) && cdhash_cmp(comp1->imag, comp2->imag);
     }
     else {
         UNREACHABLE_RETURN(-1);
-- 
cgit v1.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]