summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Frank <flori@ping.de>2016-06-21 10:12:06 +0200
committerFlorian Frank <flori@ping.de>2016-06-21 10:12:06 +0200
commite16dab51937894c674c07660cc0916a08af2e165 (patch)
treec17c40637c15b4b69ed269324310d5a8365a678a
parent6b5364c5765d48d77f6c6af323af4f8763867b5e (diff)
downloadjson-e16dab51937894c674c07660cc0916a08af2e165.tar.gz
Merge more changes from ruby core
-rw-r--r--ext/json/ext/parser/extconf.rb3
-rw-r--r--ext/json/ext/parser/parser.c205
-rw-r--r--ext/json/ext/parser/parser.rl59
-rw-r--r--json.gemspecbin4462 -> 5410 bytes
-rw-r--r--json_pure.gemspec42
5 files changed, 171 insertions, 138 deletions
diff --git a/ext/json/ext/parser/extconf.rb b/ext/json/ext/parser/extconf.rb
index ae4f861..f7360d4 100644
--- a/ext/json/ext/parser/extconf.rb
+++ b/ext/json/ext/parser/extconf.rb
@@ -1,3 +1,6 @@
+# frozen_string_literal: false
require 'mkmf'
+have_func("rb_enc_raise", "ruby.h")
+
create_makefile 'json/ext/parser'
diff --git a/ext/json/ext/parser/parser.c b/ext/json/ext/parser/parser.c
index 5b2e61c..8d83808 100644
--- a/ext/json/ext/parser/parser.c
+++ b/ext/json/ext/parser/parser.c
@@ -3,6 +3,28 @@
#include "../fbuffer/fbuffer.h"
#include "parser.h"
+#if defined HAVE_RUBY_ENCODING_H
+# define EXC_ENCODING rb_utf8_encoding(),
+# ifndef HAVE_RB_ENC_RAISE
+static void
+enc_raise(rb_encoding *enc, VALUE exc, const char *fmt, ...)
+{
+ va_list args;
+ VALUE mesg;
+
+ va_start(args, fmt);
+ mesg = rb_enc_vsprintf(enc, fmt, args);
+ va_end(args);
+
+ rb_exc_raise(rb_exc_new3(exc, mesg));
+}
+# define rb_enc_raise enc_raise
+# endif
+#else
+# define EXC_ENCODING /* nothing */
+# define rb_enc_raise rb_raise
+#endif
+
/* unicode */
static const char digit_values[256] = {
@@ -67,13 +89,6 @@ static int convert_UTF32_to_UTF8(char *buf, UTF32 ch)
return len;
}
-#ifdef HAVE_RUBY_ENCODING_H
-static VALUE CEncoding_ASCII_8BIT, CEncoding_UTF_8;
-static ID i_encoding, i_encode;
-#else
-static ID i_iconv;
-#endif
-
static VALUE mJSON, mExt, cParser, eParserError, eNestingError;
static VALUE CNaN, CInfinity, CMinusInfinity;
@@ -83,11 +98,11 @@ static ID i_json_creatable_p, i_json_create, i_create_id, i_create_additions,
i_match_string, i_aset, i_aref, i_leftshift;
-#line 109 "parser.rl"
+#line 124 "parser.rl"
-#line 91 "parser.c"
+#line 106 "parser.c"
static const int JSON_object_start = 1;
static const int JSON_object_first_final = 27;
static const int JSON_object_error = 0;
@@ -95,7 +110,7 @@ static const int JSON_object_error = 0;
static const int JSON_object_en_main = 1;
-#line 150 "parser.rl"
+#line 165 "parser.rl"
static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *result)
@@ -111,14 +126,14 @@ static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *resu
*result = NIL_P(object_class) ? rb_hash_new() : rb_class_new_instance(0, 0, object_class);
-#line 115 "parser.c"
+#line 130 "parser.c"
{
cs = JSON_object_start;
}
-#line 165 "parser.rl"
+#line 180 "parser.rl"
-#line 122 "parser.c"
+#line 137 "parser.c"
{
if ( p == pe )
goto _test_eof;
@@ -146,7 +161,7 @@ case 2:
goto st2;
goto st0;
tr2:
-#line 132 "parser.rl"
+#line 147 "parser.rl"
{
char *np;
json->parsing_name = 1;
@@ -159,7 +174,7 @@ st3:
if ( ++p == pe )
goto _test_eof3;
case 3:
-#line 163 "parser.c"
+#line 178 "parser.c"
switch( (*p) ) {
case 13: goto st3;
case 32: goto st3;
@@ -226,7 +241,7 @@ case 8:
goto st8;
goto st0;
tr11:
-#line 117 "parser.rl"
+#line 132 "parser.rl"
{
VALUE v = Qnil;
char *np = JSON_parse_value(json, p, pe, &v);
@@ -246,7 +261,7 @@ st9:
if ( ++p == pe )
goto _test_eof9;
case 9:
-#line 250 "parser.c"
+#line 265 "parser.c"
switch( (*p) ) {
case 13: goto st9;
case 32: goto st9;
@@ -335,14 +350,14 @@ case 18:
goto st9;
goto st18;
tr4:
-#line 140 "parser.rl"
+#line 155 "parser.rl"
{ p--; {p++; cs = 27; goto _out;} }
goto st27;
st27:
if ( ++p == pe )
goto _test_eof27;
case 27:
-#line 346 "parser.c"
+#line 361 "parser.c"
goto st0;
st19:
if ( ++p == pe )
@@ -440,7 +455,7 @@ case 26:
_out: {}
}
-#line 166 "parser.rl"
+#line 181 "parser.rl"
if (cs >= JSON_object_first_final) {
if (json->create_additions) {
@@ -465,7 +480,7 @@ case 26:
-#line 469 "parser.c"
+#line 484 "parser.c"
static const int JSON_value_start = 1;
static const int JSON_value_first_final = 29;
static const int JSON_value_error = 0;
@@ -473,7 +488,7 @@ static const int JSON_value_error = 0;
static const int JSON_value_en_main = 1;
-#line 270 "parser.rl"
+#line 285 "parser.rl"
static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *result)
@@ -481,14 +496,14 @@ static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *resul
int cs = EVIL;
-#line 485 "parser.c"
+#line 500 "parser.c"
{
cs = JSON_value_start;
}
-#line 277 "parser.rl"
+#line 292 "parser.rl"
-#line 492 "parser.c"
+#line 507 "parser.c"
{
if ( p == pe )
goto _test_eof;
@@ -522,14 +537,14 @@ st0:
cs = 0;
goto _out;
tr2:
-#line 218 "parser.rl"
+#line 233 "parser.rl"
{
char *np = JSON_parse_string(json, p, pe, result);
if (np == NULL) { p--; {p++; cs = 29; goto _out;} } else {p = (( np))-1;}
}
goto st29;
tr3:
-#line 223 "parser.rl"
+#line 238 "parser.rl"
{
char *np;
if(pe > p + 8 && !strncmp(MinusInfinity, p, 9)) {
@@ -538,7 +553,7 @@ tr3:
{p = (( p + 10))-1;}
p--; {p++; cs = 29; goto _out;}
} else {
- rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p);
+ rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p);
}
}
np = JSON_parse_float(json, p, pe, result);
@@ -549,7 +564,7 @@ tr3:
}
goto st29;
tr7:
-#line 241 "parser.rl"
+#line 256 "parser.rl"
{
char *np;
json->current_nesting++;
@@ -559,7 +574,7 @@ tr7:
}
goto st29;
tr11:
-#line 249 "parser.rl"
+#line 264 "parser.rl"
{
char *np;
json->current_nesting++;
@@ -569,39 +584,39 @@ tr11:
}
goto st29;
tr25:
-#line 211 "parser.rl"
+#line 226 "parser.rl"
{
if (json->allow_nan) {
*result = CInfinity;
} else {
- rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p - 8);
+ rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p - 8);
}
}
goto st29;
tr27:
-#line 204 "parser.rl"
+#line 219 "parser.rl"
{
if (json->allow_nan) {
*result = CNaN;
} else {
- rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p - 2);
+ rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p - 2);
}
}
goto st29;
tr31:
-#line 198 "parser.rl"
+#line 213 "parser.rl"
{
*result = Qfalse;
}
goto st29;
tr34:
-#line 195 "parser.rl"
+#line 210 "parser.rl"
{
*result = Qnil;
}
goto st29;
tr37:
-#line 201 "parser.rl"
+#line 216 "parser.rl"
{
*result = Qtrue;
}
@@ -610,9 +625,9 @@ st29:
if ( ++p == pe )
goto _test_eof29;
case 29:
-#line 257 "parser.rl"
+#line 272 "parser.rl"
{ p--; {p++; cs = 29; goto _out;} }
-#line 616 "parser.c"
+#line 631 "parser.c"
switch( (*p) ) {
case 13: goto st29;
case 32: goto st29;
@@ -853,7 +868,7 @@ case 28:
_out: {}
}
-#line 278 "parser.rl"
+#line 293 "parser.rl"
if (cs >= JSON_value_first_final) {
return p;
@@ -863,7 +878,7 @@ case 28:
}
-#line 867 "parser.c"
+#line 882 "parser.c"
static const int JSON_integer_start = 1;
static const int JSON_integer_first_final = 3;
static const int JSON_integer_error = 0;
@@ -871,7 +886,7 @@ static const int JSON_integer_error = 0;
static const int JSON_integer_en_main = 1;
-#line 294 "parser.rl"
+#line 309 "parser.rl"
static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *result)
@@ -879,15 +894,15 @@ static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *res
int cs = EVIL;
-#line 883 "parser.c"
+#line 898 "parser.c"
{
cs = JSON_integer_start;
}
-#line 301 "parser.rl"
+#line 316 "parser.rl"
json->memo = p;
-#line 891 "parser.c"
+#line 906 "parser.c"
{
if ( p == pe )
goto _test_eof;
@@ -921,14 +936,14 @@ case 3:
goto st0;
goto tr4;
tr4:
-#line 291 "parser.rl"
+#line 306 "parser.rl"
{ p--; {p++; cs = 4; goto _out;} }
goto st4;
st4:
if ( ++p == pe )
goto _test_eof4;
case 4:
-#line 932 "parser.c"
+#line 947 "parser.c"
goto st0;
st5:
if ( ++p == pe )
@@ -947,7 +962,7 @@ case 5:
_out: {}
}
-#line 303 "parser.rl"
+#line 318 "parser.rl"
if (cs >= JSON_integer_first_final) {
long len = p - json->memo;
@@ -962,7 +977,7 @@ case 5:
}
-#line 966 "parser.c"
+#line 981 "parser.c"
static const int JSON_float_start = 1;
static const int JSON_float_first_final = 8;
static const int JSON_float_error = 0;
@@ -970,7 +985,7 @@ static const int JSON_float_error = 0;
static const int JSON_float_en_main = 1;
-#line 328 "parser.rl"
+#line 343 "parser.rl"
static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *result)
@@ -978,15 +993,15 @@ static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *resul
int cs = EVIL;
-#line 982 "parser.c"
+#line 997 "parser.c"
{
cs = JSON_float_start;
}
-#line 335 "parser.rl"
+#line 350 "parser.rl"
json->memo = p;
-#line 990 "parser.c"
+#line 1005 "parser.c"
{
if ( p == pe )
goto _test_eof;
@@ -1044,14 +1059,14 @@ case 8:
goto st0;
goto tr9;
tr9:
-#line 322 "parser.rl"
+#line 337 "parser.rl"
{ p--; {p++; cs = 9; goto _out;} }
goto st9;
st9:
if ( ++p == pe )
goto _test_eof9;
case 9:
-#line 1055 "parser.c"
+#line 1070 "parser.c"
goto st0;
st5:
if ( ++p == pe )
@@ -1112,7 +1127,7 @@ case 7:
_out: {}
}
-#line 337 "parser.rl"
+#line 352 "parser.rl"
if (cs >= JSON_float_first_final) {
long len = p - json->memo;
@@ -1128,7 +1143,7 @@ case 7:
-#line 1132 "parser.c"
+#line 1147 "parser.c"
static const int JSON_array_start = 1;
static const int JSON_array_first_final = 17;
static const int JSON_array_error = 0;
@@ -1136,7 +1151,7 @@ static const int JSON_array_error = 0;
static const int JSON_array_en_main = 1;
-#line 380 "parser.rl"
+#line 395 "parser.rl"
static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *result)
@@ -1150,14 +1165,14 @@ static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *resul
*result = NIL_P(array_class) ? rb_ary_new() : rb_class_new_instance(0, 0, array_class);
-#line 1154 "parser.c"
+#line 1169 "parser.c"
{
cs = JSON_array_start;
}
-#line 393 "parser.rl"
+#line 408 "parser.rl"
-#line 1161 "parser.c"
+#line 1176 "parser.c"
{
if ( p == pe )
goto _test_eof;
@@ -1196,7 +1211,7 @@ case 2:
goto st2;
goto st0;
tr2:
-#line 357 "parser.rl"
+#line 372 "parser.rl"
{
VALUE v = Qnil;
char *np = JSON_parse_value(json, p, pe, &v);
@@ -1216,7 +1231,7 @@ st3:
if ( ++p == pe )
goto _test_eof3;
case 3:
-#line 1220 "parser.c"
+#line 1235 "parser.c"
switch( (*p) ) {
case 13: goto st3;
case 32: goto st3;
@@ -1316,14 +1331,14 @@ case 12:
goto st3;
goto st12;
tr4:
-#line 372 "parser.rl"
+#line 387 "parser.rl"
{ p--; {p++; cs = 17; goto _out;} }
goto st17;
st17:
if ( ++p == pe )
goto _test_eof17;
case 17:
-#line 1327 "parser.c"
+#line 1342 "parser.c"
goto st0;
st13:
if ( ++p == pe )
@@ -1379,12 +1394,12 @@ case 16:
_out: {}
}
-#line 394 "parser.rl"
+#line 409 "parser.rl"
if(cs >= JSON_array_first_final) {
return p + 1;
} else {
- rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p);
+ rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p);
return NULL;
}
}
@@ -1460,7 +1475,7 @@ static VALUE json_string_unescape(VALUE result, char *string, char *stringEnd)
}
-#line 1464 "parser.c"
+#line 1479 "parser.c"
static const int JSON_string_start = 1;
static const int JSON_string_first_final = 8;
static const int JSON_string_error = 0;
@@ -1468,7 +1483,7 @@ static const int JSON_string_error = 0;
static const int JSON_string_en_main = 1;
-#line 493 "parser.rl"
+#line 508 "parser.rl"
static int
@@ -1490,15 +1505,15 @@ static char *JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *resu
*result = rb_str_buf_new(0);
-#line 1494 "parser.c"
+#line 1509 "parser.c"
{
cs = JSON_string_start;
}
-#line 514 "parser.rl"
+#line 529 "parser.rl"
json->memo = p;
-#line 1502 "parser.c"
+#line 1517 "parser.c"
{
if ( p == pe )
goto _test_eof;
@@ -1523,7 +1538,7 @@ case 2:
goto st0;
goto st2;
tr2:
-#line 479 "parser.rl"
+#line 494 "parser.rl"
{
*result = json_string_unescape(*result, json->memo + 1, p);
if (NIL_P(*result)) {
@@ -1534,14 +1549,14 @@ tr2:
{p = (( p + 1))-1;}
}
}
-#line 490 "parser.rl"
+#line 505 "parser.rl"
{ p--; {p++; cs = 8; goto _out;} }
goto st8;
st8:
if ( ++p == pe )
goto _test_eof8;
case 8:
-#line 1545 "parser.c"
+#line 1560 "parser.c"
goto st0;
st3:
if ( ++p == pe )
@@ -1617,7 +1632,7 @@ case 7:
_out: {}
}
-#line 516 "parser.rl"
+#line 531 "parser.rl"
if (json->create_additions && RTEST(match_string = json->match_string)) {
VALUE klass;
@@ -1655,11 +1670,11 @@ case 7:
static VALUE convert_encoding(VALUE source)
{
#ifdef HAVE_RUBY_ENCODING_H
- VALUE encoding = rb_funcall(source, i_encoding, 0);
- if (encoding == CEncoding_ASCII_8BIT) {
+ rb_encoding *enc = rb_enc_get(source);
+ if (enc == rb_ascii8bit_encoding()) {
FORCE_UTF8(source);
} else {
- source = rb_funcall(source, i_encode, 1, CEncoding_UTF_8);
+ source = rb_str_conv_enc(source, NULL, rb_utf8_encoding());
}
#endif
return source;
@@ -1700,12 +1715,18 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
if (json->Vsource) {
rb_raise(rb_eTypeError, "already initialized instance");
}
+#ifdef HAVE_RB_SCAN_ARGS_OPTIONAL_HASH
+ rb_scan_args(argc, argv, "1:", &source, &opts);
+#else
rb_scan_args(argc, argv, "11", &source, &opts);
+#endif
if (!NIL_P(opts)) {
+#ifndef HAVE_RB_SCAN_ARGS_OPTIONAL_HASH
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 {
+#endif
VALUE tmp = ID2SYM(i_max_nesting);
if (option_given_p(opts, tmp)) {
VALUE max_nesting = rb_hash_aref(opts, tmp);
@@ -1766,7 +1787,9 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
} else {
json->match_string = Qnil;
}
+#ifndef HAVE_RB_SCAN_ARGS_OPTIONAL_HASH
}
+#endif
} else {
json->max_nesting = 100;
json->allow_nan = 0;
@@ -1786,7 +1809,7 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
}
-#line 1790 "parser.c"
+#line 1813 "parser.c"
static const int JSON_start = 1;
static const int JSON_first_final = 10;
static const int JSON_error = 0;
@@ -1794,7 +1817,7 @@ static const int JSON_error = 0;
static const int JSON_en_main = 1;
-#line 698 "parser.rl"
+#line 721 "parser.rl"
/*
@@ -1811,16 +1834,16 @@ static VALUE cParser_parse(VALUE self)
GET_PARSER;
-#line 1815 "parser.c"
+#line 1838 "parser.c"
{
cs = JSON_start;
}
-#line 714 "parser.rl"
+#line 737 "parser.rl"
p = json->source;
pe = p + json->len;
-#line 1824 "parser.c"
+#line 1847 "parser.c"
{
if ( p == pe )
goto _test_eof;
@@ -1854,7 +1877,7 @@ st0:
cs = 0;
goto _out;
tr2:
-#line 690 "parser.rl"
+#line 713 "parser.rl"
{
char *np = JSON_parse_value(json, p, pe, &result);
if (np == NULL) { p--; {p++; cs = 10; goto _out;} } else {p = (( np))-1;}
@@ -1864,7 +1887,7 @@ st10:
if ( ++p == pe )
goto _test_eof10;
case 10:
-#line 1868 "parser.c"
+#line 1891 "parser.c"
switch( (*p) ) {
case 13: goto st10;
case 32: goto st10;
@@ -1953,7 +1976,7 @@ case 9:
_out: {}
}
-#line 717 "parser.rl"
+#line 740 "parser.rl"
if (cs >= JSON_first_final && p == pe) {
return result;
@@ -2051,14 +2074,6 @@ void Init_parser(void)
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"));
- CEncoding_ASCII_8BIT = rb_funcall(rb_path2class("Encoding"), rb_intern("find"), 1, rb_str_new2("ascii-8bit"));
- i_encoding = rb_intern("encoding");
- i_encode = rb_intern("encode");
-#else
- i_iconv = rb_intern("iconv");
-#endif
}
/*
diff --git a/ext/json/ext/parser/parser.rl b/ext/json/ext/parser/parser.rl
index f3933cb..04d1b47 100644
--- a/ext/json/ext/parser/parser.rl
+++ b/ext/json/ext/parser/parser.rl
@@ -1,6 +1,28 @@
#include "../fbuffer/fbuffer.h"
#include "parser.h"
+#if defined HAVE_RUBY_ENCODING_H
+# define EXC_ENCODING rb_utf8_encoding(),
+# ifndef HAVE_RB_ENC_RAISE
+static void
+enc_raise(rb_encoding *enc, VALUE exc, const char *fmt, ...)
+{
+ va_list args;
+ VALUE mesg;
+
+ va_start(args, fmt);
+ mesg = rb_enc_vsprintf(enc, fmt, args);
+ va_end(args);
+
+ rb_exc_raise(rb_exc_new3(exc, mesg));
+}
+# define rb_enc_raise enc_raise
+# endif
+#else
+# define EXC_ENCODING /* nothing */
+# define rb_enc_raise rb_raise
+#endif
+
/* unicode */
static const char digit_values[256] = {
@@ -65,13 +87,6 @@ static int convert_UTF32_to_UTF8(char *buf, UTF32 ch)
return len;
}
-#ifdef HAVE_RUBY_ENCODING_H
-static VALUE CEncoding_ASCII_8BIT, CEncoding_UTF_8;
-static ID i_encoding, i_encode;
-#else
-static ID i_iconv;
-#endif
-
static VALUE mJSON, mExt, cParser, eParserError, eNestingError;
static VALUE CNaN, CInfinity, CMinusInfinity;
@@ -205,14 +220,14 @@ static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *resu
if (json->allow_nan) {
*result = CNaN;
} else {
- rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p - 2);
+ rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p - 2);
}
}
action parse_infinity {
if (json->allow_nan) {
*result = CInfinity;
} else {
- rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p - 8);
+ rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p - 8);
}
}
action parse_string {
@@ -228,7 +243,7 @@ static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *resu
fexec p + 10;
fhold; fbreak;
} else {
- rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p);
+ rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p);
}
}
np = JSON_parse_float(json, fpc, pe, result);
@@ -395,7 +410,7 @@ static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *resul
if(cs >= JSON_array_first_final) {
return p + 1;
} else {
- rb_raise(eParserError, "%u: unexpected token at '%s'", __LINE__, p);
+ rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p);
return NULL;
}
}
@@ -550,11 +565,11 @@ static char *JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *resu
static VALUE convert_encoding(VALUE source)
{
#ifdef HAVE_RUBY_ENCODING_H
- VALUE encoding = rb_funcall(source, i_encoding, 0);
- if (encoding == CEncoding_ASCII_8BIT) {
+ rb_encoding *enc = rb_enc_get(source);
+ if (enc == rb_ascii8bit_encoding()) {
FORCE_UTF8(source);
} else {
- source = rb_funcall(source, i_encode, 1, CEncoding_UTF_8);
+ source = rb_str_conv_enc(source, NULL, rb_utf8_encoding());
}
#endif
return source;
@@ -595,12 +610,18 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
if (json->Vsource) {
rb_raise(rb_eTypeError, "already initialized instance");
}
+#ifdef HAVE_RB_SCAN_ARGS_OPTIONAL_HASH
+ rb_scan_args(argc, argv, "1:", &source, &opts);
+#else
rb_scan_args(argc, argv, "11", &source, &opts);
+#endif
if (!NIL_P(opts)) {
+#ifndef HAVE_RB_SCAN_ARGS_OPTIONAL_HASH
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 {
+#endif
VALUE tmp = ID2SYM(i_max_nesting);
if (option_given_p(opts, tmp)) {
VALUE max_nesting = rb_hash_aref(opts, tmp);
@@ -661,7 +682,9 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
} else {
json->match_string = Qnil;
}
+#ifndef HAVE_RB_SCAN_ARGS_OPTIONAL_HASH
}
+#endif
} else {
json->max_nesting = 100;
json->allow_nan = 0;
@@ -811,14 +834,6 @@ void Init_parser(void)
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"));
- CEncoding_ASCII_8BIT = rb_funcall(rb_path2class("Encoding"), rb_intern("find"), 1, rb_str_new2("ascii-8bit"));
- i_encoding = rb_intern("encoding");
- i_encode = rb_intern("encode");
-#else
- i_iconv = rb_intern("iconv");
-#endif
}
/*
diff --git a/json.gemspec b/json.gemspec
index ca023f7..71982d9 100644
--- a/json.gemspec
+++ b/json.gemspec
Binary files differ
diff --git a/json_pure.gemspec b/json_pure.gemspec
index c2fb15f..3b3726b 100644
--- a/json_pure.gemspec
+++ b/json_pure.gemspec
@@ -2,36 +2,36 @@
# stub: json_pure 2.0.0 ruby lib
Gem::Specification.new do |s|
- s.name = "json_pure"
+ s.name = "json_pure".freeze
s.version = "2.0.0"
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
- s.require_paths = ["lib"]
- s.authors = ["Florian Frank"]
- s.date = "2016-06-07"
- s.description = "This is a JSON implementation in pure Ruby."
- s.email = "flori@ping.de"
- s.extra_rdoc_files = ["README.md"]
- s.files = ["./tests/test_helper.rb", ".gitignore", ".travis.yml", "CHANGES", "Gemfile", "README-json-jruby.markdown", "README.md", "Rakefile", "VERSION", "data/example.json", "data/index.html", "data/prototype.js", "diagrams/.keep", "ext/json/ext/fbuffer/fbuffer.h", "ext/json/ext/generator/depend", "ext/json/ext/generator/extconf.rb", "ext/json/ext/generator/generator.c", "ext/json/ext/generator/generator.h", "ext/json/ext/parser/depend", "ext/json/ext/parser/extconf.rb", "ext/json/ext/parser/parser.c", "ext/json/ext/parser/parser.h", "ext/json/ext/parser/parser.rl", "ext/json/extconf.rb", "install.rb", "java/src/json/ext/ByteListTranscoder.java", "java/src/json/ext/Generator.java", "java/src/json/ext/GeneratorMethods.java", "java/src/json/ext/GeneratorService.java", "java/src/json/ext/GeneratorState.java", "java/src/json/ext/OptionsReader.java", "java/src/json/ext/Parser.java", "java/src/json/ext/Parser.rl", "java/src/json/ext/ParserService.java", "java/src/json/ext/RuntimeInfo.java", "java/src/json/ext/StringDecoder.java", "java/src/json/ext/StringEncoder.java", "java/src/json/ext/Utils.java", "json-java.gemspec", "json.gemspec", "json_pure.gemspec", "lib/json.rb", "lib/json/add/bigdecimal.rb", "lib/json/add/complex.rb", "lib/json/add/core.rb", "lib/json/add/date.rb", "lib/json/add/date_time.rb", "lib/json/add/exception.rb", "lib/json/add/ostruct.rb", "lib/json/add/range.rb", "lib/json/add/rational.rb", "lib/json/add/regexp.rb", "lib/json/add/struct.rb", "lib/json/add/symbol.rb", "lib/json/add/time.rb", "lib/json/common.rb", "lib/json/ext.rb", "lib/json/ext/.keep", "lib/json/generic_object.rb", "lib/json/pure.rb", "lib/json/pure/generator.rb", "lib/json/pure/parser.rb", "lib/json/version.rb", "references/rfc7159.txt", "tests/fixtures/fail10.json", "tests/fixtures/fail11.json", "tests/fixtures/fail12.json", "tests/fixtures/fail13.json", "tests/fixtures/fail14.json", "tests/fixtures/fail18.json", "tests/fixtures/fail19.json", "tests/fixtures/fail2.json", "tests/fixtures/fail20.json", "tests/fixtures/fail21.json", "tests/fixtures/fail22.json", "tests/fixtures/fail23.json", "tests/fixtures/fail24.json", "tests/fixtures/fail25.json", "tests/fixtures/fail27.json", "tests/fixtures/fail28.json", "tests/fixtures/fail3.json", "tests/fixtures/fail4.json", "tests/fixtures/fail5.json", "tests/fixtures/fail6.json", "tests/fixtures/fail7.json", "tests/fixtures/fail8.json", "tests/fixtures/fail9.json", "tests/fixtures/obsolete_fail1.json", "tests/fixtures/pass1.json", "tests/fixtures/pass15.json", "tests/fixtures/pass16.json", "tests/fixtures/pass17.json", "tests/fixtures/pass2.json", "tests/fixtures/pass26.json", "tests/fixtures/pass3.json", "tests/json_addition_test.rb", "tests/json_common_interface_test.rb", "tests/json_encoding_test.rb", "tests/json_ext_parser_test.rb", "tests/json_fixtures_test.rb", "tests/json_generator_test.rb", "tests/json_generic_object_test.rb", "tests/json_parser_test.rb", "tests/json_string_matching_test.rb", "tests/test_helper.rb", "tools/fuzz.rb", "tools/server.rb"]
- s.homepage = "http://flori.github.com/json"
- s.licenses = ["Ruby"]
- s.rdoc_options = ["--title", "JSON implemention for ruby", "--main", "README.md"]
- s.rubygems_version = "2.5.1"
- s.summary = "JSON Implementation for Ruby"
- s.test_files = ["./tests/test_helper.rb"]
+ s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
+ s.require_paths = ["lib".freeze]
+ s.authors = ["Florian Frank".freeze]
+ s.date = "2016-06-21"
+ s.description = "This is a JSON implementation in pure Ruby.".freeze
+ s.email = "flori@ping.de".freeze
+ s.extra_rdoc_files = ["README.md".freeze]
+ s.files = ["./tests/test_helper.rb".freeze, ".gitignore".freeze, ".travis.yml".freeze, "CHANGES".freeze, "Gemfile".freeze, "README-json-jruby.markdown".freeze, "README.md".freeze, "Rakefile".freeze, "VERSION".freeze, "data/example.json".freeze, "data/index.html".freeze, "data/prototype.js".freeze, "diagrams/.keep".freeze, "ext/json/ext/fbuffer/fbuffer.h".freeze, "ext/json/ext/generator/depend".freeze, "ext/json/ext/generator/extconf.rb".freeze, "ext/json/ext/generator/generator.c".freeze, "ext/json/ext/generator/generator.h".freeze, "ext/json/ext/parser/depend".freeze, "ext/json/ext/parser/extconf.rb".freeze, "ext/json/ext/parser/parser.c".freeze, "ext/json/ext/parser/parser.h".freeze, "ext/json/ext/parser/parser.rl".freeze, "ext/json/extconf.rb".freeze, "install.rb".freeze, "java/src/json/ext/ByteListTranscoder.java".freeze, "java/src/json/ext/Generator.java".freeze, "java/src/json/ext/GeneratorMethods.java".freeze, "java/src/json/ext/GeneratorService.java".freeze, "java/src/json/ext/GeneratorState.java".freeze, "java/src/json/ext/OptionsReader.java".freeze, "java/src/json/ext/Parser.java".freeze, "java/src/json/ext/Parser.rl".freeze, "java/src/json/ext/ParserService.java".freeze, "java/src/json/ext/RuntimeInfo.java".freeze, "java/src/json/ext/StringDecoder.java".freeze, "java/src/json/ext/StringEncoder.java".freeze, "java/src/json/ext/Utils.java".freeze, "json-java.gemspec".freeze, "json.gemspec".freeze, "json_pure.gemspec".freeze, "lib/json.rb".freeze, "lib/json/add/bigdecimal.rb".freeze, "lib/json/add/complex.rb".freeze, "lib/json/add/core.rb".freeze, "lib/json/add/date.rb".freeze, "lib/json/add/date_time.rb".freeze, "lib/json/add/exception.rb".freeze, "lib/json/add/ostruct.rb".freeze, "lib/json/add/range.rb".freeze, "lib/json/add/rational.rb".freeze, "lib/json/add/regexp.rb".freeze, "lib/json/add/struct.rb".freeze, "lib/json/add/symbol.rb".freeze, "lib/json/add/time.rb".freeze, "lib/json/common.rb".freeze, "lib/json/ext.rb".freeze, "lib/json/ext/.keep".freeze, "lib/json/generic_object.rb".freeze, "lib/json/pure.rb".freeze, "lib/json/pure/generator.rb".freeze, "lib/json/pure/parser.rb".freeze, "lib/json/version.rb".freeze, "references/rfc7159.txt".freeze, "tests/fixtures/fail10.json".freeze, "tests/fixtures/fail11.json".freeze, "tests/fixtures/fail12.json".freeze, "tests/fixtures/fail13.json".freeze, "tests/fixtures/fail14.json".freeze, "tests/fixtures/fail18.json".freeze, "tests/fixtures/fail19.json".freeze, "tests/fixtures/fail2.json".freeze, "tests/fixtures/fail20.json".freeze, "tests/fixtures/fail21.json".freeze, "tests/fixtures/fail22.json".freeze, "tests/fixtures/fail23.json".freeze, "tests/fixtures/fail24.json".freeze, "tests/fixtures/fail25.json".freeze, "tests/fixtures/fail27.json".freeze, "tests/fixtures/fail28.json".freeze, "tests/fixtures/fail3.json".freeze, "tests/fixtures/fail4.json".freeze, "tests/fixtures/fail5.json".freeze, "tests/fixtures/fail6.json".freeze, "tests/fixtures/fail7.json".freeze, "tests/fixtures/fail8.json".freeze, "tests/fixtures/fail9.json".freeze, "tests/fixtures/obsolete_fail1.json".freeze, "tests/fixtures/pass1.json".freeze, "tests/fixtures/pass15.json".freeze, "tests/fixtures/pass16.json".freeze, "tests/fixtures/pass17.json".freeze, "tests/fixtures/pass2.json".freeze, "tests/fixtures/pass26.json".freeze, "tests/fixtures/pass3.json".freeze, "tests/json_addition_test.rb".freeze, "tests/json_common_interface_test.rb".freeze, "tests/json_encoding_test.rb".freeze, "tests/json_ext_parser_test.rb".freeze, "tests/json_fixtures_test.rb".freeze, "tests/json_generator_test.rb".freeze, "tests/json_generic_object_test.rb".freeze, "tests/json_parser_test.rb".freeze, "tests/json_string_matching_test.rb".freeze, "tests/test_helper.rb".freeze, "tools/diff.sh".freeze, "tools/fuzz.rb".freeze, "tools/server.rb".freeze]
+ s.homepage = "http://flori.github.com/json".freeze
+ s.licenses = ["Ruby".freeze]
+ s.rdoc_options = ["--title".freeze, "JSON implemention for ruby".freeze, "--main".freeze, "README.md".freeze]
+ s.rubygems_version = "2.6.4".freeze
+ s.summary = "JSON Implementation for Ruby".freeze
+ s.test_files = ["./tests/test_helper.rb".freeze]
if s.respond_to? :specification_version then
s.specification_version = 4
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
- s.add_development_dependency(%q<rake>, [">= 0"])
- s.add_development_dependency(%q<test-unit>, ["~> 2.0"])
+ s.add_development_dependency(%q<rake>.freeze, [">= 0"])
+ s.add_development_dependency(%q<test-unit>.freeze, ["~> 2.0"])
else
- s.add_dependency(%q<rake>, [">= 0"])
- s.add_dependency(%q<test-unit>, ["~> 2.0"])
+ s.add_dependency(%q<rake>.freeze, [">= 0"])
+ s.add_dependency(%q<test-unit>.freeze, ["~> 2.0"])
end
else
- s.add_dependency(%q<rake>, [">= 0"])
- s.add_dependency(%q<test-unit>, ["~> 2.0"])
+ s.add_dependency(%q<rake>.freeze, [">= 0"])
+ s.add_dependency(%q<test-unit>.freeze, ["~> 2.0"])
end
end