diff options
author | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-03-11 13:36:06 +0000 |
---|---|---|
committer | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-03-11 13:36:06 +0000 |
commit | 4d8d3184d18b1a9d2eadb86a6688dc62eca7eabc (patch) | |
tree | 03e3a00e4e484ffdb46d5d774ab887dc695b8ed0 /ext/json/parser/parser.rl | |
parent | 9d9ab5a384de3877f29cef8c0293c1caa432692c (diff) | |
download | ruby-4d8d3184d18b1a9d2eadb86a6688dc62eca7eabc.tar.gz |
* ext/json: Merge 164a75c8bd2007d32c4d7665d53140d8fc126dcd.
[ruby-core:41917] [Bug #5846]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34971 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/json/parser/parser.rl')
-rw-r--r-- | ext/json/parser/parser.rl | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/ext/json/parser/parser.rl b/ext/json/parser/parser.rl index 33e775ce72..c96b0a8225 100644 --- a/ext/json/parser/parser.rl +++ b/ext/json/parser/parser.rl @@ -1,3 +1,4 @@ +#include "../fbuffer/fbuffer.h" #include "parser.h" /* unicode */ @@ -78,7 +79,7 @@ static VALUE CNaN, CInfinity, CMinusInfinity; static ID i_json_creatable_p, i_json_create, i_create_id, i_create_additions, i_chr, i_max_nesting, i_allow_nan, i_symbolize_names, i_quirks_mode, i_object_class, i_array_class, i_key_p, i_deep_const_get, i_match, - i_match_string, i_aset, i_leftshift; + i_match_string, i_aset, i_aref, i_leftshift; %%{ machine JSON_common; @@ -166,7 +167,12 @@ static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *resu if (cs >= JSON_object_first_final) { if (json->create_additions) { - VALUE klassname = rb_hash_aref(*result, json->create_id); + VALUE klassname; + if (NIL_P(json->object_class)) { + klassname = rb_hash_aref(*result, json->create_id); + } else { + klassname = rb_funcall(*result, i_aref, 1, json->create_id); + } if (!NIL_P(klassname)) { VALUE klass = rb_funcall(mJSON, i_deep_const_get, 1, klassname); if (RTEST(rb_funcall(klass, i_json_creatable_p, 0))) { @@ -298,7 +304,10 @@ static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *res if (cs >= JSON_integer_first_final) { long len = p - json->memo; - *result = rb_Integer(rb_str_new(json->memo, len)); + fbuffer_clear(json->fbuffer); + fbuffer_append(json->fbuffer, json->memo, len); + fbuffer_append_char(json->fbuffer, '\0'); + *result = rb_cstr2inum(FBUFFER_PTR(json->fbuffer), 10); return p + 1; } else { return NULL; @@ -329,7 +338,10 @@ static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *resul if (cs >= JSON_float_first_final) { long len = p - json->memo; - *result = rb_Float(rb_str_new(json->memo, len)); + fbuffer_clear(json->fbuffer); + fbuffer_append(json->fbuffer, json->memo, len); + fbuffer_append_char(json->fbuffer, '\0'); + *result = rb_float_new(rb_cstr_to_dbl(FBUFFER_PTR(json->fbuffer), 1)); return p + 1; } else { return NULL; @@ -688,6 +700,7 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self) json->object_class = Qnil; json->array_class = Qnil; } + source = rb_convert_type(source, T_STRING, "String", "to_str"); if (!json->quirks_mode) { source = convert_encoding(StringValue(source)); } @@ -805,6 +818,7 @@ static JSON_Parser *JSON_allocate() { JSON_Parser *json = ALLOC(JSON_Parser); MEMZERO(json, JSON_Parser, 1); + json->fbuffer = fbuffer_alloc(0); return json; } @@ -819,6 +833,7 @@ static void JSON_mark(JSON_Parser *json) static void JSON_free(JSON_Parser *json) { + fbuffer_free(json->fbuffer); ruby_xfree(json); } @@ -886,6 +901,7 @@ void Init_parser() i_key_p = rb_intern("key?"); i_deep_const_get = rb_intern("deep_const_get"); i_aset = rb_intern("[]="); + i_aref = rb_intern("[]"); i_leftshift = rb_intern("<<"); #ifdef HAVE_RUBY_ENCODING_H CEncoding_UTF_8 = rb_funcall(rb_path2class("Encoding"), rb_intern("find"), 1, rb_str_new2("utf-8")); |