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

ruby-changes:35740

From: suke <ko1@a...>
Date: Mon, 6 Oct 2014 23:35:53 +0900 (JST)
Subject: [ruby-changes:35740] suke:r47822 (trunk): ext/win32ole/win32ole_param.c: use typed data.

suke	2014-10-06 23:35:43 +0900 (Mon, 06 Oct 2014)

  New Revision: 47822

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

  Log:
    ext/win32ole/win32ole_param.c: use typed data.

  Modified files:
    trunk/ChangeLog
    trunk/ext/win32ole/win32ole_param.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 47821)
+++ ChangeLog	(revision 47822)
@@ -1,3 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Mon Oct  6 23:34:42 2014  Masaki Suketa <masaki.suketa@n...>
+
+	* ext/win32ole/win32ole_param.c: use typed data.
+
 Mon Oct  6 22:37:09 2014  Nobuyoshi Nakada  <nobu@r...>
 
 	* symbol.h (struct RSymbol): move from internal.h.
Index: ext/win32ole/win32ole_param.c
===================================================================
--- ext/win32ole/win32ole_param.c	(revision 47821)
+++ ext/win32ole/win32ole_param.c	(revision 47822)
@@ -8,7 +8,8 @@ struct oleparamdata { https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole_param.c#L8
     UINT index;
 };
 
-static void oleparam_free(struct oleparamdata *pole);
+static void oleparam_free(void *ptr);
+static size_t oleparam_size(const void *ptr);
 static VALUE foleparam_s_allocate(VALUE klass);
 static VALUE oleparam_ole_param_from_index(VALUE self, ITypeInfo *pTypeInfo, UINT method_index, int param_index);
 static VALUE oleparam_ole_param(VALUE self, VALUE olemethod, int n);
@@ -27,19 +28,32 @@ static VALUE ole_param_default(ITypeInfo https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole_param.c#L28
 static VALUE foleparam_default(VALUE self);
 static VALUE foleparam_inspect(VALUE self);
 
+static const rb_data_type_t oleparam_datatype = {
+    "win32ole_param",
+    {NULL, oleparam_free, oleparam_size,},
+    NULL, NULL, RUBY_TYPED_FREE_IMMEDIATELY
+};
+
 static void
-oleparam_free(struct oleparamdata *pole)
+oleparam_free(void *ptr)
 {
+    struct oleparamdata *pole = ptr;
     OLE_FREE(pole->pTypeInfo);
     free(pole);
 }
 
+static size_t
+oleparam_size(const void *ptr)
+{
+    return ptr ? sizeof(struct oleparamdata) : 0;
+}
+
 VALUE
 create_win32ole_param(ITypeInfo *pTypeInfo, UINT method_index, UINT index, VALUE name)
 {
     struct oleparamdata *pparam;
     VALUE obj = foleparam_s_allocate(cWIN32OLE_PARAM);
-    Data_Get_Struct(obj, struct oleparamdata, pparam);
+    TypedData_Get_Struct(obj, struct oleparamdata, &oleparam_datatype, pparam);
 
     pparam->pTypeInfo = pTypeInfo;
     OLE_ADDREF(pTypeInfo);
@@ -60,9 +74,9 @@ foleparam_s_allocate(VALUE klass) https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole_param.c#L74
 {
     struct oleparamdata *pparam;
     VALUE obj;
-    obj = Data_Make_Struct(klass,
-                           struct oleparamdata,
-                           0, oleparam_free, pparam);
+    obj = TypedData_Make_Struct(klass,
+                                struct oleparamdata,
+                                &oleparam_datatype, pparam);
     pparam->pTypeInfo = NULL;
     pparam->method_index = 0;
     pparam->index = 0;
@@ -97,7 +111,7 @@ oleparam_ole_param_from_index(VALUE self https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole_param.c#L111
         rb_raise(rb_eIndexError, "index of param must be in 1..%d", len);
     }
 
-    Data_Get_Struct(self, struct oleparamdata, pparam);
+    TypedData_Get_Struct(self, struct oleparamdata, &oleparam_datatype, pparam);
     pparam->pTypeInfo = pTypeInfo;
     OLE_ADDREF(pTypeInfo);
     pparam->method_index = method_index;
@@ -183,7 +197,7 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole_param.c#L197
 foleparam_ole_type(VALUE self)
 {
     struct oleparamdata *pparam;
-    Data_Get_Struct(self, struct oleparamdata, pparam);
+    TypedData_Get_Struct(self, struct oleparamdata, &oleparam_datatype, pparam);
     return ole_param_ole_type(pparam->pTypeInfo, pparam->method_index,
                               pparam->index);
 }
@@ -217,7 +231,7 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole_param.c#L231
 foleparam_ole_type_detail(VALUE self)
 {
     struct oleparamdata *pparam;
-    Data_Get_Struct(self, struct oleparamdata, pparam);
+    TypedData_Get_Struct(self, struct oleparamdata, &oleparam_datatype, pparam);
     return ole_param_ole_type_detail(pparam->pTypeInfo, pparam->method_index,
                                      pparam->index);
 }
@@ -250,7 +264,7 @@ ole_param_flag_mask(ITypeInfo *pTypeInfo https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole_param.c#L264
 static VALUE foleparam_input(VALUE self)
 {
     struct oleparamdata *pparam;
-    Data_Get_Struct(self, struct oleparamdata, pparam);
+    TypedData_Get_Struct(self, struct oleparamdata, &oleparam_datatype, pparam);
     return ole_param_flag_mask(pparam->pTypeInfo, pparam->method_index,
                                pparam->index, PARAMFLAG_FIN);
 }
@@ -277,7 +291,7 @@ static VALUE foleparam_input(VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole_param.c#L291
 static VALUE foleparam_output(VALUE self)
 {
     struct oleparamdata *pparam;
-    Data_Get_Struct(self, struct oleparamdata, pparam);
+    TypedData_Get_Struct(self, struct oleparamdata, &oleparam_datatype, pparam);
     return ole_param_flag_mask(pparam->pTypeInfo, pparam->method_index,
                                pparam->index, PARAMFLAG_FOUT);
 }
@@ -295,7 +309,7 @@ static VALUE foleparam_output(VALUE self https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole_param.c#L309
 static VALUE foleparam_optional(VALUE self)
 {
     struct oleparamdata *pparam;
-    Data_Get_Struct(self, struct oleparamdata, pparam);
+    TypedData_Get_Struct(self, struct oleparamdata, &oleparam_datatype, pparam);
     return ole_param_flag_mask(pparam->pTypeInfo, pparam->method_index,
                                pparam->index, PARAMFLAG_FOPT);
 }
@@ -314,7 +328,7 @@ static VALUE foleparam_optional(VALUE se https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole_param.c#L328
 static VALUE foleparam_retval(VALUE self)
 {
     struct oleparamdata *pparam;
-    Data_Get_Struct(self, struct oleparamdata, pparam);
+    TypedData_Get_Struct(self, struct oleparamdata, &oleparam_datatype, pparam);
     return ole_param_flag_mask(pparam->pTypeInfo, pparam->method_index,
                                pparam->index, PARAMFLAG_FRETVAL);
 }
@@ -374,7 +388,7 @@ ole_param_default(ITypeInfo *pTypeInfo, https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole_param.c#L388
 static VALUE foleparam_default(VALUE self)
 {
     struct oleparamdata *pparam;
-    Data_Get_Struct(self, struct oleparamdata, pparam);
+    TypedData_Get_Struct(self, struct oleparamdata, &oleparam_datatype, pparam);
     return ole_param_default(pparam->pTypeInfo, pparam->method_index,
                              pparam->index);
 }

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

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