aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKazuki Yamaguchi <k@rhe.jp>2017-09-09 16:31:33 +0900
committerKazuki Yamaguchi <k@rhe.jp>2017-09-09 16:31:33 +0900
commit7d91217a0a65ff24ab629bd63870a5b0a36775de (patch)
tree411c64fa616a40290e1a93d749976f17d16aace5
parent1dab9557432e12f489109966b8ab5c6cb85afba6 (diff)
downloadruby-wip/cleanup-num-macros.tar.gz
ruby.h: simplify RB_NUM2INT() and RB_FIX2INT() declarationwip/cleanup-num-macros
-rw-r--r--include/ruby/backward.h5
-rw-r--r--include/ruby/ruby.h18
-rw-r--r--numeric.c34
3 files changed, 11 insertions, 46 deletions
diff --git a/include/ruby/backward.h b/include/ruby/backward.h
index c3606ac..e07e274 100644
--- a/include/ruby/backward.h
+++ b/include/ruby/backward.h
@@ -24,6 +24,11 @@ DECLARE_DEPRECATED_FEATURE(2.2, rb_enable_super);
DECLARE_DEPRECATED_FEATURE(2.2, rb_hash_iter_lev);
DECLARE_DEPRECATED_FEATURE(2.2, rb_hash_ifnone);
+/* numeric.c */
+/* Note prototypes were only defined if SIZEOF_INT < SIZEOF_LONG. */
+DECLARE_DEPRECATED_FEATURE(2.5, rb_fix2int);
+DECLARE_DEPRECATED_FEATURE(2.5, rb_num2int);
+
/* string.c */
DECLARE_DEPRECATED_FEATURE(2.2, rb_str_associate);
DECLARE_DEPRECATED_FEATURE(2.2, rb_str_associated);
diff --git a/include/ruby/ruby.h b/include/ruby/ruby.h
index 60dbf79..ca4897d 100644
--- a/include/ruby/ruby.h
+++ b/include/ruby/ruby.h
@@ -649,29 +649,15 @@ rb_num2ulong_inline(VALUE x)
}
#define RB_NUM2ULONG(x) rb_num2ulong_inline(x)
#define NUM2ULONG(x) RB_NUM2ULONG(x)
+#define RB_NUM2INT(x) rb_long2int(RB_NUM2LONG(x))
+#define RB_FIX2INT(x) rb_long2int(RB_FIX2LONG(x))
#if SIZEOF_INT < SIZEOF_LONG
-long rb_num2int(VALUE);
-long rb_fix2int(VALUE);
-#define RB_FIX2INT(x) ((int)rb_fix2int((VALUE)(x)))
-
-static inline int
-rb_num2int_inline(VALUE x)
-{
- if (RB_FIXNUM_P(x))
- return (int)rb_fix2int(x);
- else
- return (int)rb_num2int(x);
-}
-#define RB_NUM2INT(x) rb_num2int_inline(x)
-
unsigned long rb_num2uint(VALUE);
#define RB_NUM2UINT(x) ((unsigned int)rb_num2uint(x))
unsigned long rb_fix2uint(VALUE);
#define RB_FIX2UINT(x) ((unsigned int)rb_fix2uint(x))
#else /* SIZEOF_INT < SIZEOF_LONG */
-#define RB_NUM2INT(x) ((int)RB_NUM2LONG(x))
#define RB_NUM2UINT(x) ((unsigned int)RB_NUM2ULONG(x))
-#define RB_FIX2INT(x) ((int)RB_FIX2LONG(x))
#define RB_FIX2UINT(x) ((unsigned int)RB_FIX2ULONG(x))
#endif /* SIZEOF_INT < SIZEOF_LONG */
#define NUM2INT(x) RB_NUM2INT(x)
diff --git a/numeric.c b/numeric.c
index 480ab7e..739c968 100644
--- a/numeric.c
+++ b/numeric.c
@@ -2879,14 +2879,6 @@ rb_out_of_int(SIGNED_VALUE num)
}
static void
-check_int(long num)
-{
- if ((long)(int)num != num) {
- rb_out_of_int(num);
- }
-}
-
-static void
check_uint(unsigned long num, int sign)
{
if (sign) {
@@ -2901,24 +2893,6 @@ check_uint(unsigned long num, int sign)
}
}
-long
-rb_num2int(VALUE val)
-{
- long num = rb_num2long(val);
-
- check_int(num);
- return num;
-}
-
-long
-rb_fix2int(VALUE val)
-{
- long num = FIXNUM_P(val)?FIX2LONG(val):rb_num2long(val);
-
- check_int(num);
- return num;
-}
-
unsigned long
rb_num2uint(VALUE val)
{
@@ -2942,19 +2916,19 @@ rb_fix2uint(VALUE val)
check_uint(num, negative_int_p(val));
return num;
}
-#else
+#endif
+
long
rb_num2int(VALUE val)
{
- return rb_num2long(val);
+ return NUM2INT(val);
}
long
rb_fix2int(VALUE val)
{
- return FIX2INT(val);
+ return FIX2INT(val)
}
-#endif
NORETURN(static void rb_out_of_short(SIGNED_VALUE num));
static void