From aed7a09aea58ea20e4c2ff785416b756bc2a88c6 Mon Sep 17 00:00:00 2001 From: suke Date: Mon, 17 Nov 2014 11:18:54 +0000 Subject: ext/win32ole/win32ole_event.c: use typed data. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48469 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/win32ole/win32ole_event.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) (limited to 'ext/win32ole') diff --git a/ext/win32ole/win32ole_event.c b/ext/win32ole/win32ole_event.c index 2cceae7af7..fdd2c46e99 100644 --- a/ext/win32ole/win32ole_event.c +++ b/ext/win32ole/win32ole_event.c @@ -86,7 +86,8 @@ static long ole_search_event_at(VALUE ary, VALUE ev); 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); 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) 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 *poleev) 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 self) 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 self, VALUE is_ary_arg) { 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 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); -- cgit v1.2.3