@@ -89,12 +89,13 @@ static int convert_UTF32_to_UTF8(char *buf, UTF32 ch)
8989
9090static VALUE mJSON, mExt, cParser, eParserError, eNestingError;
9191static VALUE CNaN, CInfinity, CMinusInfinity;
92+ static VALUE cBigDecimal = Qundef;
9293
9394static ID i_json_creatable_p, i_json_create, i_create_id, i_create_additions,
9495 i_chr, i_max_nesting, i_allow_nan, i_symbolize_names,
9596 i_object_class, i_array_class, i_decimal_class, i_key_p,
9697 i_deep_const_get, i_match, i_match_string, i_aset, i_aref,
97- i_leftshift, i_new;
98+ i_leftshift, i_new, i_BigDecimal ;
9899
99100%%{
100101 machine JSON_common;
@@ -339,6 +340,18 @@ static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *res
339340 ) (^[0-9Ee.\-]? @exit );
340341}%%
341342
343+ static int is_bigdecimal_class(VALUE obj)
344+ {
345+ if (cBigDecimal == Qundef) {
346+ if (rb_const_defined(rb_cObject, i_BigDecimal)) {
347+ cBigDecimal = rb_const_get_at(rb_cObject, i_BigDecimal);
348+ } else {
349+ return 0;
350+ }
351+ }
352+ return obj == cBigDecimal;
353+ }
354+
342355static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *result)
343356{
344357 int cs = EVIL;
@@ -357,7 +370,11 @@ static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *resul
357370 } else {
358371 VALUE text;
359372 text = rb_str_new2(FBUFFER_PTR(json->fbuffer));
360- *result = rb_funcall(json->decimal_class, i_new, 1, text);
373+ if (is_bigdecimal_class(json->decimal_class)) {
374+ *result = rb_funcall(Qnil, i_BigDecimal, 1, text);
375+ } else {
376+ *result = rb_funcall(json->decimal_class, i_new, 1, text);
377+ }
361378 }
362379 return p + 1;
363380 } else {
0 commit comments