From 18b3000090d1044425d369a58ebe52f5342b9699 Mon Sep 17 00:00:00 2001 From: Zachary Scott Date: Thu, 25 Dec 2014 15:43:37 -0500 Subject: Sync with trunk --- ext/json/ext/parser/parser.rl | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'ext/json/ext/parser/parser.rl') 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); } /* -- cgit v1.2.1