mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Integer unification macro
* include/ruby/ruby.h (RUBY_INTEGER_UNIFICATION): macro to tell if Integer is integrated. [ruby-core:75718][Bug #12427] * include/ruby/backward.h, internal.h (rb_cFixnum, rb_cBignum): fallback to rb_cInteger. * bignum.c, numeric.c, ext/json/generator/generator.{c,h}: use the macro. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55394 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
ed75b6b4b0
commit
c071c05229
8 changed files with 61 additions and 11 deletions
11
ChangeLog
11
ChangeLog
|
@ -1,3 +1,14 @@
|
|||
Mon Jun 13 20:34:53 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* include/ruby/ruby.h (RUBY_INTEGER_UNIFICATION): macro to tell if
|
||||
Integer is integrated. [ruby-core:75718][Bug #12427]
|
||||
|
||||
* include/ruby/backward.h, internal.h (rb_cFixnum, rb_cBignum):
|
||||
fallback to rb_cInteger.
|
||||
|
||||
* bignum.c, numeric.c, ext/json/generator/generator.{c,h}: use the
|
||||
macro.
|
||||
|
||||
Mon Jun 13 16:58:53 2016 Martin Duerst <duerst@it.aoyama.ac.jp>
|
||||
|
||||
* test/ruby/enc/test_case_comprehensive.rb: Add tests for full Unicode
|
||||
|
|
4
bignum.c
4
bignum.c
|
@ -31,7 +31,9 @@
|
|||
|
||||
#define RB_BIGNUM_TYPE_P(x) RB_TYPE_P((x), T_BIGNUM)
|
||||
|
||||
#ifndef RUBY_INTEGER_UNIFICATION
|
||||
VALUE rb_cBignum;
|
||||
#endif
|
||||
const char ruby_digitmap[] = "0123456789abcdefghijklmnopqrstuvwxyz";
|
||||
|
||||
#ifndef SIZEOF_BDIGIT_DBL
|
||||
|
@ -6783,7 +6785,9 @@ rb_big_even_p(VALUE num)
|
|||
void
|
||||
Init_Bignum(void)
|
||||
{
|
||||
#ifndef RUBY_INTEGER_UNIFICATION
|
||||
rb_cBignum = rb_cInteger;
|
||||
#endif
|
||||
rb_define_const(rb_cObject, "Bignum", rb_cInteger);
|
||||
|
||||
rb_define_method(rb_cInteger, "coerce", rb_int_coerce, 1);
|
||||
|
|
|
@ -7,7 +7,13 @@ static ID i_encoding, i_encode;
|
|||
#endif
|
||||
|
||||
static VALUE mJSON, mExt, mGenerator, cState, mGeneratorMethods, mObject,
|
||||
mHash, mArray, mInteger, mFixnum, mBignum, mFloat, mString, mString_Extend,
|
||||
mHash, mArray,
|
||||
#ifdef RUBY_INTEGER_UNIFICATION
|
||||
mInteger,
|
||||
#else
|
||||
mFixnum, mBignum,
|
||||
#endif
|
||||
mFloat, mString, mString_Extend,
|
||||
mTrueClass, mFalseClass, mNilClass, eGeneratorError,
|
||||
eNestingError, CRegexp_MULTILINE, CJSON_SAFE_STATE_PROTOTYPE,
|
||||
i_SAFE_STATE_PROTOTYPE;
|
||||
|
@ -342,6 +348,7 @@ static VALUE mArray_to_json(int argc, VALUE *argv, VALUE self) {
|
|||
GENERATE_JSON(array);
|
||||
}
|
||||
|
||||
#ifdef RUBY_INTEGER_UNIFICATION
|
||||
/*
|
||||
* call-seq: to_json(*)
|
||||
*
|
||||
|
@ -352,6 +359,7 @@ static VALUE mInteger_to_json(int argc, VALUE *argv, VALUE self)
|
|||
GENERATE_JSON(integer);
|
||||
}
|
||||
|
||||
#else
|
||||
/*
|
||||
* call-seq: to_json(*)
|
||||
*
|
||||
|
@ -371,6 +379,7 @@ static VALUE mBignum_to_json(int argc, VALUE *argv, VALUE self)
|
|||
{
|
||||
GENERATE_JSON(bignum);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* call-seq: to_json(*)
|
||||
|
@ -835,6 +844,7 @@ static void generate_json_bignum(FBuffer *buffer, VALUE Vstate, JSON_Generator_S
|
|||
fbuffer_append_str(buffer, tmp);
|
||||
}
|
||||
|
||||
#ifdef RUBY_INTEGER_UNIFICATION
|
||||
static void generate_json_integer(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj)
|
||||
{
|
||||
if (FIXNUM_P(obj))
|
||||
|
@ -842,6 +852,7 @@ static void generate_json_integer(FBuffer *buffer, VALUE Vstate, JSON_Generator_
|
|||
else
|
||||
generate_json_bignum(buffer, Vstate, state, obj);
|
||||
}
|
||||
#endif
|
||||
|
||||
static void generate_json_float(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj)
|
||||
{
|
||||
|
@ -1420,16 +1431,15 @@ void Init_generator(void)
|
|||
rb_define_method(mHash, "to_json", mHash_to_json, -1);
|
||||
mArray = rb_define_module_under(mGeneratorMethods, "Array");
|
||||
rb_define_method(mArray, "to_json", mArray_to_json, -1);
|
||||
if (rb_cInteger == rb_cFixnum) {
|
||||
mInteger = rb_define_module_under(mGeneratorMethods, "Integer");
|
||||
rb_define_method(mInteger, "to_json", mInteger_to_json, -1);
|
||||
}
|
||||
else {
|
||||
mFixnum = rb_define_module_under(mGeneratorMethods, "Fixnum");
|
||||
rb_define_method(mFixnum, "to_json", mFixnum_to_json, -1);
|
||||
mBignum = rb_define_module_under(mGeneratorMethods, "Bignum");
|
||||
rb_define_method(mBignum, "to_json", mBignum_to_json, -1);
|
||||
}
|
||||
#ifdef RUBY_INTEGER_UNIFICATION
|
||||
mInteger = rb_define_module_under(mGeneratorMethods, "Integer");
|
||||
rb_define_method(mInteger, "to_json", mInteger_to_json, -1);
|
||||
#else
|
||||
mFixnum = rb_define_module_under(mGeneratorMethods, "Fixnum");
|
||||
rb_define_method(mFixnum, "to_json", mFixnum_to_json, -1);
|
||||
mBignum = rb_define_module_under(mGeneratorMethods, "Bignum");
|
||||
rb_define_method(mBignum, "to_json", mBignum_to_json, -1);
|
||||
#endif
|
||||
mFloat = rb_define_module_under(mGeneratorMethods, "Float");
|
||||
rb_define_method(mFloat, "to_json", mFloat_to_json, -1);
|
||||
mString = rb_define_module_under(mGeneratorMethods, "String");
|
||||
|
|
|
@ -99,8 +99,12 @@ typedef struct JSON_Generator_StateStruct {
|
|||
|
||||
static VALUE mHash_to_json(int argc, VALUE *argv, VALUE self);
|
||||
static VALUE mArray_to_json(int argc, VALUE *argv, VALUE self);
|
||||
#ifdef RUBY_INTEGER_UNIFICATION
|
||||
static VALUE mInteger_to_json(int argc, VALUE *argv, VALUE self);
|
||||
#else
|
||||
static VALUE mFixnum_to_json(int argc, VALUE *argv, VALUE self);
|
||||
static VALUE mBignum_to_json(int argc, VALUE *argv, VALUE self);
|
||||
#endif
|
||||
static VALUE mFloat_to_json(int argc, VALUE *argv, VALUE self);
|
||||
static VALUE mString_included_s(VALUE self, VALUE modul);
|
||||
static VALUE mString_to_json(int argc, VALUE *argv, VALUE self);
|
||||
|
@ -122,7 +126,9 @@ static void generate_json_string(FBuffer *buffer, VALUE Vstate, JSON_Generator_S
|
|||
static void generate_json_null(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
|
||||
static void generate_json_false(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
|
||||
static void generate_json_true(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
|
||||
#ifdef RUBY_INTEGER_UNIFICATION
|
||||
static void generate_json_integer(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
|
||||
#endif
|
||||
static void generate_json_fixnum(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
|
||||
static void generate_json_bignum(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
|
||||
static void generate_json_float(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
|
||||
|
|
|
@ -17,4 +17,9 @@ ruby_show_copyright_to_die(int exitcode)
|
|||
(exit(ruby_show_copyright_to_die(EXIT_SUCCESS)))
|
||||
#endif
|
||||
|
||||
#ifdef RUBY_INTEGER_UNIFICATION
|
||||
# define rb_cFixnum rb_cInteger
|
||||
# define rb_cBignum rb_cInteger
|
||||
#endif
|
||||
|
||||
#endif /* RUBY_RUBY_BACKWARD_H */
|
||||
|
|
|
@ -1502,6 +1502,7 @@ rb_obj_write(VALUE a, VALUE *slot, VALUE b, RB_UNUSED_VAR(const char *filename),
|
|||
return a;
|
||||
}
|
||||
|
||||
#define RUBY_INTEGER_UNIFICATION 1
|
||||
#define RB_INTEGER_TYPE_P(obj) rb_integer_type_p(obj)
|
||||
static inline int
|
||||
rb_integer_type_p(VALUE obj)
|
||||
|
@ -1865,7 +1866,9 @@ RUBY_EXTERN VALUE rb_mWaitWritable;
|
|||
RUBY_EXTERN VALUE rb_cBasicObject;
|
||||
RUBY_EXTERN VALUE rb_cObject;
|
||||
RUBY_EXTERN VALUE rb_cArray;
|
||||
#ifndef RUBY_INTEGER_UNIFICATION
|
||||
RUBY_EXTERN VALUE rb_cBignum;
|
||||
#endif
|
||||
RUBY_EXTERN VALUE rb_cBinding;
|
||||
RUBY_EXTERN VALUE rb_cClass;
|
||||
RUBY_EXTERN VALUE rb_cCont;
|
||||
|
@ -1875,7 +1878,9 @@ RUBY_EXTERN VALUE rb_cFalseClass;
|
|||
RUBY_EXTERN VALUE rb_cEncoding;
|
||||
RUBY_EXTERN VALUE rb_cEnumerator;
|
||||
RUBY_EXTERN VALUE rb_cFile;
|
||||
#ifndef RUBY_INTEGER_UNIFICATION
|
||||
RUBY_EXTERN VALUE rb_cFixnum;
|
||||
#endif
|
||||
RUBY_EXTERN VALUE rb_cFloat;
|
||||
RUBY_EXTERN VALUE rb_cHash;
|
||||
RUBY_EXTERN VALUE rb_cInteger;
|
||||
|
|
|
@ -780,6 +780,11 @@ struct MEMO {
|
|||
|
||||
#define STRING_P(s) (RB_TYPE_P((s), T_STRING) && CLASS_OF(s) == rb_cString)
|
||||
|
||||
#ifdef RUBY_INTEGER_UNIFICATION
|
||||
# define rb_cFixnum rb_cInteger
|
||||
# define rb_cBignum rb_cInteger
|
||||
#endif
|
||||
|
||||
enum {
|
||||
cmp_opt_Fixnum,
|
||||
cmp_opt_String,
|
||||
|
|
|
@ -111,7 +111,9 @@ static ID id_coerce, id_div, id_divmod;
|
|||
VALUE rb_cNumeric;
|
||||
VALUE rb_cFloat;
|
||||
VALUE rb_cInteger;
|
||||
#ifndef RUBY_INTEGER_UNIFICATION
|
||||
VALUE rb_cFixnum;
|
||||
#endif
|
||||
|
||||
VALUE rb_eZeroDivError;
|
||||
VALUE rb_eFloatDomainError;
|
||||
|
@ -4957,7 +4959,9 @@ Init_Numeric(void)
|
|||
rb_define_method(rb_cInteger, "size", int_size, 0);
|
||||
rb_define_method(rb_cInteger, "bit_length", rb_int_bit_length, 0);
|
||||
|
||||
#ifndef RUBY_INTEGER_UNIFICATION
|
||||
rb_cFixnum = rb_cInteger;
|
||||
#endif
|
||||
rb_define_const(rb_cObject, "Fixnum", rb_cInteger);
|
||||
|
||||
rb_cFloat = rb_define_class("Float", rb_cNumeric);
|
||||
|
|
Loading…
Add table
Reference in a new issue