ruby-changes:43320
From: nobu <ko1@a...>
Date: Mon, 13 Jun 2016 20:35:01 +0900 (JST)
Subject: [ruby-changes:43320] nobu:r55394 (trunk): Integer unification macro
nobu 2016-06-13 20:34:56 +0900 (Mon, 13 Jun 2016) New Revision: 55394 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=55394 Log: 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. Modified files: trunk/ChangeLog trunk/bignum.c trunk/ext/json/generator/generator.c trunk/ext/json/generator/generator.h trunk/include/ruby/backward.h trunk/include/ruby/ruby.h trunk/internal.h trunk/numeric.c Index: numeric.c =================================================================== --- numeric.c (revision 55393) +++ numeric.c (revision 55394) @@ -111,7 +111,9 @@ static ID id_coerce, id_div, id_divmod; https://github.com/ruby/ruby/blob/trunk/numeric.c#L111 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) https://github.com/ruby/ruby/blob/trunk/numeric.c#L4959 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); Index: ext/json/generator/generator.c =================================================================== --- ext/json/generator/generator.c (revision 55393) +++ ext/json/generator/generator.c (revision 55394) @@ -7,7 +7,13 @@ static ID i_encoding, i_encode; https://github.com/ruby/ruby/blob/trunk/ext/json/generator/generator.c#L7 #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, VA https://github.com/ruby/ruby/blob/trunk/ext/json/generator/generator.c#L348 GENERATE_JSON(array); } +#ifdef RUBY_INTEGER_UNIFICATION /* * call-seq: to_json(*) * @@ -352,6 +359,7 @@ static VALUE mInteger_to_json(int argc, https://github.com/ruby/ruby/blob/trunk/ext/json/generator/generator.c#L359 GENERATE_JSON(integer); } +#else /* * call-seq: to_json(*) * @@ -371,6 +379,7 @@ static VALUE mBignum_to_json(int argc, V https://github.com/ruby/ruby/blob/trunk/ext/json/generator/generator.c#L379 { GENERATE_JSON(bignum); } +#endif /* * call-seq: to_json(*) @@ -835,6 +844,7 @@ static void generate_json_bignum(FBuffer https://github.com/ruby/ruby/blob/trunk/ext/json/generator/generator.c#L844 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(FBuffe https://github.com/ruby/ruby/blob/trunk/ext/json/generator/generator.c#L852 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) https://github.com/ruby/ruby/blob/trunk/ext/json/generator/generator.c#L1431 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"); Index: ext/json/generator/generator.h =================================================================== --- ext/json/generator/generator.h (revision 55393) +++ ext/json/generator/generator.h (revision 55394) @@ -99,8 +99,12 @@ typedef struct JSON_Generator_StateStruc https://github.com/ruby/ruby/blob/trunk/ext/json/generator/generator.h#L99 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 https://github.com/ruby/ruby/blob/trunk/ext/json/generator/generator.h#L126 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); Index: include/ruby/backward.h =================================================================== --- include/ruby/backward.h (revision 55393) +++ include/ruby/backward.h (revision 55394) @@ -17,4 +17,9 @@ ruby_show_copyright_to_die(int exitcode) https://github.com/ruby/ruby/blob/trunk/include/ruby/backward.h#L17 (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 */ Index: include/ruby/ruby.h =================================================================== --- include/ruby/ruby.h (revision 55393) +++ include/ruby/ruby.h (revision 55394) @@ -1502,6 +1502,7 @@ rb_obj_write(VALUE a, VALUE *slot, VALUE https://github.com/ruby/ruby/blob/trunk/include/ruby/ruby.h#L1502 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; https://github.com/ruby/ruby/blob/trunk/include/ruby/ruby.h#L1866 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; https://github.com/ruby/ruby/blob/trunk/include/ruby/ruby.h#L1878 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; Index: ChangeLog =================================================================== --- ChangeLog (revision 55393) +++ ChangeLog (revision 55394) @@ -1,3 +1,14 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Mon Jun 13 20:34:53 2016 Nobuyoshi Nakada <nobu@r...> + + * 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@i...> * test/ruby/enc/test_case_comprehensive.rb: Add tests for full Unicode Index: bignum.c =================================================================== --- bignum.c (revision 55393) +++ bignum.c (revision 55394) @@ -31,7 +31,9 @@ https://github.com/ruby/ruby/blob/trunk/bignum.c#L31 #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) https://github.com/ruby/ruby/blob/trunk/bignum.c#L6785 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); Index: internal.h =================================================================== --- internal.h (revision 55393) +++ internal.h (revision 55394) @@ -780,6 +780,11 @@ struct MEMO { https://github.com/ruby/ruby/blob/trunk/internal.h#L780 #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, -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/