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

ruby-changes:36388

From: suke <ko1@a...>
Date: Mon, 17 Nov 2014 20:19:08 +0900 (JST)
Subject: [ruby-changes:36388] suke:r48469 (trunk): ext/win32ole/win32ole_event.c: use typed data.

suke	2014-11-17 20:18:54 +0900 (Mon, 17 Nov 2014)

  New Revision: 48469

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

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

  Modified files:
    trunk/ChangeLog
    trunk/ext/win32ole/win32ole_event.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 48468)
+++ ChangeLog	(revision 48469)
@@ -1,3 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Mon Nov 17 20:17:59 2014  Masaki Suketa <masaki.suketa@n...>
+
+	* ext/win32ole/win32ole_event.c: use typed data.
+
 Mon Nov 17 12:54:56 2014  SHIBATA Hiroshi  <shibata.hiroshi@g...>
 
 	* lib/rubygems/*, test/rubygems/*: Update to RubyGems 2.4.4
Index: ext/win32ole/win32ole_event.c
===================================================================
--- ext/win32ole/win32ole_event.c	(revision 48468)
+++ ext/win32ole/win32ole_event.c	(revision 48469)
@@ -86,7 +86,8 @@ static long ole_search_event_at(VALUE ar https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole_event.c#L86
 static VALUE ole_search_event(VALUE ary, VALUE ev, BOOL  *is_default);
 static VALUE ole_search_handler_method(VALUE handler, VALUE ev, BOOL *is_default_handler);
 static void ole_delete_event(VALUE ary, VALUE ev);
-static void ole_event_free(struct oleeventdata *poleev);
+static void oleevent_free(void *ptr);
+static size_t oleevent_size(const void *ptr);
 static VALUE fev_s_allocate(VALUE klass);
 static VALUE ev_advise(int argc, VALUE *argv, VALUE self);
 static VALUE fev_initialize(int argc, VALUE *argv, VALUE self);
@@ -105,6 +106,13 @@ static VALUE evs_delete(long i); https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole_event.c#L106
 static VALUE evs_entry(long i);
 static long  evs_length(void);
 
+
+static const rb_data_type_t oleevent_datatype = {
+    "win32ole_event",
+    {NULL, oleevent_free, oleevent_size,},
+    NULL, NULL, RUBY_TYPED_FREE_IMMEDIATELY
+};
+
 STDMETHODIMP EVENTSINK_Invoke(
     PEVENTSINK pEventSink,
     DISPID dispid,
@@ -852,8 +860,9 @@ ole_delete_event(VALUE ary, VALUE ev) https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole_event.c#L860
 
 
 static void
-ole_event_free(struct oleeventdata *poleev)
+oleevent_free(void *ptr)
 {
+    struct oleeventdata *poleev = ptr;
     if (poleev->pConnectionPoint) {
         poleev->pConnectionPoint->lpVtbl->Unadvise(poleev->pConnectionPoint, poleev->dwCookie);
         OLE_RELEASE(poleev->pConnectionPoint);
@@ -863,12 +872,18 @@ ole_event_free(struct oleeventdata *pole https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole_event.c#L872
     free(poleev);
 }
 
+static size_t
+oleevent_size(const void *ptr)
+{
+    return ptr ? sizeof(struct oleeventdata) : 0;
+}
+
 static VALUE
 fev_s_allocate(VALUE klass)
 {
     VALUE obj;
     struct oleeventdata *poleev;
-    obj = Data_Make_Struct(klass,struct oleeventdata,0,ole_event_free,poleev);
+    obj = TypedData_Make_Struct(klass, struct oleeventdata, &oleevent_datatype, poleev);
     poleev->dwCookie = 0;
     poleev->pConnectionPoint = NULL;
     poleev->event_id = 0;
@@ -944,7 +959,7 @@ ev_advise(int argc, VALUE *argv, VALUE s https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole_event.c#L959
         ole_raise(hr, rb_eRuntimeError, "Advise Error");
     }
 
-    Data_Get_Struct(self, struct oleeventdata, poleev);
+    TypedData_Get_Struct(self, struct oleeventdata, &oleevent_datatype, poleev);
     pIEV->m_event_id = evs_length();
     pIEV->pTypeInfo = pTypeInfo;
     poleev->dwCookie = dwCookie;
@@ -1016,7 +1031,7 @@ ev_on_event(int argc, VALUE *argv, VALUE https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole_event.c#L1031
 {
     struct oleeventdata *poleev;
     VALUE event, args, data;
-    Data_Get_Struct(self, struct oleeventdata, poleev);
+    TypedData_Get_Struct(self, struct oleeventdata, &oleevent_datatype, poleev);
     if (poleev->pConnectionPoint == NULL) {
         rb_raise(eWIN32OLERuntimeError, "IConnectionPoint not found. You must call advise at first.");
     }
@@ -1146,7 +1161,7 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole_event.c#L1161
 fev_unadvise(VALUE self)
 {
     struct oleeventdata *poleev;
-    Data_Get_Struct(self, struct oleeventdata, poleev);
+    TypedData_Get_Struct(self, struct oleeventdata, &oleevent_datatype, poleev);
     if (poleev->pConnectionPoint) {
         ole_msg_loop();
         evs_delete(poleev->event_id);

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

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