summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZachary Scott <e@zzak.io>2014-12-25 15:43:37 -0500
committerZachary Scott <e@zzak.io>2014-12-25 15:43:37 -0500
commit18b3000090d1044425d369a58ebe52f5342b9699 (patch)
treebf0bd35737237b5f178461c969c017fa39a5f51c
parent17fe8e72f484e65e0c36670946934d1f8696e37b (diff)
downloadjson-18b3000090d1044425d369a58ebe52f5342b9699.tar.gz
Sync with trunk
-rw-r--r--ext/json/ext/fbuffer/fbuffer.h11
-rw-r--r--ext/json/ext/generator/depend20
-rw-r--r--ext/json/ext/generator/extconf.rb10
-rw-r--r--ext/json/ext/generator/generator.c63
-rw-r--r--ext/json/ext/generator/generator.h14
-rw-r--r--ext/json/ext/parser/depend19
-rw-r--r--ext/json/ext/parser/extconf.rb10
-rw-r--r--ext/json/ext/parser/parser.c93
-rw-r--r--ext/json/ext/parser/parser.h9
-rw-r--r--ext/json/ext/parser/parser.rl25
-rw-r--r--ext/json/ext/parser/prereq.mk10
-rw-r--r--lib/json/add/complex.rb8
-rw-r--r--lib/json/add/rational.rb5
-rw-r--r--lib/json/add/time.rb2
-rw-r--r--lib/json/common.rb10
15 files changed, 197 insertions, 112 deletions
diff --git a/ext/json/ext/fbuffer/fbuffer.h b/ext/json/ext/fbuffer/fbuffer.h
index af74187..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())
@@ -172,7 +181,7 @@ static FBuffer *fbuffer_dup(FBuffer *fb)
static VALUE fbuffer_to_s(FBuffer *fb)
{
- VALUE result = rb_str_new(FBUFFER_PAIR(fb));
+ VALUE result = rb_str_new(FBUFFER_PTR(fb), FBUFFER_LEN(fb));
fbuffer_free(fb);
FORCE_UTF8(result);
return result;
diff --git a/ext/json/ext/generator/depend b/ext/json/ext/generator/depend
index 1a042a2..b7373cd 100644
--- a/ext/json/ext/generator/depend
+++ b/ext/json/ext/generator/depend
@@ -1 +1,21 @@
+$(OBJS): $(ruby_headers)
generator.o: generator.c generator.h $(srcdir)/../fbuffer/fbuffer.h
+
+# AUTOGENERATED DEPENDENCIES START
+generator.o: $(RUBY_EXTCONF_H)
+generator.o: $(arch_hdrdir)/ruby/config.h
+generator.o: $(hdrdir)/ruby/defines.h
+generator.o: $(hdrdir)/ruby/encoding.h
+generator.o: $(hdrdir)/ruby/intern.h
+generator.o: $(hdrdir)/ruby/missing.h
+generator.o: $(hdrdir)/ruby/oniguruma.h
+generator.o: $(hdrdir)/ruby/re.h
+generator.o: $(hdrdir)/ruby/regex.h
+generator.o: $(hdrdir)/ruby/ruby.h
+generator.o: $(hdrdir)/ruby/st.h
+generator.o: $(hdrdir)/ruby/subst.h
+generator.o: $(top_srcdir)/ext/json/fbuffer/fbuffer.h
+generator.o: $(top_srcdir)/include/ruby.h
+generator.o: generator.c
+generator.o: generator.h
+# AUTOGENERATED DEPENDENCIES END
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..f56ac09 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,17 +500,38 @@ 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)
{
- JSON_Generator_State *state = ALLOC(JSON_Generator_State);
- MEMZERO(state, JSON_Generator_State, 1);
+ 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;
+}
+
+static const rb_data_type_t JSON_Generator_State_type = {
+ "JSON/Generator/State",
+ {NULL, State_free, State_memsize,},
+ 0, 0,
+ RUBY_TYPED_FREE_IMMEDIATELY,
+};
+
+static JSON_Generator_State *State_allocate(void)
+{
+ JSON_Generator_State *state = ZALLOC(JSON_Generator_State);
return state;
}
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);
}
/*
@@ -646,7 +668,7 @@ static VALUE cState_to_h(VALUE self)
/*
* call-seq: [](name)
*
-* Returns the value returned by method +name+.
+* Return the value returned by method +name+.
*/
static VALUE cState_aref(VALUE self, VALUE name)
{
@@ -661,7 +683,7 @@ static VALUE cState_aref(VALUE self, VALUE name)
/*
* call-seq: []=(name, value)
*
-* Sets the attribute name to value.
+* Set the attribute name to value.
*/
static VALUE cState_aset(VALUE self, VALUE name, VALUE value)
{
@@ -812,10 +834,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);
@@ -958,15 +980,16 @@ static VALUE cState_initialize(int argc, VALUE *argv, VALUE self)
/*
* call-seq: initialize_copy(orig)
*
- * Initializes this object from orig if it can be duplicated/cloned and returns
+ * Initializes this object from orig if it to be duplicated/cloned and returns
* it.
*/
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);
@@ -1005,7 +1028,7 @@ static VALUE cState_from_state_s(VALUE self, VALUE opts)
/*
* call-seq: indent()
*
- * Returns the string that is used to indent levels in the JSON text.
+ * This string is used to indent levels in the JSON text.
*/
static VALUE cState_indent(VALUE self)
{
@@ -1016,7 +1039,7 @@ static VALUE cState_indent(VALUE self)
/*
* call-seq: indent=(indent)
*
- * Sets the string that is used to indent levels in the JSON text.
+ * This string is used to indent levels in the JSON text.
*/
static VALUE cState_indent_set(VALUE self, VALUE indent)
{
@@ -1041,7 +1064,7 @@ static VALUE cState_indent_set(VALUE self, VALUE indent)
/*
* call-seq: space()
*
- * Returns the string that is used to insert a space between the tokens in a JSON
+ * This string is used to insert a space between the tokens in a JSON
* string.
*/
static VALUE cState_space(VALUE self)
@@ -1053,7 +1076,7 @@ static VALUE cState_space(VALUE self)
/*
* call-seq: space=(space)
*
- * Sets _space_ to the string that is used to insert a space between the tokens in a JSON
+ * This string is used to insert a space between the tokens in a JSON
* string.
*/
static VALUE cState_space_set(VALUE self, VALUE space)
@@ -1079,7 +1102,7 @@ static VALUE cState_space_set(VALUE self, VALUE space)
/*
* call-seq: space_before()
*
- * Returns the string that is used to insert a space before the ':' in JSON objects.
+ * This string is used to insert a space before the ':' in JSON objects.
*/
static VALUE cState_space_before(VALUE self)
{
@@ -1090,7 +1113,7 @@ static VALUE cState_space_before(VALUE self)
/*
* call-seq: space_before=(space_before)
*
- * Sets the string that is used to insert a space before the ':' in JSON objects.
+ * This string is used to insert a space before the ':' in JSON objects.
*/
static VALUE cState_space_before_set(VALUE self, VALUE space_before)
{
@@ -1297,7 +1320,7 @@ static VALUE cState_depth_set(VALUE self, VALUE depth)
/*
* call-seq: buffer_initial_length
*
- * This integer returns the current initial length of the buffer.
+ * This integer returns the current inital length of the buffer.
*/
static VALUE cState_buffer_initial_length(VALUE self)
{
@@ -1326,7 +1349,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..ddd1aa8 100644
--- a/ext/json/ext/generator/generator.h
+++ b/ext/json/ext/generator/generator.h
@@ -23,7 +23,7 @@
#define option_given_p(opts, key) RTEST(rb_funcall(opts, i_key_p, 1, key))
-/* unicode definitions */
+/* unicode defintions */
#define UNI_STRICT_CONVERSION 1
@@ -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,6 @@ 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);
+static const rb_data_type_t JSON_Generator_State_type;
#endif
diff --git a/ext/json/ext/parser/depend b/ext/json/ext/parser/depend
index 498ffa9..bc5db06 100644
--- a/ext/json/ext/parser/depend
+++ b/ext/json/ext/parser/depend
@@ -1 +1,20 @@
+$(OBJS): $(ruby_headers)
parser.o: parser.c parser.h $(srcdir)/../fbuffer/fbuffer.h
+
+# AUTOGENERATED DEPENDENCIES START
+parser.o: $(RUBY_EXTCONF_H)
+parser.o: $(arch_hdrdir)/ruby/config.h
+parser.o: $(hdrdir)/ruby/defines.h
+parser.o: $(hdrdir)/ruby/encoding.h
+parser.o: $(hdrdir)/ruby/intern.h
+parser.o: $(hdrdir)/ruby/missing.h
+parser.o: $(hdrdir)/ruby/oniguruma.h
+parser.o: $(hdrdir)/ruby/ruby.h
+parser.o: $(hdrdir)/ruby/st.h
+parser.o: $(hdrdir)/ruby/subst.h
+parser.o: $(top_srcdir)/ext/json/fbuffer/fbuffer.h
+parser.o: $(top_srcdir)/include/ruby.h
+parser.o: parser.c
+parser.o: parser.h
+parser.o: parser.rl
+# AUTOGENERATED DEPENDENCIES END
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..560aa89 100644
--- a/ext/json/ext/parser/parser.c
+++ b/ext/json/ext/parser/parser.c
@@ -89,11 +89,11 @@ static ID i_json_creatable_p, i_json_create, i_create_id, i_create_additions,
#line 92 "parser.c"
-static const int JSON_object_start = 1;
-static const int JSON_object_first_final = 27;
-static const int JSON_object_error = 0;
+enum {JSON_object_start = 1};
+enum {JSON_object_first_final = 27};
+enum {JSON_object_error = 0};
-static const int JSON_object_en_main = 1;
+enum {JSON_object_en_main = 1};
#line 151 "parser.rl"
@@ -467,11 +467,11 @@ case 26:
#line 470 "parser.c"
-static const int JSON_value_start = 1;
-static const int JSON_value_first_final = 21;
-static const int JSON_value_error = 0;
+enum {JSON_value_start = 1};
+enum {JSON_value_first_final = 21};
+enum {JSON_value_error = 0};
-static const int JSON_value_en_main = 1;
+enum {JSON_value_en_main = 1};
#line 271 "parser.rl"
@@ -776,11 +776,11 @@ case 20:
#line 779 "parser.c"
-static const int JSON_integer_start = 1;
-static const int JSON_integer_first_final = 3;
-static const int JSON_integer_error = 0;
+enum {JSON_integer_start = 1};
+enum {JSON_integer_first_final = 3};
+enum {JSON_integer_error = 0};
-static const int JSON_integer_en_main = 1;
+enum {JSON_integer_en_main = 1};
#line 295 "parser.rl"
@@ -875,11 +875,11 @@ case 5:
#line 878 "parser.c"
-static const int JSON_float_start = 1;
-static const int JSON_float_first_final = 8;
-static const int JSON_float_error = 0;
+enum {JSON_float_start = 1};
+enum {JSON_float_first_final = 8};
+enum {JSON_float_error = 0};
-static const int JSON_float_en_main = 1;
+enum {JSON_float_en_main = 1};
#line 329 "parser.rl"
@@ -1041,11 +1041,11 @@ case 7:
#line 1044 "parser.c"
-static const int JSON_array_start = 1;
-static const int JSON_array_first_final = 17;
-static const int JSON_array_error = 0;
+enum {JSON_array_start = 1};
+enum {JSON_array_first_final = 17};
+enum {JSON_array_error = 0};
-static const int JSON_array_en_main = 1;
+enum {JSON_array_en_main = 1};
#line 381 "parser.rl"
@@ -1373,11 +1373,11 @@ static VALUE json_string_unescape(VALUE result, char *string, char *stringEnd)
#line 1376 "parser.c"
-static const int JSON_string_start = 1;
-static const int JSON_string_first_final = 8;
-static const int JSON_string_error = 0;
+enum {JSON_string_start = 1};
+enum {JSON_string_first_final = 8};
+enum {JSON_string_error = 0};
-static const int JSON_string_en_main = 1;
+enum {JSON_string_en_main = 1};
#line 494 "parser.rl"
@@ -1626,8 +1626,8 @@ static VALUE convert_encoding(VALUE source)
* (keys) in a JSON object. Otherwise strings are returned, which is also
* 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 false.
+ * additions even if a matchin class and create_id was found. This option
+ * defaults to true.
* * *object_class*: Defaults to Hash
* * *array_class*: Defaults to Array
*/
@@ -1730,11 +1730,11 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
#line 1733 "parser.c"
-static const int JSON_start = 1;
-static const int JSON_first_final = 10;
-static const int JSON_error = 0;
+enum {JSON_start = 1};
+enum {JSON_first_final = 10};
+enum {JSON_error = 0};
-static const int JSON_en_main = 1;
+enum {JSON_en_main = 1};
#line 740 "parser.rl"
@@ -1904,11 +1904,11 @@ case 9:
#line 1907 "parser.c"
-static const int JSON_quirks_mode_start = 1;
-static const int JSON_quirks_mode_first_final = 10;
-static const int JSON_quirks_mode_error = 0;
+enum {JSON_quirks_mode_start = 1};
+enum {JSON_quirks_mode_first_final = 10};
+enum {JSON_quirks_mode_error = 0};
-static const int JSON_quirks_mode_en_main = 1;
+enum {JSON_quirks_mode_en_main = 1};
#line 778 "parser.rl"
@@ -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,30 @@ 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);
+}
+
+static const rb_data_type_t JSON_Parser_type = {
+ "JSON/Parser",
+ {JSON_mark, JSON_free, JSON_memsize,},
+ 0, 0,
+ RUBY_TYPED_FREE_IMMEDIATELY,
+};
+
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);
}
/*
@@ -2145,7 +2160,7 @@ static VALUE cParser_quirks_mode_p(VALUE self)
}
-void Init_parser()
+void Init_parser(void)
{
rb_require("json/common");
mJSON = rb_define_module("JSON");
diff --git a/ext/json/ext/parser/parser.h b/ext/json/ext/parser/parser.h
index b192064..45afbc2 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,11 @@ 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);
+static const rb_data_type_t JSON_Parser_type;
#endif
diff --git a/ext/json/ext/parser/parser.rl b/ext/json/ext/parser/parser.rl
index c60e35c..34e30f4 100644
--- a/ext/json/ext/parser/parser.rl
+++ b/ext/json/ext/parser/parser.rl
@@ -610,7 +610,7 @@ static VALUE convert_encoding(VALUE source)
* (keys) in a JSON object. Otherwise strings are returned, which is also
* 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
+ * additions even if a matchin class and create_id was found. This option
* defaults to true.
* * *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,30 @@ 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);
+}
+
+static const rb_data_type_t JSON_Parser_type = {
+ "JSON/Parser",
+ {JSON_mark, JSON_free, JSON_memsize,},
+ 0, 0,
+ RUBY_TYPED_FREE_IMMEDIATELY,
+};
+
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/prereq.mk b/ext/json/ext/parser/prereq.mk
new file mode 100644
index 0000000..be7bcb4
--- /dev/null
+++ b/ext/json/ext/parser/prereq.mk
@@ -0,0 +1,10 @@
+RAGEL = ragel
+
+.SUFFIXES: .rl
+
+.rl.c:
+ $(RAGEL) -G2 $<
+ $(BASERUBY) -pli -e '$$_.sub!(/[ \t]+$$/, "")' \
+ -e '$$_.sub!(/^static const int (JSON_.*=.*);$$/, "enum {\\1};")' $@
+
+parser.c:
diff --git a/lib/json/add/complex.rb b/lib/json/add/complex.rb
index 2723f60..d7ebebf 100644
--- a/lib/json/add/complex.rb
+++ b/lib/json/add/complex.rb
@@ -4,15 +4,10 @@ end
defined?(::Complex) or require 'complex'
class Complex
-
- # Deserializes JSON string by converting Real value <tt>r</tt>, imaginary
- # value <tt>i</tt>, to a Complex object.
def self.json_create(object)
Complex(object['r'], object['i'])
end
- # Returns a hash, that will be turned into a JSON object and represent this
- # object.
def as_json(*)
{
JSON.create_id => self.class.name,
@@ -21,8 +16,7 @@ class Complex
}
end
- # Stores class name (Complex) along with real value <tt>r</tt> and imaginary value <tt>i</tt> as JSON string
def to_json(*)
as_json.to_json
end
-end \ No newline at end of file
+end
diff --git a/lib/json/add/rational.rb b/lib/json/add/rational.rb
index ee39c20..867cd92 100644
--- a/lib/json/add/rational.rb
+++ b/lib/json/add/rational.rb
@@ -4,14 +4,10 @@ end
defined?(::Rational) or require 'rational'
class Rational
- # Deserializes JSON string by converting numerator value <tt>n</tt>,
- # denominator value <tt>d</tt>, to a Rational object.
def self.json_create(object)
Rational(object['n'], object['d'])
end
- # Returns a hash, that will be turned into a JSON object and represent this
- # object.
def as_json(*)
{
JSON.create_id => self.class.name,
@@ -20,7 +16,6 @@ class Rational
}
end
- # Stores class name (Rational) along with numerator value <tt>n</tt> and denominator value <tt>d</tt> as JSON string
def to_json(*)
as_json.to_json
end
diff --git a/lib/json/add/time.rb b/lib/json/add/time.rb
index d983467..338209d 100644
--- a/lib/json/add/time.rb
+++ b/lib/json/add/time.rb
@@ -10,7 +10,7 @@ class Time
if usec = object.delete('u') # used to be tv_usec -> tv_nsec
object['n'] = usec * 1000
end
- if method_defined?(:tv_nsec)
+ if instance_methods.include?(:tv_nsec)
at(object['s'], Rational(object['n'], 1000))
else
at(object['s'], object['n'] / 1000)
diff --git a/lib/json/common.rb b/lib/json/common.rb
index 32d9892..8fbaa2b 100644
--- a/lib/json/common.rb
+++ b/lib/json/common.rb
@@ -148,7 +148,7 @@ module JSON
# 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 false.
+ # defaults to true.
# * *object_class*: Defaults to Hash
# * *array_class*: Defaults to Array
def parse(source, opts = {})
@@ -169,7 +169,7 @@ module JSON
# to true.
# * *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 false.
+ # defaults to true.
def parse!(source, opts = {})
opts = {
:max_nesting => false,
@@ -390,7 +390,7 @@ module JSON
end
end
opts = JSON.dump_default_options
- opts = opts.merge(:max_nesting => limit) if limit
+ limit and opts.update(:max_nesting => limit)
result = generate(obj, opts)
if anIO
anIO.write result
@@ -411,7 +411,7 @@ module JSON
string
end
- # Shortcut for iconv.
+ # Shortuct for iconv.
if ::String.method_defined?(:encode)
# Encodes string using Ruby's _String.encode_
def self.iconv(to, from, string)
@@ -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|