summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/json/ext/generator/generator.c7
-rw-r--r--ext/json/ext/parser/parser.c120
-rw-r--r--ext/json/ext/parser/parser.h19
-rw-r--r--ext/json/ext/parser/parser.rl92
-rw-r--r--json-java.gemspec1
5 files changed, 136 insertions, 103 deletions
diff --git a/ext/json/ext/generator/generator.c b/ext/json/ext/generator/generator.c
index 4e44178..8ea0a63 100644
--- a/ext/json/ext/generator/generator.c
+++ b/ext/json/ext/generator/generator.c
@@ -1022,6 +1022,13 @@ static VALUE cState_init_copy(VALUE obj, VALUE orig)
return obj;
}
+#if defined(MAGLEV)
+static int rb_obj_is_kind_of(VALUE obj, VALUE klass)
+{
+ return rb_obj_is_kind_of_(obj, klass);
+}
+#endif
+
/*
* call-seq: from_state(opts)
*
diff --git a/ext/json/ext/parser/parser.c b/ext/json/ext/parser/parser.c
index af57b81..b28a6fc 100644
--- a/ext/json/ext/parser/parser.c
+++ b/ext/json/ext/parser/parser.c
@@ -97,7 +97,7 @@ static const int JSON_object_en_main = 1;
#line 148 "parser.rl"
-static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *result)
+static const char *JSON_parse_object(JSON_Parser *json, const char *p, const char *pe, VALUE *result)
{
int cs = EVIL;
VALUE last_name = Qnil;
@@ -147,7 +147,7 @@ case 2:
tr2:
#line 131 "parser.rl"
{
- char *np;
+ const char *np;
json->parsing_name = 1;
np = JSON_parse_string(json, p, pe, &last_name);
json->parsing_name = 0;
@@ -228,7 +228,7 @@ tr11:
#line 116 "parser.rl"
{
VALUE v = Qnil;
- char *np = JSON_parse_value(json, p, pe, &v);
+ const char *np = JSON_parse_value(json, p, pe, &v);
if (np == NULL) {
p--; {p++; cs = 9; goto _out;}
} else {
@@ -469,7 +469,7 @@ static const int JSON_value_en_main = 1;
#line 262 "parser.rl"
-static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *result)
+static const char *JSON_parse_value(JSON_Parser *json, const char *p, const char *pe, VALUE *result)
{
int cs = EVIL;
@@ -508,14 +508,14 @@ cs = 0;
tr0:
#line 210 "parser.rl"
{
- char *np = JSON_parse_string(json, p, pe, result);
+ const char *np = JSON_parse_string(json, p, pe, result);
if (np == NULL) { p--; {p++; cs = 21; goto _out;} } else {p = (( np))-1;}
}
goto st21;
tr2:
#line 215 "parser.rl"
{
- char *np;
+ const char *np;
if(pe > p + 9 && !strncmp(MinusInfinity, p, 9)) {
if (json->allow_nan) {
*result = CMinusInfinity;
@@ -535,7 +535,7 @@ tr2:
tr5:
#line 233 "parser.rl"
{
- char *np;
+ const char *np;
json->current_nesting++;
np = JSON_parse_array(json, p, pe, result);
json->current_nesting--;
@@ -545,7 +545,7 @@ tr5:
tr9:
#line 241 "parser.rl"
{
- char *np;
+ const char *np;
json->current_nesting++;
np = JSON_parse_object(json, p, pe, result);
json->current_nesting--;
@@ -778,7 +778,7 @@ static const int JSON_integer_en_main = 1;
#line 286 "parser.rl"
-static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *result)
+static const char *JSON_parse_integer(JSON_Parser *json, const char *p, const char *pe, VALUE *result)
{
int cs = EVIL;
@@ -874,7 +874,7 @@ static const int JSON_float_en_main = 1;
#line 317 "parser.rl"
-static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *result)
+static const char *JSON_parse_float(JSON_Parser *json, const char *p, const char *pe, VALUE *result)
{
int cs = EVIL;
@@ -1037,7 +1037,7 @@ static const int JSON_array_en_main = 1;
#line 366 "parser.rl"
-static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *result)
+static const char *JSON_parse_array(JSON_Parser *json, const char *p, const char *pe, VALUE *result)
{
int cs = EVIL;
VALUE array_class = json->array_class;
@@ -1097,7 +1097,7 @@ tr2:
#line 343 "parser.rl"
{
VALUE v = Qnil;
- char *np = JSON_parse_value(json, p, pe, &v);
+ const char *np = JSON_parse_value(json, p, pe, &v);
if (np == NULL) {
p--; {p++; cs = 3; goto _out;}
} else {
@@ -1287,9 +1287,9 @@ case 16:
}
}
-static VALUE json_string_unescape(VALUE result, char *string, char *stringEnd)
+static VALUE json_string_unescape(VALUE result, const char *string, const char *stringEnd)
{
- char *p = string, *pe = string, *unescape;
+ const char *p = string, *pe = string, *unescape;
int unescape_len;
while (pe < stringEnd) {
@@ -1381,22 +1381,20 @@ match_i(VALUE regexp, VALUE klass, VALUE memo)
return ST_CONTINUE;
}
-static char *JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *result)
+static const char *JSON_parse_string(JSON_Parser *json, const char *p, const char *pe, VALUE *result)
{
int cs = EVIL;
- VALUE match_string;
-
*result = rb_str_buf_new(0);
-#line 1392 "parser.c"
+#line 1390 "parser.c"
{
cs = JSON_string_start;
}
-#line 500 "parser.rl"
+#line 498 "parser.rl"
json->memo = p;
-#line 1400 "parser.c"
+#line 1398 "parser.c"
{
if ( p == pe )
goto _test_eof;
@@ -1439,7 +1437,7 @@ st8:
if ( ++p == pe )
goto _test_eof8;
case 8:
-#line 1443 "parser.c"
+#line 1441 "parser.c"
goto st0;
st3:
if ( ++p == pe )
@@ -1515,9 +1513,11 @@ case 7:
_out: {}
}
-#line 502 "parser.rl"
+#line 500 "parser.rl"
- if (json->create_additions && RTEST(match_string = json->match_string)) {
+ if (json->create_additions) {
+ VALUE match_string = json->match_string;
+ if (RTEST(match_string)) {
VALUE klass;
VALUE memo = rb_ary_new2(2);
rb_ary_push(memo, *result);
@@ -1526,6 +1526,7 @@ case 7:
if (RTEST(klass)) {
*result = rb_funcall(klass, i_json_create, 1, *result);
}
+ }
}
if (json->symbolize_names && json->parsing_name) {
@@ -1540,7 +1541,7 @@ case 7:
-#line 1544 "parser.c"
+#line 1545 "parser.c"
static const int JSON_start = 1;
static const int JSON_first_final = 10;
static const int JSON_error = 0;
@@ -1548,7 +1549,7 @@ static const int JSON_error = 0;
static const int JSON_en_main = 1;
-#line 550 "parser.rl"
+#line 551 "parser.rl"
/*
@@ -1565,7 +1566,7 @@ static const int JSON_en_main = 1;
static VALUE convert_encoding(VALUE source)
{
- char *ptr = RSTRING_PTR(source);
+ const char *ptr = RSTRING_PTR(source);
long len = RSTRING_LEN(source);
if (len < 2) {
rb_raise(eParserError, "A JSON text must at least contain two octets!");
@@ -1604,6 +1605,13 @@ static VALUE convert_encoding(VALUE source)
return source;
}
+static inline void parser_iv_set(JSON_Parser *json, const char* iv_name, VALUE v)
+{
+ // store reference to v in a Ruby instVar to keep v alive
+ // without using a gc_mark function in Data_Wrap_Struct calls
+ rb_iv_set(json->dwrapped_parser, iv_name, v);
+}
+
/*
* call-seq: new(source, opts => {})
*
@@ -1630,12 +1638,16 @@ static VALUE convert_encoding(VALUE source)
* * *object_class*: Defaults to Hash
* * *array_class*: Defaults to Array
*/
+
+static int init_count = 0;
static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
{
- char *ptr;
+ const char *ptr;
long len;
VALUE source, opts;
+
GET_PARSER_INIT;
+ init_count += 1;
if (json->Vsource) {
rb_raise(rb_eTypeError, "already initialized instance");
@@ -1685,24 +1697,22 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
} else {
json->create_id = rb_funcall(mJSON, i_create_id, 0);
}
+ parser_iv_set(json, "@create_id", json->create_id);
tmp = ID2SYM(i_object_class);
if (option_given_p(opts, tmp)) {
json->object_class = rb_hash_aref(opts, tmp);
- } else {
- json->object_class = Qnil;
+ parser_iv_set(json, "@object_class", json->object_class);
}
tmp = ID2SYM(i_array_class);
if (option_given_p(opts, tmp)) {
json->array_class = rb_hash_aref(opts, tmp);
- } else {
- json->array_class = Qnil;
+ parser_iv_set(json, "@array_class", json->array_class);
}
tmp = ID2SYM(i_match_string);
if (option_given_p(opts, tmp)) {
VALUE match_string = rb_hash_aref(opts, tmp);
json->match_string = RTEST(match_string) ? match_string : Qnil;
- } else {
- json->match_string = Qnil;
+ parser_iv_set(json, "@match_string", json->match_string);
}
}
} else {
@@ -1710,13 +1720,13 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
json->allow_nan = 0;
json->create_additions = 1;
json->create_id = rb_funcall(mJSON, i_create_id, 0);
- json->object_class = Qnil;
- json->array_class = Qnil;
+ parser_iv_set(json, "@create_id", json->create_id);
}
json->current_nesting = 0;
json->len = len;
json->source = ptr;
json->Vsource = source;
+ parser_iv_set(json, "@vsource", json->Vsource);
return self;
}
@@ -1728,22 +1738,22 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
*/
static VALUE cParser_parse(VALUE self)
{
- char *p, *pe;
+ const char *p, *pe;
int cs = EVIL;
VALUE result = Qnil;
GET_PARSER;
-#line 1738 "parser.c"
+#line 1748 "parser.c"
{
cs = JSON_start;
}
-#line 735 "parser.rl"
+#line 745 "parser.rl"
p = json->source;
pe = p + json->len;
-#line 1747 "parser.c"
+#line 1757 "parser.c"
{
if ( p == pe )
goto _test_eof;
@@ -1799,18 +1809,18 @@ case 5:
goto st1;
goto st5;
tr3:
-#line 539 "parser.rl"
+#line 540 "parser.rl"
{
- char *np;
+ const char *np;
json->current_nesting = 1;
np = JSON_parse_array(json, p, pe, &result);
if (np == NULL) { p--; {p++; cs = 10; goto _out;} } else {p = (( np))-1;}
}
goto st10;
tr4:
-#line 532 "parser.rl"
+#line 533 "parser.rl"
{
- char *np;
+ const char *np;
json->current_nesting = 1;
np = JSON_parse_object(json, p, pe, &result);
if (np == NULL) { p--; {p++; cs = 10; goto _out;} } else {p = (( np))-1;}
@@ -1820,7 +1830,7 @@ st10:
if ( ++p == pe )
goto _test_eof10;
case 10:
-#line 1824 "parser.c"
+#line 1834 "parser.c"
switch( (*p) ) {
case 13: goto st10;
case 32: goto st10;
@@ -1877,7 +1887,7 @@ case 9:
_out: {}
}
-#line 738 "parser.rl"
+#line 748 "parser.rl"
if (cs >= JSON_first_final && p == pe) {
return result;
@@ -1891,17 +1901,17 @@ static JSON_Parser *JSON_allocate()
{
JSON_Parser *json = ALLOC(JSON_Parser);
MEMZERO(json, JSON_Parser, 1);
+ json->dwrapped_parser = Qnil;
+ json->Vsource = Qnil;
+ json->create_id = Qnil;
+ json->object_class = Qnil;
+ json->array_class = Qnil;
+ json->match_string = Qnil;
+
return json;
}
-static void JSON_mark(JSON_Parser *json)
-{
- rb_gc_mark_maybe(json->Vsource);
- rb_gc_mark_maybe(json->create_id);
- rb_gc_mark_maybe(json->object_class);
- rb_gc_mark_maybe(json->array_class);
- rb_gc_mark_maybe(json->match_string);
-}
+/* deleted JSON_mark function */
static void JSON_free(JSON_Parser *json)
{
@@ -1911,7 +1921,9 @@ static void JSON_free(JSON_Parser *json)
static VALUE cJSON_parser_s_allocate(VALUE klass)
{
JSON_Parser *json = JSON_allocate();
- return Data_Wrap_Struct(klass, JSON_mark, JSON_free, json);
+ VALUE data_obj = Data_Wrap_Struct(klass, NULL, JSON_free, json);
+ json->dwrapped_parser = data_obj;
+ return data_obj;
}
/*
diff --git a/ext/json/ext/parser/parser.h b/ext/json/ext/parser/parser.h
index f2ce5a4..5571787 100644
--- a/ext/json/ext/parser/parser.h
+++ b/ext/json/ext/parser/parser.h
@@ -34,10 +34,11 @@ typedef unsigned char UTF8; /* typically 8 bits */
#define UNI_SUR_LOW_END (UTF32)0xDFFF
typedef struct JSON_ParserStruct {
+ VALUE dwrapped_parser;
VALUE Vsource;
- char *source;
+ const char *source;
long len;
- char *memo;
+ const char *memo;
VALUE create_id;
int max_nesting;
int current_nesting;
@@ -62,13 +63,13 @@ typedef struct JSON_ParserStruct {
static UTF32 unescape_unicode(const unsigned char *p);
static int convert_UTF32_to_UTF8(char *buf, UTF32 ch);
-static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *result);
-static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *result);
-static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *result);
-static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *result);
-static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *result);
-static VALUE json_string_unescape(VALUE result, char *string, char *stringEnd);
-static char *JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *result);
+static const char *JSON_parse_object(JSON_Parser *json, const char *p, const char *pe, VALUE *result);
+static const char *JSON_parse_value(JSON_Parser *json, const char *p, const char *pe, VALUE *result);
+static const char *JSON_parse_integer(JSON_Parser *json, const char *p, const char *pe, VALUE *result);
+static const char *JSON_parse_float(JSON_Parser *json, const char *p, const char *pe, VALUE *result);
+static const char *JSON_parse_array(JSON_Parser *json, const char *p, const char *pe, VALUE *result);
+static VALUE json_string_unescape(VALUE result, const char *string, const char *stringEnd);
+static const char *JSON_parse_string(JSON_Parser *json, const char *p, const char *pe, VALUE *result);
static VALUE convert_encoding(VALUE source);
static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self);
static VALUE cParser_parse(VALUE self);
diff --git a/ext/json/ext/parser/parser.rl b/ext/json/ext/parser/parser.rl
index 21b445e..fad8ac7 100644
--- a/ext/json/ext/parser/parser.rl
+++ b/ext/json/ext/parser/parser.rl
@@ -115,7 +115,7 @@ static ID i_json_creatable_p, i_json_create, i_create_id, i_create_additions,
action parse_value {
VALUE v = Qnil;
- char *np = JSON_parse_value(json, fpc, pe, &v);
+ const char *np = JSON_parse_value(json, fpc, pe, &v);
if (np == NULL) {
fhold; fbreak;
} else {
@@ -129,7 +129,7 @@ static ID i_json_creatable_p, i_json_create, i_create_id, i_create_additions,
}
action parse_name {
- char *np;
+ const char *np;
json->parsing_name = 1;
np = JSON_parse_string(json, fpc, pe, &last_name);
json->parsing_name = 0;
@@ -147,7 +147,7 @@ static ID i_json_creatable_p, i_json_create, i_create_id, i_create_additions,
ignore* end_object @exit;
}%%
-static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *result)
+static const char *JSON_parse_object(JSON_Parser *json, const char *p, const char *pe, VALUE *result)
{
int cs = EVIL;
VALUE last_name = Qnil;
@@ -208,12 +208,12 @@ static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *resu
}
}
action parse_string {
- char *np = JSON_parse_string(json, fpc, pe, result);
+ const char *np = JSON_parse_string(json, fpc, pe, result);
if (np == NULL) { fhold; fbreak; } else fexec np;
}
action parse_number {
- char *np;
+ const char *np;
if(pe > fpc + 9 && !strncmp(MinusInfinity, fpc, 9)) {
if (json->allow_nan) {
*result = CMinusInfinity;
@@ -231,7 +231,7 @@ static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *resu
}
action parse_array {
- char *np;
+ const char *np;
json->current_nesting++;
np = JSON_parse_array(json, fpc, pe, result);
json->current_nesting--;
@@ -239,7 +239,7 @@ static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *resu
}
action parse_object {
- char *np;
+ const char *np;
json->current_nesting++;
np = JSON_parse_object(json, fpc, pe, result);
json->current_nesting--;
@@ -261,7 +261,7 @@ main := (
) %*exit;
}%%
-static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *result)
+static const char *JSON_parse_value(JSON_Parser *json, const char *p, const char *pe, VALUE *result)
{
int cs = EVIL;
@@ -285,7 +285,7 @@ static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *resul
main := '-'? ('0' | [1-9][0-9]*) (^[0-9] @exit);
}%%
-static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *result)
+static const char *JSON_parse_integer(JSON_Parser *json, const char *p, const char *pe, VALUE *result)
{
int cs = EVIL;
@@ -316,7 +316,7 @@ static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *res
) (^[0-9Ee.\-] @exit );
}%%
-static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *result)
+static const char *JSON_parse_float(JSON_Parser *json, const char *p, const char *pe, VALUE *result)
{
int cs = EVIL;
@@ -342,7 +342,7 @@ static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *resul
action parse_value {
VALUE v = Qnil;
- char *np = JSON_parse_value(json, fpc, pe, &v);
+ const char *np = JSON_parse_value(json, fpc, pe, &v);
if (np == NULL) {
fhold; fbreak;
} else {
@@ -365,7 +365,7 @@ static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *resul
end_array @exit;
}%%
-static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *result)
+static const char *JSON_parse_array(JSON_Parser *json, const char *p, const char *pe, VALUE *result)
{
int cs = EVIL;
VALUE array_class = json->array_class;
@@ -386,9 +386,9 @@ static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *resul
}
}
-static VALUE json_string_unescape(VALUE result, char *string, char *stringEnd)
+static VALUE json_string_unescape(VALUE result, const char *string, const char *stringEnd)
{
- char *p = string, *pe = string, *unescape;
+ const char *p = string, *pe = string, *unescape;
int unescape_len;
while (pe < stringEnd) {
@@ -490,17 +490,17 @@ match_i(VALUE regexp, VALUE klass, VALUE memo)
return ST_CONTINUE;
}
-static char *JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *result)
+static const char *JSON_parse_string(JSON_Parser *json, const char *p, const char *pe, VALUE *result)
{
int cs = EVIL;
- VALUE match_string;
-
*result = rb_str_buf_new(0);
%% write init;
json->memo = p;
%% write exec;
- if (json->create_additions && RTEST(match_string = json->match_string)) {
+ if (json->create_additions) {
+ VALUE match_string = json->match_string;
+ if (RTEST(match_string)) {
VALUE klass;
VALUE memo = rb_ary_new2(2);
rb_ary_push(memo, *result);
@@ -509,6 +509,7 @@ static char *JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *resu
if (RTEST(klass)) {
*result = rb_funcall(klass, i_json_create, 1, *result);
}
+ }
}
if (json->symbolize_names && json->parsing_name) {
@@ -530,14 +531,14 @@ static char *JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *resu
include JSON_common;
action parse_object {
- char *np;
+ const char *np;
json->current_nesting = 1;
np = JSON_parse_object(json, fpc, pe, &result);
if (np == NULL) { fhold; fbreak; } else fexec np;
}
action parse_array {
- char *np;
+ const char *np;
json->current_nesting = 1;
np = JSON_parse_array(json, fpc, pe, &result);
if (np == NULL) { fhold; fbreak; } else fexec np;
@@ -563,7 +564,7 @@ static char *JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *resu
static VALUE convert_encoding(VALUE source)
{
- char *ptr = RSTRING_PTR(source);
+ const char *ptr = RSTRING_PTR(source);
long len = RSTRING_LEN(source);
if (len < 2) {
rb_raise(eParserError, "A JSON text must at least contain two octets!");
@@ -602,6 +603,13 @@ static VALUE convert_encoding(VALUE source)
return source;
}
+static inline void parser_iv_set(JSON_Parser *json, const char* iv_name, VALUE v)
+{
+ // store reference to v in a Ruby instVar to keep v alive
+ // without using a gc_mark function in Data_Wrap_Struct calls
+ rb_iv_set(json->dwrapped_parser, iv_name, v);
+}
+
/*
* call-seq: new(source, opts => {})
*
@@ -628,12 +636,16 @@ static VALUE convert_encoding(VALUE source)
* * *object_class*: Defaults to Hash
* * *array_class*: Defaults to Array
*/
+
+static int init_count = 0;
static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
{
- char *ptr;
+ const char *ptr;
long len;
VALUE source, opts;
+
GET_PARSER_INIT;
+ init_count += 1;
if (json->Vsource) {
rb_raise(rb_eTypeError, "already initialized instance");
@@ -683,24 +695,22 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
} else {
json->create_id = rb_funcall(mJSON, i_create_id, 0);
}
+ parser_iv_set(json, "@create_id", json->create_id);
tmp = ID2SYM(i_object_class);
if (option_given_p(opts, tmp)) {
json->object_class = rb_hash_aref(opts, tmp);
- } else {
- json->object_class = Qnil;
+ parser_iv_set(json, "@object_class", json->object_class);
}
tmp = ID2SYM(i_array_class);
if (option_given_p(opts, tmp)) {
json->array_class = rb_hash_aref(opts, tmp);
- } else {
- json->array_class = Qnil;
+ parser_iv_set(json, "@array_class", json->array_class);
}
tmp = ID2SYM(i_match_string);
if (option_given_p(opts, tmp)) {
VALUE match_string = rb_hash_aref(opts, tmp);
json->match_string = RTEST(match_string) ? match_string : Qnil;
- } else {
- json->match_string = Qnil;
+ parser_iv_set(json, "@match_string", json->match_string);
}
}
} else {
@@ -708,13 +718,13 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
json->allow_nan = 0;
json->create_additions = 1;
json->create_id = rb_funcall(mJSON, i_create_id, 0);
- json->object_class = Qnil;
- json->array_class = Qnil;
+ parser_iv_set(json, "@create_id", json->create_id);
}
json->current_nesting = 0;
json->len = len;
json->source = ptr;
json->Vsource = source;
+ parser_iv_set(json, "@vsource", json->Vsource);
return self;
}
@@ -726,7 +736,7 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
*/
static VALUE cParser_parse(VALUE self)
{
- char *p, *pe;
+ const char *p, *pe;
int cs = EVIL;
VALUE result = Qnil;
GET_PARSER;
@@ -748,17 +758,17 @@ static JSON_Parser *JSON_allocate()
{
JSON_Parser *json = ALLOC(JSON_Parser);
MEMZERO(json, JSON_Parser, 1);
+ json->dwrapped_parser = Qnil;
+ json->Vsource = Qnil;
+ json->create_id = Qnil;
+ json->object_class = Qnil;
+ json->array_class = Qnil;
+ json->match_string = Qnil;
+
return json;
}
-static void JSON_mark(JSON_Parser *json)
-{
- rb_gc_mark_maybe(json->Vsource);
- rb_gc_mark_maybe(json->create_id);
- rb_gc_mark_maybe(json->object_class);
- rb_gc_mark_maybe(json->array_class);
- rb_gc_mark_maybe(json->match_string);
-}
+/* deleted JSON_mark function */
static void JSON_free(JSON_Parser *json)
{
@@ -768,7 +778,9 @@ static void JSON_free(JSON_Parser *json)
static VALUE cJSON_parser_s_allocate(VALUE klass)
{
JSON_Parser *json = JSON_allocate();
- return Data_Wrap_Struct(klass, JSON_mark, JSON_free, json);
+ VALUE data_obj = Data_Wrap_Struct(klass, NULL, JSON_free, json);
+ json->dwrapped_parser = data_obj;
+ return data_obj;
}
/*
diff --git a/json-java.gemspec b/json-java.gemspec
index 422efec..35bfdf3 100644
--- a/json-java.gemspec
+++ b/json-java.gemspec
@@ -20,3 +20,4 @@ if $0 == __FILE__
else
spec
end
+spec