summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-10-04 23:33:11 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-10-04 23:33:11 +0000
commit1e46f02394fdce76e51d5304f1ad1beffc0b9e77 (patch)
tree225ef956a25eb13d7087cb968f8175291396bb08 /ext
parentbdfc2e29420d360eebf9dd1cf23668750bb8c8e8 (diff)
json/parser: typed data
* ext/json/parser/parser.rl (JSON_Parser_type): turn into typed data. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47798 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r--ext/json/parser/parser.c21
-rw-r--r--ext/json/parser/parser.h7
-rw-r--r--ext/json/parser/parser.rl23
3 files changed, 41 insertions, 10 deletions
diff --git a/ext/json/parser/parser.c b/ext/json/parser/parser.c
index a8b6069..ada5596 100644
--- a/ext/json/parser/parser.c
+++ b/ext/json/parser/parser.c
@@ -2100,8 +2100,9 @@ static JSON_Parser *JSON_allocate(void)
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,},
+ NULL, NULL,
+ 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/parser/parser.h b/ext/json/parser/parser.h
index d600037..45afbc2 100644
--- a/ext/json/parser/parser.h
+++ b/ext/json/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
@@ -69,9 +69,10 @@ 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(void);
-static void JSON_mark(JSON_Parser *json);
-static void JSON_free(JSON_Parser *json);
+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/parser/parser.rl b/ext/json/parser/parser.rl
index ab8d318..dab4bb3 100644
--- a/ext/json/parser/parser.rl
+++ b/ext/json/parser/parser.rl
@@ -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,},
+ NULL, NULL,
+ 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);
}
/*