diff options
author | Florian Frank <flori@ping.de> | 2019-04-29 16:02:22 +0200 |
---|---|---|
committer | Florian Frank <flori@ping.de> | 2019-04-29 16:02:22 +0200 |
commit | 6d12fee7d7c8180da188c02a306f40d96d0edbe2 (patch) | |
tree | bb74535cdbef58118ee8eb3c5f781d746575ad17 /ext/json/ext/parser/parser.rl | |
parent | 91a24ecac3d722bc3e545fdd0657ed225e91c2df (diff) | |
parent | 463473c6c37b3a14fde4c2d21403d6dc8500c185 (diff) | |
download | json-6d12fee7d7c8180da188c02a306f40d96d0edbe2.tar.gz |
Merge branch 'master' of github.com:flori/json
Diffstat (limited to 'ext/json/ext/parser/parser.rl')
-rw-r--r-- | ext/json/ext/parser/parser.rl | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/ext/json/ext/parser/parser.rl b/ext/json/ext/parser/parser.rl index 4c84865..e7738d6 100644 --- a/ext/json/ext/parser/parser.rl +++ b/ext/json/ext/parser/parser.rl @@ -89,12 +89,13 @@ static int convert_UTF32_to_UTF8(char *buf, UTF32 ch) static VALUE mJSON, mExt, cParser, eParserError, eNestingError; static VALUE CNaN, CInfinity, CMinusInfinity; +static VALUE cBigDecimal = Qundef; static ID i_json_creatable_p, i_json_create, i_create_id, i_create_additions, i_chr, i_max_nesting, i_allow_nan, i_symbolize_names, i_object_class, i_array_class, i_decimal_class, i_key_p, i_deep_const_get, i_match, i_match_string, i_aset, i_aref, - i_leftshift, i_new; + i_leftshift, i_new, i_BigDecimal; %%{ machine JSON_common; @@ -339,6 +340,19 @@ static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *res ) (^[0-9Ee.\-]? @exit ); }%% +static int is_bigdecimal_class(VALUE obj) +{ + if (cBigDecimal == Qundef) { + if (rb_const_defined(rb_cObject, i_BigDecimal)) { + cBigDecimal = rb_const_get_at(rb_cObject, i_BigDecimal); + } + else { + return 0; + } + } + return obj == cBigDecimal; +} + static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *result) { int cs = EVIL; @@ -357,7 +371,11 @@ static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *resul } else { VALUE text; text = rb_str_new2(FBUFFER_PTR(json->fbuffer)); - *result = rb_funcall(json->decimal_class, i_new, 1, text); + if (is_bigdecimal_class(json->decimal_class)) { + *result = rb_funcall(Qnil, i_BigDecimal, 1, text); + } else { + *result = rb_funcall(json->decimal_class, i_new, 1, text); + } } return p + 1; } else { @@ -824,6 +842,7 @@ static VALUE cParser_source(VALUE self) void Init_parser(void) { +#undef rb_intern rb_require("json/common"); mJSON = rb_define_module("JSON"); mExt = rb_define_module_under(mJSON, "Ext"); @@ -858,6 +877,7 @@ void Init_parser(void) i_aref = rb_intern("[]"); i_leftshift = rb_intern("<<"); i_new = rb_intern("new"); + i_BigDecimal = rb_intern("BigDecimal"); } /* |