From 7d91217a0a65ff24ab629bd63870a5b0a36775de Mon Sep 17 00:00:00 2001 From: Kazuki Yamaguchi Date: Sat, 9 Sep 2017 16:31:33 +0900 Subject: ruby.h: simplify RB_NUM2INT() and RB_FIX2INT() declaration --- include/ruby/backward.h | 5 +++++ include/ruby/ruby.h | 18 ++---------------- numeric.c | 34 ++++------------------------------ 3 files changed, 11 insertions(+), 46 deletions(-) diff --git a/include/ruby/backward.h b/include/ruby/backward.h index c3606ac614..e07e274cb1 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 60dbf79ec1..ca4897da1a 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 480ab7e0cb..739c968e6d 100644 --- a/numeric.c +++ b/numeric.c @@ -2878,14 +2878,6 @@ rb_out_of_int(SIGNED_VALUE num) num, num < 0 ? "small" : "big"); } -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) { @@ -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 -- cgit v1.2.3