summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore3
-rw-r--r--.travis.yml1
-rw-r--r--ext/json/ext/fbuffer/fbuffer.h9
-rw-r--r--ext/json/ext/generator/extconf.rb10
-rw-r--r--ext/json/ext/generator/generator.c44
-rw-r--r--ext/json/ext/generator/generator.h18
-rw-r--r--ext/json/ext/parser/extconf.rb10
-rw-r--r--ext/json/ext/parser/parser.c27
-rw-r--r--ext/json/ext/parser/parser.h15
-rw-r--r--ext/json/ext/parser/parser.rl29
-rw-r--r--ext/json/extconf.rb3
-rw-r--r--java/src/json/ext/Parser.java171
-rw-r--r--java/src/json/ext/Parser.rl9
-rw-r--r--json.gemspecbin4942 -> 5008 bytes
-rw-r--r--json_pure.gemspec6
-rw-r--r--lib/json/common.rb2
-rwxr-xr-xtests/test_json.rb2
-rwxr-xr-xtests/test_json_generate.rb18
18 files changed, 231 insertions, 146 deletions
diff --git a/.gitignore b/.gitignore
index 297633e..5ef62af 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,5 @@
.*.sw[pon]
+*.bundle
coverage
tags
pkg
@@ -11,3 +12,5 @@ Gemfile.lock
.rbx
.AppleDouble
.DS_Store
+*/**/Makefile
+*/**/*.o
diff --git a/.travis.yml b/.travis.yml
index 5907de7..c0d1d34 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -8,6 +8,7 @@ rvm:
- 1.9.3
- 2.0.0
- 2.1
+ - 2.2
- ree
- rbx-18mode
- rbx-19mode
diff --git a/ext/json/ext/fbuffer/fbuffer.h b/ext/json/ext/fbuffer/fbuffer.h
index 9524fb1..5a0a27c 100644
--- a/ext/json/ext/fbuffer/fbuffer.h
+++ b/ext/json/ext/fbuffer/fbuffer.h
@@ -25,6 +25,15 @@
#define RSTRING_LEN(string) RSTRING(string)->len
#endif
+#ifdef PRIsVALUE
+# define RB_OBJ_CLASSNAME(obj) rb_obj_class(obj)
+# define RB_OBJ_STRING(obj) (obj)
+#else
+# define PRIsVALUE "s"
+# define RB_OBJ_CLASSNAME(obj) rb_obj_classname(obj)
+# define RB_OBJ_STRING(obj) StringValueCStr(obj)
+#endif
+
#ifdef HAVE_RUBY_ENCODING_H
#include "ruby/encoding.h"
#define FORCE_UTF8(obj) rb_enc_associate((obj), rb_utf8_encoding())
diff --git a/ext/json/ext/generator/extconf.rb b/ext/json/ext/generator/extconf.rb
index c947501..8627c5f 100644
--- a/ext/json/ext/generator/extconf.rb
+++ b/ext/json/ext/generator/extconf.rb
@@ -1,14 +1,4 @@
require 'mkmf'
-unless $CFLAGS.gsub!(/ -O[\dsz]?/, ' -O3')
- $CFLAGS << ' -O3'
-end
-if CONFIG['CC'] =~ /gcc/
- $CFLAGS << ' -Wall'
- unless $DEBUG && !$CFLAGS.gsub!(/ -O[\dsz]?/, ' -O0 -ggdb')
- $CFLAGS << ' -O0 -ggdb'
- end
-end
-
$defs << "-DJSON_GENERATOR"
create_makefile 'json/ext/generator'
diff --git a/ext/json/ext/generator/generator.c b/ext/json/ext/generator/generator.c
index 976afc5..a474fbb 100644
--- a/ext/json/ext/generator/generator.c
+++ b/ext/json/ext/generator/generator.c
@@ -486,8 +486,9 @@ static VALUE mObject_to_json(int argc, VALUE *argv, VALUE self)
return cState_partial_generate(state, string);
}
-static void State_free(JSON_Generator_State *state)
+static void State_free(void *ptr)
{
+ JSON_Generator_State *state = ptr;
if (state->indent) ruby_xfree(state->indent);
if (state->space) ruby_xfree(state->space);
if (state->space_before) ruby_xfree(state->space_before);
@@ -499,7 +500,33 @@ static void State_free(JSON_Generator_State *state)
ruby_xfree(state);
}
-static JSON_Generator_State *State_allocate()
+static size_t State_memsize(const void *ptr)
+{
+ const JSON_Generator_State *state = ptr;
+ size_t size = sizeof(*state);
+ if (state->indent) size += state->indent_len + 1;
+ if (state->space) size += state->space_len + 1;
+ if (state->space_before) size += state->space_before_len + 1;
+ if (state->object_nl) size += state->object_nl_len + 1;
+ if (state->array_nl) size += state->array_nl_len + 1;
+ if (state->array_delim) size += FBUFFER_CAPA(state->array_delim);
+ if (state->object_delim) size += FBUFFER_CAPA(state->object_delim);
+ if (state->object_delim2) size += FBUFFER_CAPA(state->object_delim2);
+ return size;
+}
+
+#ifdef NEW_TYPEDDATA_WRAPPER
+static const rb_data_type_t JSON_Generator_State_type = {
+ "JSON/Generator/State",
+ {NULL, State_free, State_memsize,},
+#ifdef RUBY_TYPED_FREE_IMMEDIATELY
+ 0, 0,
+ RUBY_TYPED_FREE_IMMEDIATELY,
+#endif
+};
+#endif
+
+static JSON_Generator_State *State_allocate(void)
{
JSON_Generator_State *state = ALLOC(JSON_Generator_State);
MEMZERO(state, JSON_Generator_State, 1);
@@ -509,7 +536,7 @@ static JSON_Generator_State *State_allocate()
static VALUE cState_s_allocate(VALUE klass)
{
JSON_Generator_State *state = State_allocate();
- return Data_Wrap_Struct(klass, NULL, State_free, state);
+ return TypedData_Wrap_Struct(klass, &JSON_Generator_State_type, state);
}
/*
@@ -812,10 +839,10 @@ static void generate_json_float(FBuffer *buffer, VALUE Vstate, JSON_Generator_St
if (!allow_nan) {
if (isinf(value)) {
fbuffer_free(buffer);
- rb_raise(eGeneratorError, "%u: %s not allowed in JSON", __LINE__, StringValueCStr(tmp));
+ rb_raise(eGeneratorError, "%u: %"PRIsVALUE" not allowed in JSON", __LINE__, RB_OBJ_STRING(tmp));
} else if (isnan(value)) {
fbuffer_free(buffer);
- rb_raise(eGeneratorError, "%u: %s not allowed in JSON", __LINE__, StringValueCStr(tmp));
+ rb_raise(eGeneratorError, "%u: %"PRIsVALUE" not allowed in JSON", __LINE__, RB_OBJ_STRING(tmp));
}
}
fbuffer_append_str(buffer, tmp);
@@ -965,8 +992,9 @@ static VALUE cState_init_copy(VALUE obj, VALUE orig)
{
JSON_Generator_State *objState, *origState;
- Data_Get_Struct(obj, JSON_Generator_State, objState);
- Data_Get_Struct(orig, JSON_Generator_State, origState);
+ if (obj == orig) return obj;
+ GET_STATE_TO(obj, objState);
+ GET_STATE_TO(orig, origState);
if (!objState) rb_raise(rb_eArgError, "unallocated JSON::State");
MEMCPY(objState, origState, JSON_Generator_State, 1);
@@ -1326,7 +1354,7 @@ static VALUE cState_buffer_initial_length_set(VALUE self, VALUE buffer_initial_l
/*
*
*/
-void Init_generator()
+void Init_generator(void)
{
rb_require("json/common");
diff --git a/ext/json/ext/generator/generator.h b/ext/json/ext/generator/generator.h
index e2fbf12..02193f0 100644
--- a/ext/json/ext/generator/generator.h
+++ b/ext/json/ext/generator/generator.h
@@ -78,9 +78,12 @@ typedef struct JSON_Generator_StateStruct {
long buffer_initial_length;
} JSON_Generator_State;
+#define GET_STATE_TO(self, state) \
+ TypedData_Get_Struct(self, JSON_Generator_State, &JSON_Generator_State_type, state)
+
#define GET_STATE(self) \
JSON_Generator_State *state; \
- Data_Get_Struct(self, JSON_Generator_State, state)
+ GET_STATE_TO(self, state)
#define GENERATE_JSON(type) \
FBuffer *buffer; \
@@ -89,7 +92,7 @@ typedef struct JSON_Generator_StateStruct {
\
rb_scan_args(argc, argv, "01", &Vstate); \
Vstate = cState_from_state_s(cState, Vstate); \
- Data_Get_Struct(Vstate, JSON_Generator_State, state); \
+ TypedData_Get_Struct(Vstate, JSON_Generator_State, &JSON_Generator_State_type, state); \
buffer = cState_prepare_buffer(Vstate); \
generate_json_##type(buffer, Vstate, state, self); \
return fbuffer_to_s(buffer)
@@ -108,8 +111,8 @@ static VALUE mTrueClass_to_json(int argc, VALUE *argv, VALUE self);
static VALUE mFalseClass_to_json(int argc, VALUE *argv, VALUE self);
static VALUE mNilClass_to_json(int argc, VALUE *argv, VALUE self);
static VALUE mObject_to_json(int argc, VALUE *argv, VALUE self);
-static void State_free(JSON_Generator_State *state);
-static JSON_Generator_State *State_allocate();
+static void State_free(void *state);
+static JSON_Generator_State *State_allocate(void);
static VALUE cState_s_allocate(VALUE klass);
static VALUE cState_configure(VALUE self, VALUE opts);
static VALUE cState_to_h(VALUE self);
@@ -144,5 +147,12 @@ static VALUE cState_ascii_only_p(VALUE self);
static VALUE cState_depth(VALUE self);
static VALUE cState_depth_set(VALUE self, VALUE depth);
static FBuffer *cState_prepare_buffer(VALUE self);
+#ifdef TypedData_Wrap_Struct
+static const rb_data_type_t JSON_Generator_State_type;
+#define NEW_TYPEDDATA_WRAPPER 1
+#else
+#define TypedData_Wrap_Struct(klass, ignore, json) Data_Wrap_Struct(klass, NULL, State_free, json)
+#define TypedData_Get_Struct(self, JSON_Generator_State, ignore, json) Data_Get_Struct(self, JSON_Generator_State, json)
+#endif
#endif
diff --git a/ext/json/ext/parser/extconf.rb b/ext/json/ext/parser/extconf.rb
index 4791829..ae4f861 100644
--- a/ext/json/ext/parser/extconf.rb
+++ b/ext/json/ext/parser/extconf.rb
@@ -1,13 +1,3 @@
require 'mkmf'
-unless $CFLAGS.gsub!(/ -O[\dsz]?/, ' -O3')
- $CFLAGS << ' -O3'
-end
-if CONFIG['CC'] =~ /gcc/
- $CFLAGS << ' -Wall'
- if $DEBUG && !$CFLAGS.gsub!(/ -O[\dsz]?/, ' -O0 -ggdb')
- $CFLAGS << ' -O0 -ggdb'
- end
-end
-
create_makefile 'json/ext/parser'
diff --git a/ext/json/ext/parser/parser.c b/ext/json/ext/parser/parser.c
index e91e161..8824b30 100644
--- a/ext/json/ext/parser/parser.c
+++ b/ext/json/ext/parser/parser.c
@@ -2092,7 +2092,7 @@ static VALUE cParser_parse(VALUE self)
}
-static JSON_Parser *JSON_allocate()
+static JSON_Parser *JSON_allocate(void)
{
JSON_Parser *json = ALLOC(JSON_Parser);
MEMZERO(json, JSON_Parser, 1);
@@ -2100,8 +2100,9 @@ static JSON_Parser *JSON_allocate()
return json;
}
-static void JSON_mark(JSON_Parser *json)
+static void JSON_mark(void *ptr)
{
+ JSON_Parser *json = ptr;
rb_gc_mark_maybe(json->Vsource);
rb_gc_mark_maybe(json->create_id);
rb_gc_mark_maybe(json->object_class);
@@ -2109,16 +2110,34 @@ static void JSON_mark(JSON_Parser *json)
rb_gc_mark_maybe(json->match_string);
}
-static void JSON_free(JSON_Parser *json)
+static void JSON_free(void *ptr)
{
+ JSON_Parser *json = ptr;
fbuffer_free(json->fbuffer);
ruby_xfree(json);
}
+static size_t JSON_memsize(const void *ptr)
+{
+ const JSON_Parser *json = ptr;
+ return sizeof(*json) + FBUFFER_CAPA(json->fbuffer);
+}
+
+#ifdef NEW_TYPEDDATA_WRAPPER
+static const rb_data_type_t JSON_Parser_type = {
+ "JSON/Parser",
+ {JSON_mark, JSON_free, JSON_memsize,},
+#ifdef RUBY_TYPED_FREE_IMMEDIATELY
+ 0, 0,
+ RUBY_TYPED_FREE_IMMEDIATELY,
+#endif
+};
+#endif
+
static VALUE cJSON_parser_s_allocate(VALUE klass)
{
JSON_Parser *json = JSON_allocate();
- return Data_Wrap_Struct(klass, JSON_mark, JSON_free, json);
+ return TypedData_Wrap_Struct(klass, &JSON_Parser_type, json);
}
/*
diff --git a/ext/json/ext/parser/parser.h b/ext/json/ext/parser/parser.h
index b192064..418637f 100644
--- a/ext/json/ext/parser/parser.h
+++ b/ext/json/ext/parser/parser.h
@@ -51,7 +51,7 @@ typedef struct JSON_ParserStruct {
if (!json->Vsource) rb_raise(rb_eTypeError, "uninitialized instance")
#define GET_PARSER_INIT \
JSON_Parser *json; \
- Data_Get_Struct(self, JSON_Parser, json)
+ TypedData_Get_Struct(self, JSON_Parser, &JSON_Parser_type, json)
#define MinusInfinity "-Infinity"
#define EVIL 0x666
@@ -68,10 +68,17 @@ static char *JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *resu
static VALUE convert_encoding(VALUE source);
static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self);
static VALUE cParser_parse(VALUE self);
-static JSON_Parser *JSON_allocate();
-static void JSON_mark(JSON_Parser *json);
-static void JSON_free(JSON_Parser *json);
+static JSON_Parser *JSON_allocate(void);
+static void JSON_mark(void *json);
+static void JSON_free(void *json);
static VALUE cJSON_parser_s_allocate(VALUE klass);
static VALUE cParser_source(VALUE self);
+#ifdef TypedData_Wrap_Struct
+static const rb_data_type_t JSON_Parser_type;
+#define NEW_TYPEDDATA_WRAPPER 1
+#else
+#define TypedData_Wrap_Struct(klass, ignore, json) Data_Wrap_Struct(klass, JSON_mark, JSON_free, json)
+#define TypedData_Get_Struct(self, JSON_Parser, ignore, json) Data_Get_Struct(self, JSON_Parser, json)
+#endif
#endif
diff --git a/ext/json/ext/parser/parser.rl b/ext/json/ext/parser/parser.rl
index c60e35c..2af1cc6 100644
--- a/ext/json/ext/parser/parser.rl
+++ b/ext/json/ext/parser/parser.rl
@@ -611,7 +611,7 @@ static VALUE convert_encoding(VALUE source)
* the default.
* * *create_additions*: If set to false, the Parser doesn't create
* additions even if a matching class and create_id was found. This option
- * defaults to true.
+ * defaults to false.
* * *object_class*: Defaults to Hash
* * *array_class*: Defaults to Array
*/
@@ -815,7 +815,7 @@ static VALUE cParser_parse(VALUE self)
}
-static JSON_Parser *JSON_allocate()
+static JSON_Parser *JSON_allocate(void)
{
JSON_Parser *json = ALLOC(JSON_Parser);
MEMZERO(json, JSON_Parser, 1);
@@ -823,8 +823,9 @@ static JSON_Parser *JSON_allocate()
return json;
}
-static void JSON_mark(JSON_Parser *json)
+static void JSON_mark(void *ptr)
{
+ JSON_Parser *json = ptr;
rb_gc_mark_maybe(json->Vsource);
rb_gc_mark_maybe(json->create_id);
rb_gc_mark_maybe(json->object_class);
@@ -832,16 +833,34 @@ static void JSON_mark(JSON_Parser *json)
rb_gc_mark_maybe(json->match_string);
}
-static void JSON_free(JSON_Parser *json)
+static void JSON_free(void *ptr)
{
+ JSON_Parser *json = ptr;
fbuffer_free(json->fbuffer);
ruby_xfree(json);
}
+static size_t JSON_memsize(const void *ptr)
+{
+ const JSON_Parser *json = ptr;
+ return sizeof(*json) + FBUFFER_CAPA(json->fbuffer);
+}
+
+#ifdef NEW_TYPEDDATA_WRAPPER
+static const rb_data_type_t JSON_Parser_type = {
+ "JSON/Parser",
+ {JSON_mark, JSON_free, JSON_memsize,},
+#ifdef RUBY_TYPED_FREE_IMMEDIATELY
+ 0, 0,
+ RUBY_TYPED_FREE_IMMEDIATELY,
+#endif
+};
+#endif
+
static VALUE cJSON_parser_s_allocate(VALUE klass)
{
JSON_Parser *json = JSON_allocate();
- return Data_Wrap_Struct(klass, JSON_mark, JSON_free, json);
+ return TypedData_Wrap_Struct(klass, &JSON_Parser_type, json);
}
/*
diff --git a/ext/json/extconf.rb b/ext/json/extconf.rb
new file mode 100644
index 0000000..850798c
--- /dev/null
+++ b/ext/json/extconf.rb
@@ -0,0 +1,3 @@
+require 'mkmf'
+create_makefile('json')
+
diff --git a/java/src/json/ext/Parser.java b/java/src/json/ext/Parser.java
index 6cb5886..37423f5 100644
--- a/java/src/json/ext/Parser.java
+++ b/java/src/json/ext/Parser.java
@@ -130,7 +130,7 @@ public class Parser extends RubyObject {
*
* <dt><code>:create_additions</code>
* <dd>If set to <code>false</code>, the Parser doesn't create additions
- * even if a matchin class and <code>create_id</code> was found. This option
+ * even if a matching class and <code>create_id</code> was found. This option
* defaults to <code>true</code>.
*
* <dt><code>:object_class</code>
@@ -248,7 +248,7 @@ public class Parser extends RubyObject {
*/
@JRubyMethod
public IRubyObject parse(ThreadContext context) {
- return new ParserSession(this, context).parse();
+ return new ParserSession(this, context, info).parse();
}
/**
@@ -304,6 +304,7 @@ public class Parser extends RubyObject {
private static class ParserSession {
private final Parser parser;
private final ThreadContext context;
+ private final RuntimeInfo info;
private final ByteList byteList;
private final ByteList view;
private final byte[] data;
@@ -315,9 +316,10 @@ public class Parser extends RubyObject {
// no idea about the origins of this value, ask Flori ;)
private static final int EVIL = 0x666;
- private ParserSession(Parser parser, ThreadContext context) {
+ private ParserSession(Parser parser, ThreadContext context, RuntimeInfo info) {
this.parser = parser;
this.context = context;
+ this.info = info;
this.byteList = parser.checkAndGetSource().getByteList();
this.data = byteList.unsafeBytes();
this.view = new ByteList(data, false);
@@ -337,11 +339,11 @@ public class Parser extends RubyObject {
}
-// line 363 "Parser.rl"
+// line 365 "Parser.rl"
-// line 345 "Parser.java"
+// line 347 "Parser.java"
private static byte[] init__JSON_value_actions_0()
{
return new byte [] {
@@ -455,7 +457,7 @@ static final int JSON_value_error = 0;
static final int JSON_value_en_main = 1;
-// line 469 "Parser.rl"
+// line 471 "Parser.rl"
void parseValue(ParserResult res, int p, int pe) {
@@ -463,14 +465,14 @@ static final int JSON_value_en_main = 1;
IRubyObject result = null;
-// line 467 "Parser.java"
+// line 469 "Parser.java"
{
cs = JSON_value_start;
}
-// line 476 "Parser.rl"
+// line 478 "Parser.rl"
-// line 474 "Parser.java"
+// line 476 "Parser.java"
{
int _klen;
int _trans = 0;
@@ -496,13 +498,13 @@ case 1:
while ( _nacts-- > 0 ) {
switch ( _JSON_value_actions[_acts++] ) {
case 9:
-// line 454 "Parser.rl"
+// line 456 "Parser.rl"
{
p--;
{ p += 1; _goto_targ = 5; if (true) continue _goto;}
}
break;
-// line 506 "Parser.java"
+// line 508 "Parser.java"
}
}
@@ -565,25 +567,25 @@ case 1:
switch ( _JSON_value_actions[_acts++] )
{
case 0:
-// line 371 "Parser.rl"
+// line 373 "Parser.rl"
{
result = getRuntime().getNil();
}
break;
case 1:
-// line 374 "Parser.rl"
+// line 376 "Parser.rl"
{
result = getRuntime().getFalse();
}
break;
case 2:
-// line 377 "Parser.rl"
+// line 379 "Parser.rl"
{
result = getRuntime().getTrue();
}
break;
case 3:
-// line 380 "Parser.rl"
+// line 382 "Parser.rl"
{
if (parser.allowNaN) {
result = getConstant(CONST_NAN);
@@ -593,7 +595,7 @@ case 1:
}
break;
case 4:
-// line 387 "Parser.rl"
+// line 389 "Parser.rl"
{
if (parser.allowNaN) {
result = getConstant(CONST_INFINITY);
@@ -603,7 +605,7 @@ case 1:
}
break;
case 5:
-// line 394 "Parser.rl"
+// line 396 "Parser.rl"
{
if (pe > p + 9 - (parser.quirksMode ? 1 : 0) &&
absSubSequence(p, p + 9).equals(JSON_MINUS_INFINITY)) {
@@ -632,7 +634,7 @@ case 1:
}
break;
case 6:
-// line 420 "Parser.rl"
+// line 422 "Parser.rl"
{
parseString(res, p, pe);
if (res.result == null) {
@@ -645,7 +647,7 @@ case 1:
}
break;
case 7:
-// line 430 "Parser.rl"
+// line 432 "Parser.rl"
{
currentNesting++;
parseArray(res, p, pe);
@@ -660,7 +662,7 @@ case 1:
}
break;
case 8:
-// line 442 "Parser.rl"
+// line 444 "Parser.rl"
{
currentNesting++;
parseObject(res, p, pe);
@@ -674,7 +676,7 @@ case 1:
}
}
break;
-// line 678 "Parser.java"
+// line 680 "Parser.java"
}
}
}
@@ -694,7 +696,7 @@ case 5:
break; }
}
-// line 477 "Parser.rl"
+// line 479 "Parser.rl"
if (cs >= JSON_value_first_final && result != null) {
res.update(result, p);
@@ -704,7 +706,7 @@ case 5:
}
-// line 708 "Parser.java"
+// line 710 "Parser.java"
private static byte[] init__JSON_integer_actions_0()
{
return new byte [] {
@@ -803,7 +805,7 @@ static final int JSON_integer_error = 0;
static final int JSON_integer_en_main = 1;
-// line 496 "Parser.rl"
+// line 498 "Parser.rl"
void parseInteger(ParserResult res, int p, int pe) {
@@ -821,15 +823,15 @@ static final int JSON_integer_en_main = 1;
int cs = EVIL;
-// line 825 "Parser.java"
+// line 827 "Parser.java"
{
cs = JSON_integer_start;
}
-// line 513 "Parser.rl"
+// line 515 "Parser.rl"
int memo = p;
-// line 833 "Parser.java"
+// line 835 "Parser.java"
{
int _klen;
int _trans = 0;
@@ -910,13 +912,13 @@ case 1:
switch ( _JSON_integer_actions[_acts++] )
{
case 0:
-// line 490 "Parser.rl"
+// line 492 "Parser.rl"
{
p--;
{ p += 1; _goto_targ = 5; if (true) continue _goto;}
}
break;
-// line 920 "Parser.java"
+// line 922 "Parser.java"
}
}
}
@@ -936,7 +938,7 @@ case 5:
break; }
}
-// line 515 "Parser.rl"
+// line 517 "Parser.rl"
if (cs < JSON_integer_first_final) {
return -1;
@@ -958,7 +960,7 @@ case 5:
}
-// line 962 "Parser.java"
+// line 964 "Parser.java"
private static byte[] init__JSON_float_actions_0()
{
return new byte [] {
@@ -1060,7 +1062,7 @@ static final int JSON_float_error = 0;
static final int JSON_float_en_main = 1;
-// line 550 "Parser.rl"
+// line 552 "Parser.rl"
void parseFloat(ParserResult res, int p, int pe) {
@@ -1078,15 +1080,15 @@ static final int JSON_float_en_main = 1;
int cs = EVIL;
-// line 1082 "Parser.java"
+// line 1084 "Parser.java"
{
cs = JSON_float_start;
}
-// line 567 "Parser.rl"
+// line 569 "Parser.rl"
int memo = p;
-// line 1090 "Parser.java"
+// line 1092 "Parser.java"
{
int _klen;
int _trans = 0;
@@ -1167,13 +1169,13 @@ case 1:
switch ( _JSON_float_actions[_acts++] )
{
case 0:
-// line 541 "Parser.rl"
+// line 543 "Parser.rl"
{
p--;
{ p += 1; _goto_targ = 5; if (true) continue _goto;}
}
break;
-// line 1177 "Parser.java"
+// line 1179 "Parser.java"
}
}
}
@@ -1193,7 +1195,7 @@ case 5:
break; }
}
-// line 569 "Parser.rl"
+// line 571 "Parser.rl"
if (cs < JSON_float_first_final) {
return -1;
@@ -1209,7 +1211,7 @@ case 5:
}
-// line 1213 "Parser.java"
+// line 1215 "Parser.java"
private static byte[] init__JSON_string_actions_0()
{
return new byte [] {
@@ -1311,7 +1313,7 @@ static final int JSON_string_error = 0;
static final int JSON_string_en_main = 1;
-// line 614 "Parser.rl"
+// line 616 "Parser.rl"
void parseString(ParserResult res, int p, int pe) {
@@ -1319,15 +1321,15 @@ static final int JSON_string_en_main = 1;
IRubyObject result = null;
-// line 1323 "Parser.java"
+// line 1325 "Parser.java"
{
cs = JSON_string_start;
}
-// line 621 "Parser.rl"
+// line 623 "Parser.rl"
int memo = p;
-// line 1331 "Parser.java"
+// line 1333 "Parser.java"
{
int _klen;
int _trans = 0;
@@ -1408,7 +1410,7 @@ case 1:
switch ( _JSON_string_actions[_acts++] )
{
case 0:
-// line 589 "Parser.rl"
+// line 591 "Parser.rl"
{
int offset = byteList.begin();
ByteList decoded = decoder.decode(byteList, memo + 1 - offset,
@@ -1423,13 +1425,13 @@ case 1:
}
break;
case 1:
-// line 602 "Parser.rl"
+// line 604 "Parser.rl"
{
p--;
{ p += 1; _goto_targ = 5; if (true) continue _goto;}
}
break;
-// line 1433 "Parser.java"
+// line 1435 "Parser.java"
}
}
}
@@ -1449,7 +1451,7 @@ case 5:
break; }
}
-// line 623 "Parser.rl"
+// line 625 "Parser.rl"
if (parser.createAdditions) {
RubyHash match_string = parser.match_string;
@@ -1476,8 +1478,7 @@ case 5:
}
}
- if (cs >= JSON_string_first_final && result != null) {
- RuntimeInfo info = RuntimeInfo.forRuntime(context.getRuntime());
+ if (cs >= JSON_string_first_final && result != null) {
if (info.encodingsSupported() && result instanceof RubyString) {
((RubyString)result).force_encoding(context, info.utf8.get());
}
@@ -1488,7 +1489,7 @@ case 5:
}
-// line 1492 "Parser.java"
+// line 1493 "Parser.java"
private static byte[] init__JSON_array_actions_0()
{
return new byte [] {
@@ -1601,7 +1602,7 @@ static final int JSON_array_error = 0;
static final int JSON_array_en_main = 1;
-// line 697 "Parser.rl"
+// line 698 "Parser.rl"
void parseArray(ParserResult res, int p, int pe) {
@@ -1621,14 +1622,14 @@ static final int JSON_array_en_main = 1;
}
-// line 1625 "Parser.java"
+// line 1626 "Parser.java"
{
cs = JSON_array_start;
}
-// line 716 "Parser.rl"
+// line 717 "Parser.rl"
-// line 1632 "Parser.java"
+// line 1633 "Parser.java"
{
int _klen;
int _trans = 0;
@@ -1709,7 +1710,7 @@ case 1:
switch ( _JSON_array_actions[_acts++] )
{
case 0:
-// line 666 "Parser.rl"
+// line 667 "Parser.rl"
{
parseValue(res, p, pe);
if (res.result == null) {
@@ -1726,13 +1727,13 @@ case 1:
}
break;
case 1:
-// line 681 "Parser.rl"
+// line 682 "Parser.rl"
{
p--;
{ p += 1; _goto_targ = 5; if (true) continue _goto;}
}
break;
-// line 1736 "Parser.java"
+// line 1737 "Parser.java"
}
}
}
@@ -1752,7 +1753,7 @@ case 5:
break; }
}
-// line 717 "Parser.rl"
+// line 718 "Parser.rl"
if (cs >= JSON_array_first_final) {
res.update(result, p + 1);
@@ -1762,7 +1763,7 @@ case 5:
}
-// line 1766 "Parser.java"
+// line 1767 "Parser.java"
private static byte[] init__JSON_object_actions_0()
{
return new byte [] {
@@ -1885,7 +1886,7 @@ static final int JSON_object_error = 0;
static final int JSON_object_en_main = 1;
-// line 776 "Parser.rl"
+// line 777 "Parser.rl"
void parseObject(ParserResult res, int p, int pe) {
@@ -1910,14 +1911,14 @@ static final int JSON_object_en_main = 1;
}
-// line 1914 "Parser.java"
+// line 1915 "Parser.java"
{
cs = JSON_object_start;
}
-// line 800 "Parser.rl"
+// line 801 "Parser.rl"
-// line 1921 "Parser.java"
+// line 1922 "Parser.java"
{
int _klen;
int _trans = 0;
@@ -1998,7 +1999,7 @@ case 1:
switch ( _JSON_object_actions[_acts++] )
{
case 0:
-// line 731 "Parser.rl"
+// line 732 "Parser.rl"
{
parseValue(res, p, pe);
if (res.result == null) {
@@ -2015,7 +2016,7 @@ case 1:
}
break;
case 1:
-// line 746 "Parser.rl"
+// line 747 "Parser.rl"
{
parseString(res, p, pe);
if (res.result == null) {
@@ -2035,13 +2036,13 @@ case 1:
}
break;
case 2:
-// line 764 "Parser.rl"
+// line 765 "Parser.rl"
{
p--;
{ p += 1; _goto_targ = 5; if (true) continue _goto;}
}
break;
-// line 2045 "Parser.java"
+// line 2046 "Parser.java"
}
}
}
@@ -2061,7 +2062,7 @@ case 5:
break; }
}
-// line 801 "Parser.rl"
+// line 802 "Parser.rl"
if (cs < JSON_object_first_final) {
res.update(null, p + 1);
@@ -2094,7 +2095,7 @@ case 5:
}
-// line 2098 "Parser.java"
+// line 2099 "Parser.java"
private static byte[] init__JSON_actions_0()
{
return new byte [] {
@@ -2198,7 +2199,7 @@ static final int JSON_error = 0;
static final int JSON_en_main = 1;
-// line 866 "Parser.rl"
+// line 867 "Parser.rl"
public IRubyObject parseStrict() {
@@ -2208,16 +2209,16 @@ static final int JSON_en_main = 1;
ParserResult res = new ParserResult();
-// line 2212 "Parser.java"
+// line 2213 "Parser.java"
{
cs = JSON_start;
}
-// line 875 "Parser.rl"
+// line 876 "Parser.rl"
p = byteList.begin();
pe = p + byteList.length();
-// line 2221 "Parser.java"
+// line 2222 "Parser.java"
{
int _klen;
int _trans = 0;
@@ -2298,7 +2299,7 @@ case 1:
switch ( _JSON_actions[_acts++] )
{
case 0:
-// line 838 "Parser.rl"
+// line 839 "Parser.rl"
{
currentNesting = 1;
parseObject(res, p, pe);
@@ -2312,7 +2313,7 @@ case 1:
}
break;
case 1:
-// line 850 "Parser.rl"
+// line 851 "Parser.rl"
{
currentNesting = 1;
parseArray(res, p, pe);
@@ -2325,7 +2326,7 @@ case 1:
}
}
break;
-// line 2329 "Parser.java"
+// line 2330 "Parser.java"
}
}
}
@@ -2345,7 +2346,7 @@ case 5:
break; }
}
-// line 878 "Parser.rl"
+// line 879 "Parser.rl"
if (cs >= JSON_first_final && p == pe) {
return result;
@@ -2355,7 +2356,7 @@ case 5:
}
-// line 2359 "Parser.java"
+// line 2360 "Parser.java"
private static byte[] init__JSON_quirks_mode_actions_0()
{
return new byte [] {
@@ -2458,7 +2459,7 @@ static final int JSON_quirks_mode_error = 0;
static final int JSON_quirks_mode_en_main = 1;
-// line 906 "Parser.rl"
+// line 907 "Parser.rl"
public IRubyObject parseQuirksMode() {
@@ -2468,16 +2469,16 @@ static final int JSON_quirks_mode_en_main = 1;
ParserResult res = new ParserResult();
-// line 2472 "Parser.java"
+// line 2473 "Parser.java"
{
cs = JSON_quirks_mode_start;
}
-// line 915 "Parser.rl"
+// line 916 "Parser.rl"
p = byteList.begin();
pe = p + byteList.length();
-// line 2481 "Parser.java"
+// line 2482 "Parser.java"
{
int _klen;
int _trans = 0;
@@ -2558,7 +2559,7 @@ case 1:
switch ( _JSON_quirks_mode_actions[_acts++] )
{
case 0:
-// line 892 "Parser.rl"
+// line 893 "Parser.rl"
{
parseValue(res, p, pe);
if (res.result == null) {
@@ -2570,7 +2571,7 @@ case 1:
}
}
break;
-// line 2574 "Parser.java"
+// line 2575 "Parser.java"
}
}
}
@@ -2590,7 +2591,7 @@ case 5:
break; }
}
-// line 918 "Parser.rl"
+// line 919 "Parser.rl"
if (cs >= JSON_quirks_mode_first_final && p == pe) {
return result;
diff --git a/java/src/json/ext/Parser.rl b/java/src/json/ext/Parser.rl
index 7dcdd2e..6d65963 100644
--- a/java/src/json/ext/Parser.rl
+++ b/java/src/json/ext/Parser.rl
@@ -246,7 +246,7 @@ public class Parser extends RubyObject {
*/
@JRubyMethod
public IRubyObject parse(ThreadContext context) {
- return new ParserSession(this, context).parse();
+ return new ParserSession(this, context, info).parse();
}
/**
@@ -302,6 +302,7 @@ public class Parser extends RubyObject {
private static class ParserSession {
private final Parser parser;
private final ThreadContext context;
+ private final RuntimeInfo info;
private final ByteList byteList;
private final ByteList view;
private final byte[] data;
@@ -313,9 +314,10 @@ public class Parser extends RubyObject {
// no idea about the origins of this value, ask Flori ;)
private static final int EVIL = 0x666;
- private ParserSession(Parser parser, ThreadContext context) {
+ private ParserSession(Parser parser, ThreadContext context, RuntimeInfo info) {
this.parser = parser;
this.context = context;
+ this.info = info;
this.byteList = parser.checkAndGetSource().getByteList();
this.data = byteList.unsafeBytes();
this.view = new ByteList(data, false);
@@ -646,8 +648,7 @@ public class Parser extends RubyObject {
}
}
- if (cs >= JSON_string_first_final && result != null) {
- RuntimeInfo info = RuntimeInfo.forRuntime(context.getRuntime());
+ if (cs >= JSON_string_first_final && result != null) {
if (info.encodingsSupported() && result instanceof RubyString) {
((RubyString)result).force_encoding(context, info.utf8.get());
}
diff --git a/json.gemspec b/json.gemspec
index 259b236..9fbc284 100644
--- a/json.gemspec
+++ b/json.gemspec
Binary files differ
diff --git a/json_pure.gemspec b/json_pure.gemspec
index 40f5902..9847e5e 100644
--- a/json_pure.gemspec
+++ b/json_pure.gemspec
@@ -8,15 +8,15 @@ Gem::Specification.new do |s|
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 = "2014-07-03"
+ s.date = "2015-01-02"
s.description = "This is a JSON implementation in pure Ruby."
s.email = "flori@ping.de"
s.extra_rdoc_files = ["README.rdoc"]
- s.files = ["./tests/test_json.rb", "./tests/test_json_addition.rb", "./tests/test_json_encoding.rb", "./tests/test_json_fixtures.rb", "./tests/test_json_generate.rb", "./tests/test_json_generic_object.rb", "./tests/test_json_string_matching.rb", "./tests/test_json_unicode.rb", ".gitignore", ".travis.yml", "CHANGES", "COPYING", "COPYING-json-jruby", "GPL", "Gemfile", "README-json-jruby.markdown", "README.rdoc", "Rakefile", "TODO", "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", "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", "tests/fixtures/fail1.json", "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/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/setup_variant.rb", "tests/test_json.rb", "tests/test_json_addition.rb", "tests/test_json_encoding.rb", "tests/test_json_fixtures.rb", "tests/test_json_generate.rb", "tests/test_json_generic_object.rb", "tests/test_json_string_matching.rb", "tests/test_json_unicode.rb", "tools/fuzz.rb", "tools/server.rb"]
+ s.files = ["./tests/test_json.rb", "./tests/test_json_addition.rb", "./tests/test_json_encoding.rb", "./tests/test_json_fixtures.rb", "./tests/test_json_generate.rb", "./tests/test_json_generic_object.rb", "./tests/test_json_string_matching.rb", "./tests/test_json_unicode.rb", ".gitignore", ".travis.yml", "CHANGES", "COPYING", "COPYING-json-jruby", "GPL", "Gemfile", "README-json-jruby.markdown", "README.rdoc", "Rakefile", "TODO", "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", "tests/fixtures/fail1.json", "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/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/setup_variant.rb", "tests/test_json.rb", "tests/test_json_addition.rb", "tests/test_json_encoding.rb", "tests/test_json_fixtures.rb", "tests/test_json_generate.rb", "tests/test_json_generic_object.rb", "tests/test_json_string_matching.rb", "tests/test_json_unicode.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.rdoc"]
- s.rubygems_version = "2.2.2"
+ s.rubygems_version = "2.4.5"
s.summary = "JSON Implementation for Ruby"
s.test_files = ["./tests/test_json.rb", "./tests/test_json_addition.rb", "./tests/test_json_encoding.rb", "./tests/test_json_fixtures.rb", "./tests/test_json_generate.rb", "./tests/test_json_generic_object.rb", "./tests/test_json_string_matching.rb", "./tests/test_json_unicode.rb"]
diff --git a/lib/json/common.rb b/lib/json/common.rb
index 32d9892..f44184e 100644
--- a/lib/json/common.rb
+++ b/lib/json/common.rb
@@ -448,7 +448,7 @@ module ::Kernel
nil
end
- # Ouputs _objs_ to STDOUT as JSON strings in a pretty format, with
+ # Outputs _objs_ to STDOUT as JSON strings in a pretty format, with
# indentation and over many lines.
def jj(*objs)
objs.each do |obj|
diff --git a/tests/test_json.rb b/tests/test_json.rb
index f4e6696..7957773 100755
--- a/tests/test_json.rb
+++ b/tests/test_json.rb
@@ -491,6 +491,8 @@ EOT
assert_equal @hash, JSON.load(stringio)
assert_equal nil, JSON.load(nil)
assert_equal nil, JSON.load('')
+ ensure
+ tempfile.close!
end
def test_load_with_options
diff --git a/tests/test_json_generate.rb b/tests/test_json_generate.rb
index 117a155..ea6a9a3 100755
--- a/tests/test_json_generate.rb
+++ b/tests/test_json_generate.rb
@@ -215,16 +215,18 @@ EOT
end
def test_gc
- bignum_too_long_to_embed_as_string = 1234567890123456789012345
- expect = bignum_too_long_to_embed_as_string.to_s
- stress, GC.stress = GC.stress, true
+ if respond_to?(:assert_in_out_err)
+ assert_in_out_err(%w[-rjson --disable-gems], <<-EOS, [], [])
+ bignum_too_long_to_embed_as_string = 1234567890123456789012345
+ expect = bignum_too_long_to_embed_as_string.to_s
+ GC.stress = true
- 10.times do |i|
- tmp = bignum_too_long_to_embed_as_string.to_json
- assert_equal expect, tmp
+ 10.times do |i|
+ tmp = bignum_too_long_to_embed_as_string.to_json
+ raise "'\#{expect}' is expected, but '\#{tmp}'" unless tmp == expect
+ end
+ EOS
end
- ensure
- GC.stress = stress
end if GC.respond_to?(:stress=)
def test_configure_using_configure_and_merge