From c56edb9a59488f5efb6b6cbe02ac9db10bc0e6d3 Mon Sep 17 00:00:00 2001 From: shyouhei Date: Thu, 9 Mar 2017 02:31:23 +0000 Subject: [PATCH] revert RB_FIXABLE related changesets [Bug #13288][Bug #13293][Bug #13294] This commit is auto-generated using following command: svn diff -r57807:57788 include internal.h bignum.c numeric.c compile.c insns.def object.c sprintf.c | patch -p0 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57818 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- bignum.c | 6 ++++-- compile.c | 2 +- include/ruby/ruby.h | 15 ++------------- insns.def | 2 +- internal.h | 11 ----------- numeric.c | 32 +++++++++++++++++++++----------- object.c | 5 ++++- sprintf.c | 6 +++++- 8 files changed, 38 insertions(+), 41 deletions(-) diff --git a/bignum.c b/bignum.c index 0e15e58c12..8c723300f4 100644 --- a/bignum.c +++ b/bignum.c @@ -3184,13 +3184,15 @@ rb_int2big(SIGNED_VALUE n) VALUE rb_uint2inum(VALUE n) { - return ULONG2NUM(n); + if (POSFIXABLE(n)) return LONG2FIX(n); + return rb_uint2big(n); } VALUE rb_int2inum(SIGNED_VALUE n) { - return LONG2NUM(n); + if (FIXABLE(n)) return LONG2FIX(n); + return rb_int2big(n); } void diff --git a/compile.c b/compile.c index 835fa41414..f1ba0946b3 100644 --- a/compile.c +++ b/compile.c @@ -3190,7 +3190,7 @@ case_when_optimizable_literal(NODE *node) double ival; if (RB_TYPE_P(v, T_FLOAT) && modf(RFLOAT_VALUE(v), &ival) == 0.0) { - return rb_dbl2ival(ival); + return FIXABLE(ival) ? LONG2FIX((long)ival) : rb_dbl2big(ival); } if (SYMBOL_P(v) || rb_obj_is_kind_of(v, rb_cNumeric)) { return v; diff --git a/include/ruby/ruby.h b/include/ruby/ruby.h index f99264f105..d770c30735 100644 --- a/include/ruby/ruby.h +++ b/include/ruby/ruby.h @@ -1504,17 +1504,6 @@ rb_integer_type_p(VALUE obj) } #endif -static inline int -rb_long_is_fixable_p(long v) -{ -#ifdef HAVE_BUILTIN___BUILTIN_ADD_OVERFLOW - SIGNED_VALUE w; - return! __builtin_add_overflow(v, v, &w); -#else - return RB_FIXABLE(v); -#endif -} - #if SIZEOF_INT < SIZEOF_LONG # define RB_INT2NUM(v) RB_INT2FIX((int)(v)) # define RB_UINT2NUM(v) RB_LONG2FIX((unsigned int)(v)) @@ -1522,7 +1511,7 @@ rb_long_is_fixable_p(long v) static inline VALUE rb_int2num_inline(int v) { - if (rb_long_is_fixable_p(v)) + if (RB_FIXABLE(v)) return RB_INT2FIX(v); else return rb_int2big(v); @@ -1545,7 +1534,7 @@ rb_uint2num_inline(unsigned int v) static inline VALUE rb_long2num_inline(long v) { - if (rb_long_is_fixable_p(v)) + if (RB_FIXABLE(v)) return RB_LONG2FIX(v); else return rb_int2big(v); diff --git a/insns.def b/insns.def index 15e9d828ea..9bae14b5a9 100644 --- a/insns.def +++ b/insns.def @@ -1345,7 +1345,7 @@ opt_case_dispatch if (RB_FLOAT_TYPE_P(key)) { double kval = RFLOAT_VALUE(key); if (!isinf(kval) && modf(kval, &kval) == 0.0) { - key = rb_dbl2ival(kval); + key = FIXABLE(kval) ? LONG2FIX((long)kval) : rb_dbl2big(kval); } } if (st_lookup(RHASH_TBL_RAW(hash), key, &val)) { diff --git a/internal.h b/internal.h index bc8d9d30d3..06455f9409 100644 --- a/internal.h +++ b/internal.h @@ -1383,17 +1383,6 @@ rb_float_new_inline(double d) #define rb_float_value(v) rb_float_value_inline(v) #define rb_float_new(d) rb_float_new_inline(d) -static inline VALUE -rb_dbl2ival(double d) -{ - if (RB_FIXABLE(d)) { - return LONG2FIX((long)d); - } - else { - return rb_dbl2big(d); - } -} - /* object.c */ void rb_obj_copy_ivar(VALUE dest, VALUE obj); CONSTFUNC(VALUE rb_obj_equal(VALUE obj1, VALUE obj2)); diff --git a/numeric.c b/numeric.c index c728e309f4..3d2b501ab2 100644 --- a/numeric.c +++ b/numeric.c @@ -1279,7 +1279,10 @@ flo_mod(VALUE x, VALUE y) static VALUE dbl2ival(double d) { - return rb_dbl2ival(d); + if (FIXABLE(d)) { + return LONG2FIX((long)d); + } + return rb_dbl2big(d); } /* @@ -1964,6 +1967,7 @@ static VALUE flo_floor(int argc, VALUE *argv, VALUE num) { double number, f; + long val; int ndigits = 0; if (rb_check_arity(argc, 0, 1)) { @@ -1980,7 +1984,11 @@ flo_floor(int argc, VALUE *argv, VALUE num) return DBL2NUM(f); } f = floor(number); - return dbl2ival(f); + if (!FIXABLE(f)) { + return rb_dbl2big(f); + } + val = (long)f; + return LONG2FIX(val); } /* @@ -2319,11 +2327,16 @@ static VALUE flo_to_i(VALUE num) { double f = RFLOAT_VALUE(num); + long val; if (f > 0.0) f = floor(f); if (f < 0.0) f = ceil(f); - return dbl2ival(f); + if (!FIXABLE(f)) { + return rb_dbl2big(f); + } + val = (long)f; + return LONG2FIX(val); } /* @@ -3008,15 +3021,12 @@ rb_num2fix(VALUE val) { long v; - if (FIXNUM_P(val)) { - return val; - } - else if (rb_long_is_fixable_p(v = rb_num2long(val))) { - return LONG2FIX(v); - } - else { + if (FIXNUM_P(val)) return val; + + v = rb_num2long(val); + if (!FIXABLE(v)) rb_raise(rb_eRangeError, "integer %ld out of range of fixnum", v); - } + return LONG2FIX(v); } #if HAVE_LONG_LONG diff --git a/object.c b/object.c index 21779401fb..9ec96687e9 100644 --- a/object.c +++ b/object.c @@ -2747,8 +2747,11 @@ rb_convert_to_integer(VALUE val, int base) VALUE tmp; if (RB_FLOAT_TYPE_P(val)) { + double f; if (base != 0) goto arg_error; - return rb_dbl2ival(RFLOAT_VALUE(val)); + f = RFLOAT_VALUE(val); + if (FIXABLE(f)) return LONG2FIX((long)f); + return rb_dbl2big(f); } else if (RB_INTEGER_TYPE_P(val)) { if (base != 0) goto arg_error; diff --git a/sprintf.c b/sprintf.c index 72ac664e0e..40872c0c16 100644 --- a/sprintf.c +++ b/sprintf.c @@ -832,7 +832,11 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt) bin_retry: switch (TYPE(val)) { case T_FLOAT: - val = rb_dbl2ival(RFLOAT_VALUE(val)); + if (FIXABLE(RFLOAT_VALUE(val))) { + val = LONG2FIX((long)RFLOAT_VALUE(val)); + goto bin_retry; + } + val = rb_dbl2big(RFLOAT_VALUE(val)); if (FIXNUM_P(val)) goto bin_retry; bignum = 1; break;