ext/json/ext/parser/parser.rl in json_pure-2.0.0 vs ext/json/ext/parser/parser.rl in json_pure-2.0.1
- old
+ new
@@ -129,11 +129,11 @@
write data;
action parse_value {
VALUE v = Qnil;
- char *np = JSON_parse_value(json, fpc, pe, &v);
+ char *np = JSON_parse_value(json, fpc, pe, &v, current_nesting);
if (np == NULL) {
fhold; fbreak;
} else {
if (NIL_P(json->object_class)) {
rb_hash_aset(*result, last_name, v);
@@ -162,18 +162,18 @@
(pair (next_pair)*)? ignore*
end_object
) @exit;
}%%
-static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *result)
+static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *result, int current_nesting)
{
int cs = EVIL;
VALUE last_name = Qnil;
VALUE object_class = json->object_class;
- if (json->max_nesting && json->current_nesting > json->max_nesting) {
- rb_raise(eNestingError, "nesting of %d is too deep", json->current_nesting);
+ if (json->max_nesting && current_nesting > json->max_nesting) {
+ rb_raise(eNestingError, "nesting of %d is too deep", current_nesting);
}
*result = NIL_P(object_class) ? rb_hash_new() : rb_class_new_instance(0, 0, object_class);
%% write init;
@@ -253,21 +253,17 @@
fhold; fbreak;
}
action parse_array {
char *np;
- json->current_nesting++;
- np = JSON_parse_array(json, fpc, pe, result);
- json->current_nesting--;
+ np = JSON_parse_array(json, fpc, pe, result, current_nesting + 1);
if (np == NULL) { fhold; fbreak; } else fexec np;
}
action parse_object {
char *np;
- json->current_nesting++;
- np = JSON_parse_object(json, fpc, pe, result);
- json->current_nesting--;
+ np = JSON_parse_object(json, fpc, pe, result, current_nesting + 1);
if (np == NULL) { fhold; fbreak; } else fexec np;
}
action exit { fhold; fbreak; }
@@ -282,11 +278,11 @@
begin_array >parse_array |
begin_object >parse_object
) ignore* %*exit;
}%%
-static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *result)
+static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *result, int current_nesting)
{
int cs = EVIL;
%% write init;
%% write exec;
@@ -369,11 +365,11 @@
write data;
action parse_value {
VALUE v = Qnil;
- char *np = JSON_parse_value(json, fpc, pe, &v);
+ char *np = JSON_parse_value(json, fpc, pe, &v, current_nesting);
if (np == NULL) {
fhold; fbreak;
} else {
if (NIL_P(json->array_class)) {
rb_ary_push(*result, v);
@@ -392,17 +388,17 @@
((begin_value >parse_value ignore*)
(ignore* next_element ignore*)*)?
end_array @exit;
}%%
-static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *result)
+static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *result, int current_nesting)
{
int cs = EVIL;
VALUE array_class = json->array_class;
- if (json->max_nesting && json->current_nesting > json->max_nesting) {
- rb_raise(eNestingError, "nesting of %d is too deep", json->current_nesting);
+ if (json->max_nesting && current_nesting > json->max_nesting) {
+ rb_raise(eNestingError, "nesting of %d is too deep", current_nesting);
}
*result = NIL_P(array_class) ? rb_ary_new() : rb_class_new_instance(0, 0, array_class);
%% write init;
%% write exec;
@@ -694,11 +690,10 @@
json->create_id = rb_funcall(mJSON, i_create_id, 0);
json->object_class = Qnil;
json->array_class = Qnil;
}
source = convert_encoding(StringValue(source));
- json->current_nesting = 0;
StringValue(source);
json->len = RSTRING_LEN(source);
json->source = RSTRING_PTR(source);;
json->Vsource = source;
return self;
@@ -710,10 +705,10 @@
write data;
include JSON_common;
action parse_value {
- char *np = JSON_parse_value(json, fpc, pe, &result);
+ char *np = JSON_parse_value(json, fpc, pe, &result, 0);
if (np == NULL) { fhold; fbreak; } else fexec np;
}
main := ignore* (
begin_value >parse_value