summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Frank <flori@ping.de>2010-03-20 22:49:44 +0100
committerFlorian Frank <flori@ping.de>2010-03-20 22:49:44 +0100
commitca292f9a9ba00cc6c5982015abeec8f1bb00eb90 (patch)
treea87fbe6e31d306a1a49add853ee96747bb2218e9
parentc3e8dd92f04b010366e4d7152c83c7486af93e1e (diff)
downloadjson-ca292f9a9ba00cc6c5982015abeec8f1bb00eb90.tar.gz
does compile now, but causes a crash
-rw-r--r--ext/json/ext/generator.c13
-rw-r--r--ext/json/ext/parser.c38
-rw-r--r--ext/json/ext/parser.rl2
3 files changed, 32 insertions, 21 deletions
diff --git a/ext/json/ext/generator.c b/ext/json/ext/generator.c
index d9da01e..452d3fc 100644
--- a/ext/json/ext/generator.c
+++ b/ext/json/ext/generator.c
@@ -13,7 +13,7 @@ static VALUE mJSON, mExt, mGenerator, cState, mGeneratorMethods, mObject,
static ID i_to_s, i_to_json, i_new, i_indent, i_space, i_space_before,
i_object_nl, i_array_nl, i_max_nesting, i_allow_nan, i_ascii_only,
i_pack, i_unpack, i_create_id, i_extend, i_key_p, i_aref, i_send,
- i_respond_to_p;
+ i_respond_to_p, i_match;
/*
* Copyright 2001-2004 Unicode, Inc.
@@ -728,6 +728,7 @@ static VALUE cState_aref(VALUE self, VALUE name)
}
}
+#if 0
/*
* The fbuffer2rstring breaks encapsulation of Ruby's String datatype to avoid
* calling memcpy while creating a RString from a c string. This is rather
@@ -772,6 +773,11 @@ static VALUE fbuffer2rstring(FBuffer *buffer)
return (VALUE) str;
}
#endif
+#endif
+static VALUE fbuffer2rstring(FBuffer *buffer)
+{
+ return rb_str_new(FBUFFER_PAIR(buffer));
+}
static void generate_json(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj, long depth)
{
@@ -889,7 +895,7 @@ static void generate_json(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *s
fbuffer_append_integer(buffer, FIX2INT(obj));
break;
case T_BIGNUM:
- tmp = rb_big2str0(obj, 10, 1);
+ tmp = rb_funcall(obj, i_to_s, 0);
fbuffer_append(buffer, RSTRING_PAIR(tmp));
break;
case T_FLOAT:
@@ -978,7 +984,7 @@ static VALUE cState_generate(VALUE self, VALUE obj)
args[0] = rb_str_new2("\\A\\s*(?:\\[.*\\]|\\{.*\\})\\s*\\Z");
args[1] = CRegexp_MULTILINE;
re = rb_class_new_instance(2, args, rb_cRegexp);
- if (NIL_P(rb_reg_match(re, result))) {
+ if (NIL_P(rb_funcall(re, i_match, 1, result))) {
rb_raise(eGeneratorError, "only generation of JSON objects or arrays allowed");
}
return result;
@@ -1369,6 +1375,7 @@ void Init_generator()
i_aref = rb_intern("[]");
i_send = rb_intern("__send__");
i_respond_to_p = rb_intern("respond_to?");
+ i_match = rb_intern("match");
#ifdef HAVE_RUBY_ENCODING_H
CEncoding_UTF_8 = rb_funcall(rb_path2class("Encoding"), rb_intern("find"), 1, rb_str_new2("utf-8"));
i_encoding = rb_intern("encoding");
diff --git a/ext/json/ext/parser.c b/ext/json/ext/parser.c
index 2272fa2..242eb8a 100644
--- a/ext/json/ext/parser.c
+++ b/ext/json/ext/parser.c
@@ -1274,6 +1274,7 @@ case 16:
return p + 1;
} else {
rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p);
+ return NULL;
}
}
@@ -1348,7 +1349,7 @@ static VALUE json_string_unescape(VALUE result, char *string, char *stringEnd)
}
-#line 1352 "parser.c"
+#line 1353 "parser.c"
static const int JSON_string_start = 1;
static const int JSON_string_first_final = 8;
static const int JSON_string_error = 0;
@@ -1356,7 +1357,7 @@ static const int JSON_string_error = 0;
static const int JSON_string_en_main = 1;
-#line 469 "parser.rl"
+#line 470 "parser.rl"
static char *JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *result)
@@ -1365,15 +1366,15 @@ static char *JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *resu
*result = rb_str_buf_new(0);
-#line 1369 "parser.c"
+#line 1370 "parser.c"
{
cs = JSON_string_start;
}
-#line 477 "parser.rl"
+#line 478 "parser.rl"
json->memo = p;
-#line 1377 "parser.c"
+#line 1378 "parser.c"
{
if ( p == pe )
goto _test_eof;
@@ -1398,7 +1399,7 @@ case 2:
goto st0;
goto st2;
tr2:
-#line 455 "parser.rl"
+#line 456 "parser.rl"
{
*result = json_string_unescape(*result, json->memo + 1, p);
if (NIL_P(*result)) {
@@ -1409,14 +1410,14 @@ tr2:
{p = (( p + 1))-1;}
}
}
-#line 466 "parser.rl"
+#line 467 "parser.rl"
{ p--; {p++; cs = 8; goto _out;} }
goto st8;
st8:
if ( ++p == pe )
goto _test_eof8;
case 8:
-#line 1420 "parser.c"
+#line 1421 "parser.c"
goto st0;
st3:
if ( ++p == pe )
@@ -1492,7 +1493,7 @@ case 7:
_out: {}
}
-#line 479 "parser.rl"
+#line 480 "parser.rl"
if (json->symbolize_names && json->parsing_name) {
*result = rb_str_intern(*result);
@@ -1506,7 +1507,7 @@ case 7:
-#line 1510 "parser.c"
+#line 1511 "parser.c"
static const int JSON_start = 1;
static const int JSON_first_final = 10;
static const int JSON_error = 0;
@@ -1514,7 +1515,7 @@ static const int JSON_error = 0;
static const int JSON_en_main = 1;
-#line 516 "parser.rl"
+#line 517 "parser.rl"
/*
@@ -1696,16 +1697,16 @@ static VALUE cParser_parse(VALUE self)
GET_PARSER;
-#line 1700 "parser.c"
+#line 1701 "parser.c"
{
cs = JSON_start;
}
-#line 697 "parser.rl"
+#line 698 "parser.rl"
p = json->source;
pe = p + json->len;
-#line 1709 "parser.c"
+#line 1710 "parser.c"
{
if ( p == pe )
goto _test_eof;
@@ -1761,7 +1762,7 @@ case 5:
goto st1;
goto st5;
tr3:
-#line 505 "parser.rl"
+#line 506 "parser.rl"
{
char *np;
json->current_nesting = 1;
@@ -1770,7 +1771,7 @@ tr3:
}
goto st10;
tr4:
-#line 498 "parser.rl"
+#line 499 "parser.rl"
{
char *np;
json->current_nesting = 1;
@@ -1782,7 +1783,7 @@ st10:
if ( ++p == pe )
goto _test_eof10;
case 10:
-#line 1786 "parser.c"
+#line 1787 "parser.c"
switch( (*p) ) {
case 13: goto st10;
case 32: goto st10;
@@ -1839,12 +1840,13 @@ case 9:
_out: {}
}
-#line 700 "parser.rl"
+#line 701 "parser.rl"
if (cs >= JSON_first_final && p == pe) {
return result;
} else {
rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p);
+ return Qnil;
}
}
diff --git a/ext/json/ext/parser.rl b/ext/json/ext/parser.rl
index 012ca31..f71c694 100644
--- a/ext/json/ext/parser.rl
+++ b/ext/json/ext/parser.rl
@@ -373,6 +373,7 @@ static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *resul
return p + 1;
} else {
rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p);
+ return NULL;
}
}
@@ -702,6 +703,7 @@ static VALUE cParser_parse(VALUE self)
return result;
} else {
rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p);
+ return Qnil;
}
}