Skip to content

Commit

Permalink
Merge pull request #304 from hsbt/support-to-ruby-2.4
Browse files Browse the repository at this point in the history
Support to Integer unification for Ruby 2.4.
  • Loading branch information
ohler55 committed Jun 20, 2016
2 parents 97bc050 + cc2b7f1 commit af1d4ea
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ext/oj/fast.c
Original file line number Diff line number Diff line change
Expand Up @@ -1281,7 +1281,11 @@ doc_type(int argc, VALUE *argv, VALUE self) {
case T_TRUE: type = rb_cTrueClass; break;
case T_FALSE: type = rb_cFalseClass; break;
case T_STRING: type = rb_cString; break;
#ifdef RUBY_INTEGER_UNIFICATION
case T_FIXNUM: type = rb_cInteger; break;
#else
case T_FIXNUM: type = rb_cFixnum; break;
#endif
case T_FLOAT: type = rb_cFloat; break;
case T_ARRAY: type = rb_cArray; break;
case T_HASH: type = rb_cHash; break;
Expand Down
12 changes: 12 additions & 0 deletions ext/oj/oj.c
Original file line number Diff line number Diff line change
Expand Up @@ -402,9 +402,15 @@ oj_parse_options(VALUE ropts, Options copts) {
if (Qnil != (v = rb_hash_lookup(ropts, float_prec_sym))) {
int n;

#ifdef RUBY_INTEGER_UNIFICATION
if (rb_cInteger != rb_obj_class(v)) {
rb_raise(rb_eArgError, ":float_precision must be a Integer.");
}
#else
if (rb_cFixnum != rb_obj_class(v)) {
rb_raise(rb_eArgError, ":float_precision must be a Fixnum.");
}
#endif
Check_Type(v, T_FIXNUM);
n = FIX2INT(v);
if (0 >= n) {
Expand All @@ -421,9 +427,15 @@ oj_parse_options(VALUE ropts, Options copts) {
if (Qnil != (v = rb_hash_lookup(ropts, sec_prec_sym))) {
int n;

#ifdef RUBY_INTEGER_UNIFICATION
if (rb_cInteger != rb_obj_class(v)) {
rb_raise(rb_eArgError, ":second_precision must be a Integer.");
}
#else
if (rb_cFixnum != rb_obj_class(v)) {
rb_raise(rb_eArgError, ":second_precision must be a Fixnum.");
}
#endif
n = NUM2INT(v);
if (0 > n) {
n = 0;
Expand Down

0 comments on commit af1d4ea

Please sign in to comment.