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

ruby-changes:35833

From: suke <ko1@a...>
Date: Tue, 14 Oct 2014 19:16:30 +0900 (JST)
Subject: [ruby-changes:35833] suke:r47915 (trunk): ext/win32ole/win32ole_record.c: use typed data.

suke	2014-10-14 19:16:17 +0900 (Tue, 14 Oct 2014)

  New Revision: 47915

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

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

  Modified files:
    trunk/ChangeLog
    trunk/ext/win32ole/win32ole_record.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 47914)
+++ ChangeLog	(revision 47915)
@@ -1,3 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue Oct 14 19:15:31 2014  Masaki Suketa <masaki.suketa@n...>
+
+	* ext/win32ole/win32ole_record.c: use typed data.
+
 Tue Oct 14 16:23:12 2014  Nobuyoshi Nakada  <nobu@r...>
 
 	* symbol.c (global_symbols): make ids two-dimensional array of
Index: ext/win32ole/win32ole_record.c
===================================================================
--- ext/win32ole/win32ole_record.c	(revision 47914)
+++ ext/win32ole/win32ole_record.c	(revision 47915)
@@ -7,7 +7,8 @@ struct olerecorddata { https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole_record.c#L7
 
 static HRESULT recordinfo_from_itypelib(ITypeLib *pTypeLib, VALUE name, IRecordInfo **ppri);
 static int hash2olerec(VALUE key, VALUE val, VALUE rec);
-static void olerecord_free(struct olerecorddata *pvar);
+static void olerecord_free(void *pvar);
+static size_t olerecord_size(const void *ptr);
 static VALUE folerecord_s_allocate(VALUE klass);
 static VALUE folerecord_initialize(VALUE self, VALUE typename, VALUE oleobj);
 static VALUE folerecord_to_h(VALUE self);
@@ -19,6 +20,12 @@ static VALUE folerecord_ole_instance_var https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole_record.c#L20
 static VALUE folerecord_ole_instance_variable_set(VALUE self, VALUE name, VALUE val);
 static VALUE folerecord_inspect(VALUE self);
 
+static const rb_data_type_t olerecord_datatype = {
+    "win32ole_record",
+    {NULL, olerecord_free, olerecord_size,},
+    NULL, NULL, RUBY_TYPED_FREE_IMMEDIATELY
+};
+
 static HRESULT
 recordinfo_from_itypelib(ITypeLib *pTypeLib, VALUE name, IRecordInfo **ppri)
 {
@@ -61,7 +68,7 @@ hash2olerec(VALUE key, VALUE val, VALUE https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole_record.c#L68
     HRESULT hr;
 
     if (val != Qnil) {
-        Data_Get_Struct(rec, struct olerecorddata, prec);
+        TypedData_Get_Struct(rec, struct olerecorddata, &olerecord_datatype, prec);
         pri = prec->pri;
         VariantInit(&var);
         ole_val2variant(val, &var);
@@ -84,7 +91,7 @@ ole_rec2variant(VALUE rec, VARIANT *var) https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole_record.c#L91
     IRecordInfo *pri;
     HRESULT hr;
     VALUE fields;
-    Data_Get_Struct(rec, struct olerecorddata, prec);
+    TypedData_Get_Struct(rec, struct olerecorddata, &olerecord_datatype, prec);
     pri = prec->pri;
     if (pri) {
         hr = pri->lpVtbl->GetSize(pri, &size);
@@ -126,7 +133,7 @@ olerecord_set_ivar(VALUE obj, IRecordInf https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole_record.c#L133
     void *pdata = NULL;
     struct olerecorddata *pvar;
 
-    Data_Get_Struct(obj, struct olerecorddata, pvar);
+    TypedData_Get_Struct(obj, struct olerecorddata, &olerecord_datatype, pvar);
     OLE_ADDREF(pri);
     OLE_RELEASE(pvar->pri);
     pvar->pri = pri;
@@ -206,7 +213,8 @@ create_win32ole_record(IRecordInfo *pri, https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole_record.c#L213
  */
 
 static void
-olerecord_free(struct olerecorddata *pvar) {
+olerecord_free(void *ptr) {
+    struct olerecorddata *pvar = ptr;
     OLE_FREE(pvar->pri);
     if (pvar->pdata) {
         free(pvar->pdata);
@@ -214,11 +222,30 @@ olerecord_free(struct olerecorddata *pva https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole_record.c#L222
     free(pvar);
 }
 
+static size_t
+olerecord_size(const void *ptr)
+{
+    const struct olerecorddata *pvar = ptr;
+    size_t s = 0;
+    ULONG size = 0;
+    HRESULT hr;
+    if (ptr) {
+        s += sizeof(struct olerecorddata);
+        if (pvar->pri) {
+            hr = pvar->pri->lpVtbl->GetSize(pvar->pri, &size);
+            if (SUCCEEDED(hr)) {
+                s += size;
+            }
+        }
+    }
+    return s;
+}
+
 static VALUE
 folerecord_s_allocate(VALUE klass) {
     VALUE obj = Qnil;
     struct olerecorddata *pvar;
-    obj = Data_Make_Struct(klass, struct olerecorddata, 0, olerecord_free, pvar);
+    obj = TypedData_Make_Struct(klass, struct olerecorddata, &olerecord_datatype, pvar);
     pvar->pri = NULL;
     pvar->pdata = NULL;
     return obj;

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

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