diff options
author | yugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-05-11 21:23:16 +0000 |
---|---|---|
committer | yugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-05-11 21:23:16 +0000 |
commit | 5d397b488e190b4c3012e1ec146dc6161f7c3952 (patch) | |
tree | c00b0656d5b1ad90971e8c6a60005e0dec90b747 /ext | |
parent | 91799a2fd95ac0e393d950104c5476b4cef616f7 (diff) |
merges r30791 and r30792 from trunk into ruby_1_9_2.
--
* ext/json/parser/parser.h (GET_PARSER): check if initialized.
[ruby-core:35079]
* ext/json/parser/parser.rl (cParser_initialize): ditto.
--
* ext/json/parser/parser.h (GET_PARSER): raise TypeError.
* ext/json/parser/parser.rl (cParser_initialize): ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_2@31508 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r-- | ext/json/parser/parser.c | 16 | ||||
-rw-r--r-- | ext/json/parser/parser.h | 3 | ||||
-rw-r--r-- | ext/json/parser/parser.rl | 6 |
3 files changed, 18 insertions, 7 deletions
diff --git a/ext/json/parser/parser.c b/ext/json/parser/parser.c index cf4bbfa531..42f9bf2285 100644 --- a/ext/json/parser/parser.c +++ b/ext/json/parser/parser.c @@ -1610,7 +1610,11 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self) char *ptr; long len; VALUE source, opts; - GET_PARSER; + GET_PARSER_INIT; + + if (json->Vsource) { + rb_raise(rb_eTypeError, "already initialized instance"); + } rb_scan_args(argc, argv, "11", &source, &opts); source = convert_encoding(StringValue(source)); ptr = RSTRING_PTR(source); @@ -1698,16 +1702,16 @@ static VALUE cParser_parse(VALUE self) GET_PARSER; -#line 1702 "parser.c" +#line 1706 "parser.c" { cs = JSON_start; } -#line 699 "parser.rl" +#line 703 "parser.rl" p = json->source; pe = p + json->len; -#line 1711 "parser.c" +#line 1715 "parser.c" { if ( p == pe ) goto _test_eof; @@ -1784,7 +1788,7 @@ st10: if ( ++p == pe ) goto _test_eof10; case 10: -#line 1788 "parser.c" +#line 1792 "parser.c" switch( (*p) ) { case 13: goto st10; case 32: goto st10; @@ -1841,7 +1845,7 @@ case 9: _out: {} } -#line 702 "parser.rl" +#line 706 "parser.rl" if (cs >= JSON_first_final && p == pe) { return result; diff --git a/ext/json/parser/parser.h b/ext/json/parser/parser.h index 688ffdaeba..a344da058c 100644 --- a/ext/json/parser/parser.h +++ b/ext/json/parser/parser.h @@ -44,6 +44,9 @@ typedef struct JSON_ParserStruct { } JSON_Parser; #define GET_PARSER \ + GET_PARSER_INIT; \ + if (!json->Vsource) rb_raise(rb_eTypeError, "uninitialized instance") +#define GET_PARSER_INIT \ JSON_Parser *json; \ Data_Get_Struct(self, JSON_Parser, json) diff --git a/ext/json/parser/parser.rl b/ext/json/parser/parser.rl index 05b4890366..9fafaedb7e 100644 --- a/ext/json/parser/parser.rl +++ b/ext/json/parser/parser.rl @@ -608,7 +608,11 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self) char *ptr; long len; VALUE source, opts; - GET_PARSER; + GET_PARSER_INIT; + + if (json->Vsource) { + rb_raise(rb_eTypeError, "already initialized instance"); + } rb_scan_args(argc, argv, "11", &source, &opts); source = convert_encoding(StringValue(source)); ptr = RSTRING_PTR(source); |