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

ruby-changes:67916

From: S-H-GAMELINKS <ko1@a...>
Date: Sat, 11 Sep 2021 09:13:41 +0900 (JST)
Subject: [ruby-changes:67916] 032534dbdf (master): Using RB_BIGNUM_TYPE_P macro

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

From 032534dbdf08c0912dffa482e29a491b8aa9276c Mon Sep 17 00:00:00 2001
From: S-H-GAMELINKS <gamelinks007@g...>
Date: Fri, 3 Sep 2021 20:50:12 +0900
Subject: Using RB_BIGNUM_TYPE_P macro

---
 array.c    |   4 +-
 bignum.c   |   2 -
 complex.c  |   2 +-
 enum.c     |   6 +--
 gc.c       |   4 +-
 hash.c     |   2 +-
 internal.h |   1 +
 io.c       |   2 +-
 math.c     |   2 -
 numeric.c  | 158 ++++++++++++++++++++++++++++++-------------------------------
 object.c   |   2 +-
 rational.c |   6 +--
 strftime.c |   2 +-
 thread.c   |   2 +-
 time.c     |  16 +++----
 15 files changed, 104 insertions(+), 107 deletions(-)

diff --git a/array.c b/array.c
index 66dc525..20ed970 100644
--- a/array.c
+++ b/array.c
@@ -7803,7 +7803,7 @@ rb_ary_sum(int argc, VALUE *argv, VALUE ary) https://github.com/ruby/ruby/blob/trunk/array.c#L7803
                 n = 0;
             }
         }
-        else if (RB_TYPE_P(e, T_BIGNUM))
+        else if (RB_BIGNUM_TYPE_P(e))
             v = rb_big_plus(e, v);
         else if (RB_TYPE_P(e, T_RATIONAL)) {
             if (r == Qundef)
@@ -7840,7 +7840,7 @@ rb_ary_sum(int argc, VALUE *argv, VALUE ary) https://github.com/ruby/ruby/blob/trunk/array.c#L7840
                 x = RFLOAT_VALUE(e);
             else if (FIXNUM_P(e))
                 x = FIX2LONG(e);
-            else if (RB_TYPE_P(e, T_BIGNUM))
+            else if (RB_BIGNUM_TYPE_P(e))
                 x = rb_big2dbl(e);
             else if (RB_TYPE_P(e, T_RATIONAL))
                 x = rb_num2dbl(e);
diff --git a/bignum.c b/bignum.c
index 9e1ded5..806d589 100644
--- a/bignum.c
+++ b/bignum.c
@@ -42,8 +42,6 @@ https://github.com/ruby/ruby/blob/trunk/bignum.c#L42
 #include "ruby/util.h"
 #include "ruby_assert.h"
 
-#define RB_BIGNUM_TYPE_P(x) RB_TYPE_P((x), T_BIGNUM)
-
 const char ruby_digitmap[] = "0123456789abcdefghijklmnopqrstuvwxyz";
 
 #ifndef SIZEOF_BDIGIT_DBL
diff --git a/complex.c b/complex.c
index 584619a..ec77aeb 100644
--- a/complex.c
+++ b/complex.c
@@ -1058,7 +1058,7 @@ rb_complex_pow(VALUE self, VALUE other) https://github.com/ruby/ruby/blob/trunk/complex.c#L1058
     if (k_numeric_p(other) && f_real_p(other)) {
 	VALUE r, theta;
 
-	if (RB_TYPE_P(other, T_BIGNUM))
+	if (RB_BIGNUM_TYPE_P(other))
 	    rb_warn("in a**b, b may be too big");
 
 	r = f_abs(self);
diff --git a/enum.c b/enum.c
index 4a4bb95..b73e96b 100644
--- a/enum.c
+++ b/enum.c
@@ -848,7 +848,7 @@ ary_inject_op(VALUE ary, VALUE init, VALUE op) https://github.com/ruby/ruby/blob/trunk/enum.c#L848
                         n = 0;
                     }
                 }
-                else if (RB_TYPE_P(e, T_BIGNUM))
+                else if (RB_BIGNUM_TYPE_P(e))
                     v = rb_big_plus(e, v);
                 else
                     goto not_integer;
@@ -4173,8 +4173,8 @@ enum_sum(int argc, VALUE* argv, VALUE obj) https://github.com/ruby/ruby/blob/trunk/enum.c#L4173
 
     if (RTEST(rb_range_values(obj, &beg, &end, &excl))) {
         if (!memo.block_given && !memo.float_value &&
-                (FIXNUM_P(beg) || RB_TYPE_P(beg, T_BIGNUM)) &&
-                (FIXNUM_P(end) || RB_TYPE_P(end, T_BIGNUM))) {
+                (FIXNUM_P(beg) || RB_BIGNUM_TYPE_P(beg)) &&
+                (FIXNUM_P(end) || RB_BIGNUM_TYPE_P(end))) {
             return int_range_sum(beg, end, excl, memo.v);
         }
     }
diff --git a/gc.c b/gc.c
index ac280f1..b5656c5 100644
--- a/gc.c
+++ b/gc.c
@@ -3417,7 +3417,7 @@ obj_free(rb_objspace_t *objspace, VALUE obj) https://github.com/ruby/ruby/blob/trunk/gc.c#L3417
 static int
 object_id_cmp(st_data_t x, st_data_t y)
 {
-    if (RB_TYPE_P(x, T_BIGNUM)) {
+    if (RB_BIGNUM_TYPE_P(x)) {
         return !rb_big_eql(x, y);
     }
     else {
@@ -3428,7 +3428,7 @@ object_id_cmp(st_data_t x, st_data_t y) https://github.com/ruby/ruby/blob/trunk/gc.c#L3428
 static st_index_t
 object_id_hash(st_data_t n)
 {
-    if (RB_TYPE_P(n, T_BIGNUM)) {
+    if (RB_BIGNUM_TYPE_P(n)) {
         return FIX2LONG(rb_big_hash(n));
     }
     else {
diff --git a/hash.c b/hash.c
index 314ac18..0929842 100644
--- a/hash.c
+++ b/hash.c
@@ -132,7 +132,7 @@ rb_hash(VALUE obj) https://github.com/ruby/ruby/blob/trunk/hash.c#L132
     }
 
     while (!FIXNUM_P(hval)) {
-        if (RB_TYPE_P(hval, T_BIGNUM)) {
+        if (RB_BIGNUM_TYPE_P(hval)) {
             int sign;
             unsigned long ul;
             sign = rb_integer_pack(hval, &ul, 1, sizeof(ul), 0,
diff --git a/internal.h b/internal.h
index 8c116f8..00a8295 100644
--- a/internal.h
+++ b/internal.h
@@ -104,5 +104,6 @@ RUBY_SYMBOL_EXPORT_END https://github.com/ruby/ruby/blob/trunk/internal.h#L104
 #define bp() ruby_debug_breakpoint()
 
 #define RBOOL(v) ((v) ? Qtrue : Qfalse)
+#define RB_BIGNUM_TYPE_P(x) RB_TYPE_P((x), T_BIGNUM)
 
 #endif /* RUBY_INTERNAL_H */
diff --git a/io.c b/io.c
index 2e4c335..e2f6875 100644
--- a/io.c
+++ b/io.c
@@ -4543,7 +4543,7 @@ rb_io_ungetc(VALUE io, VALUE c) https://github.com/ruby/ruby/blob/trunk/io.c#L4543
     if (FIXNUM_P(c)) {
 	c = rb_enc_uint_chr(FIX2UINT(c), io_read_encoding(fptr));
     }
-    else if (RB_TYPE_P(c, T_BIGNUM)) {
+    else if (RB_BIGNUM_TYPE_P(c)) {
 	c = rb_enc_uint_chr(NUM2UINT(c), io_read_encoding(fptr));
     }
     else {
diff --git a/math.c b/math.c
index 4298267..dd45caf 100644
--- a/math.c
+++ b/math.c
@@ -26,8 +26,6 @@ https://github.com/ruby/ruby/blob/trunk/math.c#L26
 #include "internal/object.h"
 #include "internal/vm.h"
 
-#define RB_BIGNUM_TYPE_P(x) RB_TYPE_P((x), T_BIGNUM)
-
 VALUE rb_mMath;
 VALUE rb_eMathDomainError;
 
diff --git a/numeric.c b/numeric.c
index bdf6b26..9252c7c 100644
--- a/numeric.c
+++ b/numeric.c
@@ -262,7 +262,7 @@ rb_num_to_uint(VALUE val, unsigned int *ret) https://github.com/ruby/ruby/blob/trunk/numeric.c#L262
 	return 0;
     }
 
-    if (RB_TYPE_P(val, T_BIGNUM)) {
+    if (RB_BIGNUM_TYPE_P(val)) {
 	if (BIGNUM_NEGATIVE_P(val)) return NUMERR_NEGATIVE;
 #if SIZEOF_INT < SIZEOF_LONG
 	/* long is 64bit */
@@ -285,7 +285,7 @@ int_pos_p(VALUE num) https://github.com/ruby/ruby/blob/trunk/numeric.c#L285
     if (FIXNUM_P(num)) {
 	return FIXNUM_POSITIVE_P(num);
     }
-    else if (RB_TYPE_P(num, T_BIGNUM)) {
+    else if (RB_BIGNUM_TYPE_P(num)) {
 	return BIGNUM_POSITIVE_P(num);
     }
     rb_raise(rb_eTypeError, "not an Integer");
@@ -297,7 +297,7 @@ int_neg_p(VALUE num) https://github.com/ruby/ruby/blob/trunk/numeric.c#L297
     if (FIXNUM_P(num)) {
 	return FIXNUM_NEGATIVE_P(num);
     }
-    else if (RB_TYPE_P(num, T_BIGNUM)) {
+    else if (RB_BIGNUM_TYPE_P(num)) {
 	return BIGNUM_NEGATIVE_P(num);
     }
     rb_raise(rb_eTypeError, "not an Integer");
@@ -760,7 +760,7 @@ int_zero_p(VALUE num) https://github.com/ruby/ruby/blob/trunk/numeric.c#L760
 	}
     }
     else {
-        assert(RB_TYPE_P(num, T_BIGNUM));
+        assert(RB_BIGNUM_TYPE_P(num));
 	if (rb_bigzero_p(num)) {
 	    /* this should not happen usually */
 	    return Qtrue;
@@ -830,7 +830,7 @@ num_positive_p(VALUE num) https://github.com/ruby/ruby/blob/trunk/numeric.c#L830
 	if (method_basic_p(rb_cInteger))
 	    return RBOOL((SIGNED_VALUE)num > (SIGNED_VALUE)INT2FIX(0));
     }
-    else if (RB_TYPE_P(num, T_BIGNUM)) {
+    else if (RB_BIGNUM_TYPE_P(num)) {
 	if (method_basic_p(rb_cInteger))
 	    return RBOOL(BIGNUM_POSITIVE_P(num) && !rb_bigzero_p(num));
     }
@@ -997,7 +997,7 @@ rb_float_plus(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/numeric.c#L997
     if (RB_TYPE_P(y, T_FIXNUM)) {
 	return DBL2NUM(RFLOAT_VALUE(x) + (double)FIX2LONG(y));
     }
-    else if (RB_TYPE_P(y, T_BIGNUM)) {
+    else if (RB_BIGNUM_TYPE_P(y)) {
 	return DBL2NUM(RFLOAT_VALUE(x) + rb_big2dbl(y));
     }
     else if (RB_TYPE_P(y, T_FLOAT)) {
@@ -1021,7 +1021,7 @@ rb_float_minus(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/numeric.c#L1021
     if (RB_TYPE_P(y, T_FIXNUM)) {
 	return DBL2NUM(RFLOAT_VALUE(x) - (double)FIX2LONG(y));
     }
-    else if (RB_TYPE_P(y, T_BIGNUM)) {
+    else if (RB_BIGNUM_TYPE_P(y)) {
 	return DBL2NUM(RFLOAT_VALUE(x) - rb_big2dbl(y));
     }
     else if (RB_TYPE_P(y, T_FLOAT)) {
@@ -1045,7 +1045,7 @@ rb_float_mul(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/numeric.c#L1045
     if (RB_TYPE_P(y, T_FIXNUM)) {
 	return DBL2NUM(RFLOAT_VALUE(x) * (double)FIX2LONG(y));
     }
-    else if (RB_TYPE_P(y, T_BIGNUM)) {
+    else if (RB_BIGNUM_TYPE_P(y)) {
 	return DBL2NUM(RFLOAT_VALUE(x) * rb_big2dbl(y));
     }
     else if (RB_TYPE_P(y, T_FLOAT)) {
@@ -1097,7 +1097,7 @@ rb_float_div(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/numeric.c#L1097
     if (RB_TYPE_P(y, T_FIXNUM)) {
         den = FIX2LONG(y);
     }
-    else if (RB_TYPE_P(y, T_BIGNUM)) {
+    else if (RB_BIGNUM_TYPE_P(y)) {
         den = rb_big2dbl(y);
     }
     else if (RB_TYPE_P(y, T_FLOAT)) {
@@ -1195,7 +1195,7 @@ flo_mod(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/numeric.c#L1195
     if (RB_TYPE_P(y, T_FIXNUM)) {
 	fy = (double)FIX2LONG(y);
     }
-    else if (RB_TYPE_P(y, T_BIGNUM)) {
+    else if (RB_BIGNUM_TYPE_P(y)) {
 	fy = rb_big2dbl(y);
     }
     else if (RB_TYPE_P(y, T_FLOAT)) {
@@ -1235,7 +1235,7 @@ flo_divmod(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/numeric.c#L1235
     if (RB_TYPE_P(y, T_FIXNUM)) {
 	fy = (double)FIX2LONG(y);
     }
-    else if (RB_TYPE_P(y, T_BIGNUM)) {
+    else if (RB_BIGNUM_TYPE_P(y)) {
 	fy = rb_big2dbl(y);
     }
     else if (RB_TYPE_P(y, T_FLOAT)) {
@@ -1271,7 +1271,7 @@ rb_float_pow(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/numeric.c#L1271
 	dx = RFLOAT_VALUE(x);
 	dy = (double)FIX2LONG(y);
     }
-    else if (RB_TYPE_P(y, T_BIGNUM)) {
+    else if (RB_BIGNUM_TYPE_P(y)) {
 	dx = RFLOAT_VALUE(x);
 	dy = rb_big2dbl(y);
     }
@@ -1304,7 +1304,7 @@ num_eql(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/numeric.c#L1304
 {
     if (TYPE(x) != TYPE(y)) return Qfalse;
 
-    if (RB_TYPE_P(x, T_BIGNUM)) {
+    if (RB_BIGNUM_TYPE_P(x)) {
 	return rb_big_eql(x, y);
     }
 
@@ -1352,7 +1352,7 @@ (... truncated)

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

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