aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-05-18 01:17:43 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-05-18 01:17:43 +0000
commit7ec4533c93adc4838ce53f5119c2702b10c9043f (patch)
treeadf65284cfe148dee36c8d8def3739543dcdf37a
parent3736ef5b0f89887a0b47edf5b23c33698c5f1645 (diff)
downloadruby-7ec4533c93adc4838ce53f5119c2702b10c9043f.tar.gz
ruby.h: RB_INTEGER_TYPE_P
* include/ruby/ruby.h (RB_INTEGER_TYPE_P): new macro and underlying inline function to check if the object is an Integer (Fixnum or Bignum). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55044 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog6
-rw-r--r--complex.c4
-rw-r--r--ext/date/date_core.c4
-rw-r--r--include/ruby/ruby.h9
-rw-r--r--numeric.c5
-rw-r--r--rational.c4
-rw-r--r--sprintf.c2
-rw-r--r--string.c2
8 files changed, 25 insertions, 11 deletions
diff --git a/ChangeLog b/ChangeLog
index 9fa9609fe0..c3ffe672df 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Wed May 18 10:17:41 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * include/ruby/ruby.h (RB_INTEGER_TYPE_P): new macro and
+ underlying inline function to check if the object is an
+ Integer (Fixnum or Bignum).
+
Wed May 18 09:52:00 2016 Kenta Murata <mrkn@mrkn.jp>
* enum.c (enum_sum, hash_sum, hash_sum_i, enum_sum_i, sum_iter):
diff --git a/complex.c b/complex.c
index ef3c01d0f8..181448d8d8 100644
--- a/complex.c
+++ b/complex.c
@@ -110,7 +110,7 @@ f_mul(VALUE x, VALUE y)
if (FIXNUM_P(y)) {
long iy = FIX2LONG(y);
if (iy == 0) {
- if (FIXNUM_P(x) || RB_TYPE_P(x, T_BIGNUM))
+ if (RB_INTEGER_TYPE_P(x))
return ZERO;
}
else if (iy == 1)
@@ -119,7 +119,7 @@ f_mul(VALUE x, VALUE y)
else if (FIXNUM_P(x)) {
long ix = FIX2LONG(x);
if (ix == 0) {
- if (FIXNUM_P(y) || RB_TYPE_P(y, T_BIGNUM))
+ if (RB_INTEGER_TYPE_P(y))
return ZERO;
}
else if (ix == 1)
diff --git a/ext/date/date_core.c b/ext/date/date_core.c
index 3a10fcb746..90377bf007 100644
--- a/ext/date/date_core.c
+++ b/ext/date/date_core.c
@@ -1360,7 +1360,7 @@ encode_year(VALUE nth, int y, double style,
static void
decode_jd(VALUE jd, VALUE *nth, int *rjd)
{
- assert(FIXNUM_P(jd) || RB_TYPE_P(jd, T_BIGNUM));
+ assert(RB_INTEGER_TYPE_P(jd));
*nth = f_idiv(jd, INT2FIX(CM_PERIOD));
if (f_zero_p(*nth)) {
assert(FIXNUM_P(jd));
@@ -3133,7 +3133,7 @@ wholenum_p(VALUE x)
inline static VALUE
to_integer(VALUE x)
{
- if (FIXNUM_P(x) || RB_TYPE_P(x, T_BIGNUM))
+ if (RB_INTEGER_TYPE_P(x))
return x;
return f_to_i(x);
}
diff --git a/include/ruby/ruby.h b/include/ruby/ruby.h
index 6f7ce0f217..e09d4a739b 100644
--- a/include/ruby/ruby.h
+++ b/include/ruby/ruby.h
@@ -1504,6 +1504,15 @@ rb_obj_write(VALUE a, VALUE *slot, VALUE b, RB_UNUSED_VAR(const char *filename),
return a;
}
+#define RB_INTEGER_TYPE_P(obj) rb_integer_type_p(obj)
+static inline int
+rb_integer_type_p(VALUE obj)
+{
+ return (RB_FIXNUM_P(obj) ||
+ (!RB_SPECIAL_CONST_P(obj) &&
+ RB_BUILTIN_TYPE(obj) == RUBY_T_BIGNUM));
+}
+
#if SIZEOF_INT < SIZEOF_LONG
# define RB_INT2NUM(v) INT2FIX((int)(v))
# define RB_UINT2NUM(v) LONG2FIX((unsigned int)(v))
diff --git a/numeric.c b/numeric.c
index c61f5d0982..6523249697 100644
--- a/numeric.c
+++ b/numeric.c
@@ -4037,11 +4037,10 @@ int_comp(VALUE num)
static int
bit_coerce(VALUE *x, VALUE *y)
{
- if (!FIXNUM_P(*y) && !RB_TYPE_P(*y, T_BIGNUM)) {
+ if (!RB_INTEGER_TYPE_P(*y)) {
VALUE orig = *x;
do_coerce(x, y, TRUE);
- if (!FIXNUM_P(*x) && !RB_TYPE_P(*x, T_BIGNUM)
- && !FIXNUM_P(*y) && !RB_TYPE_P(*y, T_BIGNUM)) {
+ if (!RB_INTEGER_TYPE_P(*x) && !RB_INTEGER_TYPE_P(*y)) {
coerce_failed(orig, *y);
}
}
diff --git a/rational.c b/rational.c
index f4b34dac4c..1909536461 100644
--- a/rational.c
+++ b/rational.c
@@ -106,7 +106,7 @@ f_mul(VALUE x, VALUE y)
if (FIXNUM_P(y)) {
long iy = FIX2LONG(y);
if (iy == 0) {
- if (FIXNUM_P(x) || RB_TYPE_P(x, T_BIGNUM))
+ if (RB_INTEGER_TYPE_P(x))
return ZERO;
}
else if (iy == 1)
@@ -115,7 +115,7 @@ f_mul(VALUE x, VALUE y)
else if (FIXNUM_P(x)) {
long ix = FIX2LONG(x);
if (ix == 0) {
- if (FIXNUM_P(y) || RB_TYPE_P(y, T_BIGNUM))
+ if (RB_INTEGER_TYPE_P(y))
return ZERO;
}
else if (ix == 1)
diff --git a/sprintf.c b/sprintf.c
index d8069b69df..c6afb0da59 100644
--- a/sprintf.c
+++ b/sprintf.c
@@ -1043,7 +1043,7 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
VALUE val = GETARG(), num, den;
int sign = (flags&FPLUS) ? 1 : 0, zero = 0;
long len, fill;
- if (FIXNUM_P(val) || RB_TYPE_P(val, T_BIGNUM)) {
+ if (RB_INTEGER_TYPE_P(val)) {
den = INT2FIX(1);
num = val;
}
diff --git a/string.c b/string.c
index 5c09465196..1e4d867f9d 100644
--- a/string.c
+++ b/string.c
@@ -2746,7 +2746,7 @@ rb_str_concat(VALUE str1, VALUE str2)
rb_encoding *enc = STR_ENC_GET(str1);
int encidx;
- if (FIXNUM_P(str2) || RB_TYPE_P(str2, T_BIGNUM)) {
+ if (RB_INTEGER_TYPE_P(str2)) {
if (rb_num_to_uint(str2, &code) == 0) {
}
else if (FIXNUM_P(str2)) {