ext/json/ext/parser/parser.rl in json_pure-1.1.3 vs ext/json/ext/parser/parser.rl in json_pure-1.1.4

- old
+ new

@@ -1,12 +1,30 @@ #include "ruby.h" +#include "unicode.h" +#if HAVE_RE_H #include "re.h" +#endif +#if HAVE_RUBY_ST_H +#include "ruby/st.h" +#endif +#if HAVE_ST_H #include "st.h" -#include "unicode.h" +#endif #define EVIL 0x666 +#ifndef RHASH_TBL +#define RHASH_TBL(hsh) (RHASH(hsh)->tbl) +#endif + +#ifdef HAVE_RUBY_ENCODING_H +#include "ruby/encoding.h" +#define FORCE_UTF8(obj) rb_enc_associate((obj), rb_utf8_encoding()) +#else +#define FORCE_UTF8(obj) +#endif + static VALUE mJSON, mExt, cParser, eParserError, eNestingError; 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; @@ -390,12 +408,18 @@ write data; action parse_string { *result = json_string_unescape(json->memo + 1, p); - if (NIL_P(*result)) { fhold; fbreak; } else fexec p + 1; - } + if (NIL_P(*result)) { + fhold; + fbreak; + } else { + FORCE_UTF8(*result); + fexec p + 1; + } + } action exit { fhold; fbreak; } main := '"' ((^(["\\] | 0..0x1f) | '\\'["\\/bfnrt] | '\\u'[0-9a-fA-F]{4} | '\\'^(["\\/bfnrtu]|0..0x1f))* %parse_string) '"' @exit; }%% @@ -494,11 +518,11 @@ opts = rb_convert_type(opts, T_HASH, "Hash", "to_hash"); if (NIL_P(opts)) { rb_raise(rb_eArgError, "opts needs to be like a hash"); } else { VALUE tmp = ID2SYM(i_max_nesting); - if (st_lookup(RHASH(opts)->tbl, tmp, 0)) { + if (st_lookup(RHASH_TBL(opts), tmp, 0)) { VALUE max_nesting = rb_hash_aref(opts, tmp); if (RTEST(max_nesting)) { Check_Type(max_nesting, T_FIXNUM); json->max_nesting = FIX2INT(max_nesting); } else { @@ -506,18 +530,18 @@ } } else { json->max_nesting = 19; } tmp = ID2SYM(i_allow_nan); - if (st_lookup(RHASH(opts)->tbl, tmp, 0)) { + if (st_lookup(RHASH_TBL(opts), tmp, 0)) { VALUE allow_nan = rb_hash_aref(opts, tmp); json->allow_nan = RTEST(allow_nan) ? 1 : 0; } else { json->allow_nan = 0; } tmp = ID2SYM(i_create_additions); - if (st_lookup(RHASH(opts)->tbl, tmp, 0)) { + if (st_lookup(RHASH_TBL(opts), tmp, 0)) { VALUE create_additions = rb_hash_aref(opts, tmp); if (RTEST(create_additions)) { json->create_id = rb_funcall(mJSON, i_create_id, 0); } else { json->create_id = Qnil; @@ -588,10 +612,10 @@ rb_gc_mark_maybe(json->create_id); } static void JSON_free(JSON_Parser *json) { - free(json); + ruby_xfree(json); } static VALUE cJSON_parser_s_allocate(VALUE klass) { JSON_Parser *json = JSON_allocate();