summaryrefslogtreecommitdiff
path: root/ext/json/parser/parser.c
diff options
context:
space:
mode:
authormrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-12-02 05:21:57 +0000
committermrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-12-02 05:21:57 +0000
commita7e3516ff1116a15b3ed62f55143eceee27c4ce9 (patch)
tree07d24f899726bcfbf1dbeb5c93236f280b477488 /ext/json/parser/parser.c
parente021386e905b6d6799a84dfbc2f0592e42626366 (diff)
Fix JSON::Parser against bigdecimal updates
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66127 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/json/parser/parser.c')
-rw-r--r--ext/json/parser/parser.c23
1 files changed, 21 insertions, 2 deletions
diff --git a/ext/json/parser/parser.c b/ext/json/parser/parser.c
index c8012796a4..b02aae8fb9 100644
--- a/ext/json/parser/parser.c
+++ b/ext/json/parser/parser.c
@@ -91,12 +91,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;
#line 125 "parser.rl"
@@ -985,6 +986,19 @@ enum {JSON_float_en_main = 1};
#line 340 "parser.rl"
+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;
@@ -1136,7 +1150,11 @@ case 7:
} 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 {
@@ -2101,6 +2119,7 @@ void Init_parser(void)
i_aref = rb_intern("[]");
i_leftshift = rb_intern("<<");
i_new = rb_intern("new");
+ i_BigDecimal = rb_intern("BigDecimal");
}
/*