[前][次][番号順一覧][スレッド一覧]

ruby-changes:35716

From: nobu <ko1@a...>
Date: Sun, 5 Oct 2014 08:33:32 +0900 (JST)
Subject: [ruby-changes:35716] nobu:r47798 (trunk): json/parser: typed data

nobu	2014-10-05 08:33:11 +0900 (Sun, 05 Oct 2014)

  New Revision: 47798

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=47798

  Log:
    json/parser: typed data
    
    * ext/json/parser/parser.rl (JSON_Parser_type): turn into typed
      data.

  Modified files:
    trunk/ext/json/parser/parser.c
    trunk/ext/json/parser/parser.h
    trunk/ext/json/parser/parser.rl
Index: ext/json/parser/parser.h
===================================================================
--- ext/json/parser/parser.h	(revision 47797)
+++ ext/json/parser/parser.h	(revision 47798)
@@ -51,7 +51,7 @@ typedef struct JSON_ParserStruct { https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.h#L51
     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 sour https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.h#L69
 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
Index: ext/json/parser/parser.rl
===================================================================
--- ext/json/parser/parser.rl	(revision 47797)
+++ ext/json/parser/parser.rl	(revision 47798)
@@ -815,7 +815,7 @@ static VALUE cParser_parse(VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.rl#L815
 }
 
 
-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() https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.rl#L823
     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) https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.rl#L833
     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);
 }
 
 /*
Index: ext/json/parser/parser.c
===================================================================
--- ext/json/parser/parser.c	(revision 47797)
+++ ext/json/parser/parser.c	(revision 47798)
@@ -2100,8 +2100,9 @@ static JSON_Parser *JSON_allocate(void) https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L2100
     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) https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L2110
     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);
 }
 
 /*

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]