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

ruby-changes:35717

From: nobu <ko1@a...>
Date: Sun, 5 Oct 2014 08:33:40 +0900 (JST)
Subject: [ruby-changes:35717] nobu:r47800 (trunk): psych: typed data

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

  New Revision: 47800

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

  Log:
    psych: typed data
    
    * ext/psych/psych_emitter.c (psych_emitter_type): turn into typed
      data.
    
    * ext/psych/psych_parser.c (psych_parser_type): ditto.

  Modified files:
    trunk/ext/psych/psych_emitter.c
    trunk/ext/psych/psych_parser.c
Index: ext/psych/psych_parser.c
===================================================================
--- ext/psych/psych_parser.c	(revision 47799)
+++ ext/psych/psych_parser.c	(revision 47800)
@@ -49,6 +49,22 @@ static void dealloc(void * ptr) https://github.com/ruby/ruby/blob/trunk/ext/psych/psych_parser.c#L49
     xfree(parser);
 }
 
+#if 0
+static size_t memsize(const void *ptr)
+{
+    const yaml_parser_t *parser = ptr;
+    /* TODO: calculate parser's size */
+    return 0;
+}
+#endif
+
+static const rb_data_type_t psych_parser_type = {
+    "Psych/parser",
+    {0, dealloc, 0,},
+    NULL, NULL,
+    RUBY_TYPED_FREE_IMMEDIATELY,
+};
+
 static VALUE allocate(VALUE klass)
 {
     yaml_parser_t * parser;
@@ -56,7 +72,7 @@ static VALUE allocate(VALUE klass) https://github.com/ruby/ruby/blob/trunk/ext/psych/psych_parser.c#L72
     parser = xmalloc(sizeof(yaml_parser_t));
     yaml_parser_initialize(parser);
 
-    return Data_Wrap_Struct(klass, 0, dealloc, parser);
+    return TypedData_Wrap_Struct(klass, &psych_parser_type, parser);
 }
 
 static VALUE make_exception(yaml_parser_t * parser, VALUE path)
@@ -248,7 +264,7 @@ static VALUE parse(int argc, VALUE *argv https://github.com/ruby/ruby/blob/trunk/ext/psych/psych_parser.c#L264
 	    path = rb_str_new2("<unknown>");
     }
 
-    Data_Get_Struct(self, yaml_parser_t, parser);
+    TypedData_Get_Struct(self, yaml_parser_t, &psych_parser_type, parser);
 
     yaml_parser_delete(parser);
     yaml_parser_initialize(parser);
@@ -526,7 +542,7 @@ static VALUE mark(VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/psych/psych_parser.c#L542
     VALUE args[3];
     yaml_parser_t * parser;
 
-    Data_Get_Struct(self, yaml_parser_t, parser);
+    TypedData_Get_Struct(self, yaml_parser_t, &psych_parser_type, parser);
     mark_klass = rb_const_get_at(cPsychParser, rb_intern("Mark"));
     args[0] = INT2NUM(parser->mark.index);
     args[1] = INT2NUM(parser->mark.line);
Index: ext/psych/psych_emitter.c
===================================================================
--- ext/psych/psych_emitter.c	(revision 47799)
+++ ext/psych/psych_emitter.c	(revision 47800)
@@ -29,6 +29,22 @@ static void dealloc(void * ptr) https://github.com/ruby/ruby/blob/trunk/ext/psych/psych_emitter.c#L29
     xfree(emitter);
 }
 
+#if 0
+static size_t memsize(const void *ptr)
+{
+    const yaml_emitter_t *emitter = ptr;
+    /* TODO: calculate emitter's size */
+    return 0;
+}
+#endif
+
+static const rb_data_type_t psych_emitter_type = {
+    "Psych/emitter",
+    {0, dealloc, 0,},
+    NULL, NULL,
+    RUBY_TYPED_FREE_IMMEDIATELY,
+};
+
 static VALUE allocate(VALUE klass)
 {
     yaml_emitter_t * emitter;
@@ -39,7 +55,7 @@ static VALUE allocate(VALUE klass) https://github.com/ruby/ruby/blob/trunk/ext/psych/psych_emitter.c#L55
     yaml_emitter_set_unicode(emitter, 1);
     yaml_emitter_set_indent(emitter, 2);
 
-    return Data_Wrap_Struct(klass, 0, dealloc, emitter);
+    return TypedData_Wrap_Struct(klass, &psych_emitter_type, emitter);
 }
 
 /* call-seq: Psych::Emitter.new(io, options = Psych::Emitter::OPTIONS)
@@ -54,7 +70,7 @@ static VALUE initialize(int argc, VALUE https://github.com/ruby/ruby/blob/trunk/ext/psych/psych_emitter.c#L70
     VALUE indent;
     VALUE canonical;
 
-    Data_Get_Struct(self, yaml_emitter_t, emitter);
+    TypedData_Get_Struct(self, yaml_emitter_t, &psych_emitter_type, emitter);
 
     if (rb_scan_args(argc, argv, "11", &io, &options) == 2) {
 	line_width = rb_funcall(options, id_line_width, 0);
@@ -81,7 +97,7 @@ static VALUE start_stream(VALUE self, VA https://github.com/ruby/ruby/blob/trunk/ext/psych/psych_emitter.c#L97
 {
     yaml_emitter_t * emitter;
     yaml_event_t event;
-    Data_Get_Struct(self, yaml_emitter_t, emitter);
+    TypedData_Get_Struct(self, yaml_emitter_t, &psych_emitter_type, emitter);
     Check_Type(encoding, T_FIXNUM);
 
     yaml_stream_start_event_initialize(&event, (yaml_encoding_t)NUM2INT(encoding));
@@ -101,7 +117,7 @@ static VALUE end_stream(VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/psych/psych_emitter.c#L117
 {
     yaml_emitter_t * emitter;
     yaml_event_t event;
-    Data_Get_Struct(self, yaml_emitter_t, emitter);
+    TypedData_Get_Struct(self, yaml_emitter_t, &psych_emitter_type, emitter);
 
     yaml_stream_end_event_initialize(&event);
 
@@ -124,7 +140,7 @@ static VALUE start_document(VALUE self, https://github.com/ruby/ruby/blob/trunk/ext/psych/psych_emitter.c#L140
     yaml_tag_directive_t * tail = NULL;
     yaml_event_t event;
     yaml_version_directive_t version_directive;
-    Data_Get_Struct(self, yaml_emitter_t, emitter);
+    TypedData_Get_Struct(self, yaml_emitter_t, &psych_emitter_type, emitter);
 
 
     Check_Type(version, T_ARRAY);
@@ -198,7 +214,7 @@ static VALUE end_document(VALUE self, VA https://github.com/ruby/ruby/blob/trunk/ext/psych/psych_emitter.c#L214
 {
     yaml_emitter_t * emitter;
     yaml_event_t event;
-    Data_Get_Struct(self, yaml_emitter_t, emitter);
+    TypedData_Get_Struct(self, yaml_emitter_t, &psych_emitter_type, emitter);
 
     yaml_document_end_event_initialize(&event, imp ? 1 : 0);
 
@@ -228,7 +244,7 @@ static VALUE scalar( https://github.com/ruby/ruby/blob/trunk/ext/psych/psych_emitter.c#L244
 #ifdef HAVE_RUBY_ENCODING_H
     rb_encoding *encoding;
 #endif
-    Data_Get_Struct(self, yaml_emitter_t, emitter);
+    TypedData_Get_Struct(self, yaml_emitter_t, &psych_emitter_type, emitter);
 
     Check_Type(value, T_STRING);
 
@@ -295,7 +311,7 @@ static VALUE start_sequence( https://github.com/ruby/ruby/blob/trunk/ext/psych/psych_emitter.c#L311
     }
 #endif
 
-    Data_Get_Struct(self, yaml_emitter_t, emitter);
+    TypedData_Get_Struct(self, yaml_emitter_t, &psych_emitter_type, emitter);
 
     yaml_sequence_start_event_initialize(
 	    &event,
@@ -320,7 +336,7 @@ static VALUE end_sequence(VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/psych/psych_emitter.c#L336
 {
     yaml_emitter_t * emitter;
     yaml_event_t event;
-    Data_Get_Struct(self, yaml_emitter_t, emitter);
+    TypedData_Get_Struct(self, yaml_emitter_t, &psych_emitter_type, emitter);
 
     yaml_sequence_end_event_initialize(&event);
 
@@ -348,7 +364,7 @@ static VALUE start_mapping( https://github.com/ruby/ruby/blob/trunk/ext/psych/psych_emitter.c#L364
 #ifdef HAVE_RUBY_ENCODING_H
     rb_encoding *encoding;
 #endif
-    Data_Get_Struct(self, yaml_emitter_t, emitter);
+    TypedData_Get_Struct(self, yaml_emitter_t, &psych_emitter_type, emitter);
 
 #ifdef HAVE_RUBY_ENCODING_H
     encoding = rb_utf8_encoding();
@@ -387,7 +403,7 @@ static VALUE end_mapping(VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/psych/psych_emitter.c#L403
 {
     yaml_emitter_t * emitter;
     yaml_event_t event;
-    Data_Get_Struct(self, yaml_emitter_t, emitter);
+    TypedData_Get_Struct(self, yaml_emitter_t, &psych_emitter_type, emitter);
 
     yaml_mapping_end_event_initialize(&event);
 
@@ -406,7 +422,7 @@ static VALUE alias(VALUE self, VALUE anc https://github.com/ruby/ruby/blob/trunk/ext/psych/psych_emitter.c#L422
 {
     yaml_emitter_t * emitter;
     yaml_event_t event;
-    Data_Get_Struct(self, yaml_emitter_t, emitter);
+    TypedData_Get_Struct(self, yaml_emitter_t, &psych_emitter_type, emitter);
 
 #ifdef HAVE_RUBY_ENCODING_H
     if(!NIL_P(anchor)) {
@@ -432,7 +448,7 @@ static VALUE alias(VALUE self, VALUE anc https://github.com/ruby/ruby/blob/trunk/ext/psych/psych_emitter.c#L448
 static VALUE set_canonical(VALUE self, VALUE style)
 {
     yaml_emitter_t * emitter;
-    Data_Get_Struct(self, yaml_emitter_t, emitter);
+    TypedData_Get_Struct(self, yaml_emitter_t, &psych_emitter_type, emitter);
 
     yaml_emitter_set_canonical(emitter, Qtrue == style ? 1 : 0);
 
@@ -446,7 +462,7 @@ static VALUE set_canonical(VALUE self, V https://github.com/ruby/ruby/blob/trunk/ext/psych/psych_emitter.c#L462
 static VALUE canonical(VALUE self)
 {
     yaml_emitter_t * emitter;
-    Data_Get_Struct(self, yaml_emitter_t, emitter);
+    TypedData_Get_Struct(self, yaml_emitter_t, &psych_emitter_type, emitter);
 
     return (emitter->canonical == 0) ? Qfalse : Qtrue;
 }
@@ -459,7 +475,7 @@ static VALUE canonical(VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/psych/psych_emitter.c#L475
 static VALUE set_indentation(VALUE self, VALUE level)
 {
     yaml_emitter_t * emitter;
-    Data_Get_Struct(self, yaml_emitter_t, emitter);
+    TypedData_Get_Struct(self, yaml_emitter_t, &psych_emitter_type, emitter);
 
     yaml_emitter_set_indent(emitter, NUM2INT(level));
 
@@ -473,7 +489,7 @@ static VALUE set_indentation(VALUE self, https://github.com/ruby/ruby/blob/trunk/ext/psych/psych_emitter.c#L489
 static VALUE indentation(VALUE self)
 {
     yaml_emitter_t * emitter;
-    Data_Get_Struct(self, yaml_emitter_t, emitter);
+    TypedData_Get_Struct(self, yaml_emitter_t, &psych_emitter_type, emitter);
 
     return INT2NUM(emitter->best_indent);
 }
@@ -485,7 +501,7 @@ static VALUE indentation(VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/psych/psych_emitter.c#L501
 static VALUE line_width(VALUE self)
 {
     yaml_emitter_t * emitter;
-    Data_Get_Struct(self, yaml_emitter_t, emitter);
+    TypedData_Get_Struct(self, yaml_emitter_t, &psych_emitter_type, emitter);
 
     return INT2NUM(emitter->best_width);
 }
@@ -497,7 +513,7 @@ static VALUE line_width(VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/psych/psych_emitter.c#L513
 static VALUE set_line_width(VALUE self, VALUE width)
 {
     yaml_emitter_t * emitter;
-    Data_Get_Struct(self, yaml_emitter_t, emitter);
+    TypedData_Get_Struct(self, yaml_emitter_t, &psych_emitter_type, emitter);
 
     yaml_emitter_set_width(emitter, NUM2INT(width));
 

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

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