summaryrefslogtreecommitdiff
path: root/ext/json/ext/parser/parser.rl
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 /ext/json/ext/parser/parser.rl
parent17fe8e72f484e65e0c36670946934d1f8696e37b (diff)
downloadjson-18b3000090d1044425d369a58ebe52f5342b9699.tar.gz
Sync with trunk
Diffstat (limited to 'ext/json/ext/parser/parser.rl')
-rw-r--r--ext/json/ext/parser/parser.rl25
1 files changed, 20 insertions, 5 deletions
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);
}
/*