summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-02-05 01:30:01 +0000
committerNobuyoshi Nakada <nobu@ruby-lang.org>2011-07-07 13:04:12 +0900
commitd2cbd056040a83408629306bc211592cd5cbc8a3 (patch)
tree9957f93fcdbb212d961cfd87b1566327d716b207
parent43bfa8ae5bbbf71b431a6e5838030271b4c621b8 (diff)
downloadjson-d2cbd056040a83408629306bc211592cd5cbc8a3.tar.gz
* ext/json/ext/parser/parser.h (GET_PARSER): check if initialized. [ruby-core:35079]
* ext/json/ext/parser/parser.rl (cParser_initialize): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30791 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ext/json/ext/parser/parser.c17
-rw-r--r--ext/json/ext/parser/parser.h3
-rw-r--r--ext/json/ext/parser/parser.rl7
3 files changed, 20 insertions, 7 deletions
diff --git a/ext/json/ext/parser/parser.c b/ext/json/ext/parser/parser.c
index a635209..d223a86 100644
--- a/ext/json/ext/parser/parser.c
+++ b/ext/json/ext/parser/parser.c
@@ -1642,7 +1642,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_eArgError, "already initialized instance");
+ }
rb_scan_args(argc, argv, "11", &source, &opts);
source = convert_encoding(StringValue(source));
ptr = RSTRING_PTR(source);
@@ -1737,16 +1741,16 @@ static VALUE cParser_parse(VALUE self)
GET_PARSER;
-#line 1741 "parser.c"
+#line 1745 "parser.c"
{
cs = JSON_start;
}
-#line 738 "parser.rl"
+#line 742 "parser.rl"
p = json->source;
pe = p + json->len;
-#line 1750 "parser.c"
+#line 1754 "parser.c"
{
if ( p == pe )
goto _test_eof;
@@ -1823,7 +1827,7 @@ st10:
if ( ++p == pe )
goto _test_eof10;
case 10:
-#line 1827 "parser.c"
+#line 1831 "parser.c"
switch( (*p) ) {
case 13: goto st10;
case 32: goto st10;
@@ -1880,7 +1884,7 @@ case 9:
_out: {}
}
-#line 741 "parser.rl"
+#line 745 "parser.rl"
if (cs >= JSON_first_final && p == pe) {
return result;
@@ -1982,5 +1986,6 @@ void Init_parser()
* Local variables:
* mode: c
* c-file-style: ruby
+ * indent-tabs-mode: nil
* End:
*/
diff --git a/ext/json/ext/parser/parser.h b/ext/json/ext/parser/parser.h
index 66a4f18..904156f 100644
--- a/ext/json/ext/parser/parser.h
+++ b/ext/json/ext/parser/parser.h
@@ -51,6 +51,9 @@ typedef struct JSON_ParserStruct {
} JSON_Parser;
#define GET_PARSER \
+ GET_PARSER_INIT; \
+ if (!json->Vsource) rb_raise(rb_eArgError, "uninitialized instance")
+#define GET_PARSER_INIT \
JSON_Parser *json; \
Data_Get_Struct(self, JSON_Parser, json)
diff --git a/ext/json/ext/parser/parser.rl b/ext/json/ext/parser/parser.rl
index 9e24d44..eb0a6ba 100644
--- a/ext/json/ext/parser/parser.rl
+++ b/ext/json/ext/parser/parser.rl
@@ -640,7 +640,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_eArgError, "already initialized instance");
+ }
rb_scan_args(argc, argv, "11", &source, &opts);
source = convert_encoding(StringValue(source));
ptr = RSTRING_PTR(source);
@@ -839,5 +843,6 @@ void Init_parser()
* Local variables:
* mode: c
* c-file-style: ruby
+ * indent-tabs-mode: nil
* End:
*/