@@ -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,19 @@ 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+ }
349+ else {
350+ return 0;
351+ }
352+ }
353+ return obj == cBigDecimal;
354+ }
355+
342356static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *result)
343357{
344358 int cs = EVIL;
@@ -358,7 +372,11 @@ static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *resul
358372 else {
359373 VALUE text;
360374 text = rb_str_new2(FBUFFER_PTR(json->fbuffer));
361- *result = rb_funcall(json->decimal_class, i_new, 1, text);
375+ if (is_bigdecimal_class(json->decimal_class)) {
376+ *result = rb_funcall(Qnil, i_BigDecimal, 1, text);
377+ } else {
378+ *result = rb_funcall(json->decimal_class, i_new, 1, text);
379+ }
362380 }
363381 return p + 1;
364382 } else {
0 commit comments