ruby-changes:35749
From: suke <ko1@a...>
Date: Tue, 7 Oct 2014 22:45:00 +0900 (JST)
Subject: [ruby-changes:35749] suke:r47831 (trunk): ext/win32ole/win32ole_method.c: use typed data.
suke 2014-10-07 22:44:45 +0900 (Tue, 07 Oct 2014) New Revision: 47831 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=47831 Log: ext/win32ole/win32ole_method.c: use typed data. Modified files: trunk/ChangeLog trunk/ext/win32ole/win32ole_method.c Index: ChangeLog =================================================================== --- ChangeLog (revision 47830) +++ ChangeLog (revision 47831) @@ -1,3 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Tue Oct 7 22:43:44 2014 Masaki Suketa <masaki.suketa@n...> + + * ext/win32ole/win32ole_method.c: use typed data. + Tue Oct 7 21:47:05 2014 Masaki Suketa <masaki.suketa@n...> * ext/win32ole/win32ole_param.c: refactoring. Index: ext/win32ole/win32ole_method.c =================================================================== --- ext/win32ole/win32ole_method.c (revision 47830) +++ ext/win32ole/win32ole_method.c (revision 47831) @@ -1,9 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole_method.c#L1 #include "win32ole.h" +static void olemethod_free(void *ptr); +static size_t olemethod_size(const void *ptr); static VALUE ole_method_sub(VALUE self, ITypeInfo *pOwnerTypeInfo, ITypeInfo *pTypeInfo, VALUE name); static VALUE olemethod_from_typeinfo(VALUE self, ITypeInfo *pTypeInfo, VALUE name); static VALUE ole_methods_sub(ITypeInfo *pOwnerTypeInfo, ITypeInfo *pTypeInfo, VALUE methods, int mask); -static void olemethod_free(struct olemethoddata *polemethod); static VALUE olemethod_set_member(VALUE self, ITypeInfo *pTypeInfo, ITypeInfo *pOwnerTypeInfo, int index, VALUE name); static VALUE folemethod_initialize(VALUE self, VALUE oletype, VALUE method); static VALUE folemethod_name(VALUE self); @@ -41,19 +42,32 @@ static VALUE ole_method_params(ITypeInfo https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole_method.c#L42 static VALUE folemethod_params(VALUE self); static VALUE folemethod_inspect(VALUE self); +static const rb_data_type_t olemethod_datatype = { + "win32ole_method", + {NULL, olemethod_free, olemethod_size,}, + NULL, NULL, RUBY_TYPED_FREE_IMMEDIATELY +}; + static void -olemethod_free(struct olemethoddata *polemethod) +olemethod_free(void *ptr) { + struct olemethoddata *polemethod = ptr; OLE_FREE(polemethod->pTypeInfo); OLE_FREE(polemethod->pOwnerTypeInfo); free(polemethod); } +static size_t +olemethod_size(const void *ptr) +{ + return ptr ? sizeof(struct olemethoddata) : 0; +} + struct olemethoddata * olemethod_data_get_struct(VALUE obj) { struct olemethoddata *pmethod; - Data_Get_Struct(obj, struct olemethoddata, pmethod); + TypedData_Get_Struct(obj, struct olemethoddata, &olemethod_datatype, pmethod); return pmethod; } @@ -211,7 +225,7 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole_method.c#L225 olemethod_set_member(VALUE self, ITypeInfo *pTypeInfo, ITypeInfo *pOwnerTypeInfo, int index, VALUE name) { struct olemethoddata *pmethod; - Data_Get_Struct(self, struct olemethoddata, pmethod); + TypedData_Get_Struct(self, struct olemethoddata, &olemethod_datatype, pmethod); pmethod->pTypeInfo = pTypeInfo; OLE_ADDREF(pTypeInfo); pmethod->pOwnerTypeInfo = pOwnerTypeInfo; @@ -226,9 +240,9 @@ folemethod_s_allocate(VALUE klass) https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole_method.c#L240 { struct olemethoddata *pmethod; VALUE obj; - obj = Data_Make_Struct(klass, - struct olemethoddata, - 0, olemethod_free, pmethod); + obj = TypedData_Make_Struct(klass, + struct olemethoddata, + &olemethod_datatype, pmethod); pmethod->pTypeInfo = NULL; pmethod->pOwnerTypeInfo = NULL; pmethod->index = 0; @@ -315,7 +329,7 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole_method.c#L329 folemethod_return_type(VALUE self) { struct olemethoddata *pmethod; - Data_Get_Struct(self, struct olemethoddata, pmethod); + TypedData_Get_Struct(self, struct olemethoddata, &olemethod_datatype, pmethod); return ole_method_return_type(pmethod->pTypeInfo, pmethod->index); } @@ -349,7 +363,7 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole_method.c#L363 folemethod_return_vtype(VALUE self) { struct olemethoddata *pmethod; - Data_Get_Struct(self, struct olemethoddata, pmethod); + TypedData_Get_Struct(self, struct olemethoddata, &olemethod_datatype, pmethod); return ole_method_return_vtype(pmethod->pTypeInfo, pmethod->index); } @@ -383,7 +397,7 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole_method.c#L397 folemethod_return_type_detail(VALUE self) { struct olemethoddata *pmethod; - Data_Get_Struct(self, struct olemethoddata, pmethod); + TypedData_Get_Struct(self, struct olemethoddata, &olemethod_datatype, pmethod); return ole_method_return_type_detail(pmethod->pTypeInfo, pmethod->index); } @@ -435,7 +449,7 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole_method.c#L449 folemethod_invkind(VALUE self) { struct olemethoddata *pmethod; - Data_Get_Struct(self, struct olemethoddata, pmethod); + TypedData_Get_Struct(self, struct olemethoddata, &olemethod_datatype, pmethod); return ole_method_invkind(pmethod->pTypeInfo, pmethod->index); } @@ -454,7 +468,7 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole_method.c#L468 folemethod_invoke_kind(VALUE self) { struct olemethoddata *pmethod; - Data_Get_Struct(self, struct olemethoddata, pmethod); + TypedData_Get_Struct(self, struct olemethoddata, &olemethod_datatype, pmethod); return ole_method_invoke_kind(pmethod->pTypeInfo, pmethod->index); } @@ -491,7 +505,7 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole_method.c#L505 folemethod_visible(VALUE self) { struct olemethoddata *pmethod; - Data_Get_Struct(self, struct olemethoddata, pmethod); + TypedData_Get_Struct(self, struct olemethoddata, &olemethod_datatype, pmethod); return ole_method_visible(pmethod->pTypeInfo, pmethod->index); } @@ -573,7 +587,7 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole_method.c#L587 folemethod_event(VALUE self) { struct olemethoddata *pmethod; - Data_Get_Struct(self, struct olemethoddata, pmethod); + TypedData_Get_Struct(self, struct olemethoddata, &olemethod_datatype, pmethod); if (!pmethod->pOwnerTypeInfo) return Qfalse; return ole_method_event(pmethod->pOwnerTypeInfo, @@ -596,7 +610,7 @@ folemethod_event_interface(VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole_method.c#L610 BSTR name; struct olemethoddata *pmethod; HRESULT hr; - Data_Get_Struct(self, struct olemethoddata, pmethod); + TypedData_Get_Struct(self, struct olemethoddata, &olemethod_datatype, pmethod); if(folemethod_event(self) == Qtrue) { hr = ole_docinfo_from_type(pmethod->pTypeInfo, &name, NULL, NULL, NULL); if(SUCCEEDED(hr)) @@ -654,7 +668,7 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole_method.c#L668 folemethod_helpstring(VALUE self) { struct olemethoddata *pmethod; - Data_Get_Struct(self, struct olemethoddata, pmethod); + TypedData_Get_Struct(self, struct olemethoddata, &olemethod_datatype, pmethod); return ole_method_helpstring(pmethod->pTypeInfo, pmethod->index); } @@ -684,7 +698,7 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole_method.c#L698 folemethod_helpfile(VALUE self) { struct olemethoddata *pmethod; - Data_Get_Struct(self, struct olemethoddata, pmethod); + TypedData_Get_Struct(self, struct olemethoddata, &olemethod_datatype, pmethod); return ole_method_helpfile(pmethod->pTypeInfo, pmethod->index); } @@ -714,7 +728,7 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole_method.c#L728 folemethod_helpcontext(VALUE self) { struct olemethoddata *pmethod; - Data_Get_Struct(self, struct olemethoddata, pmethod); + TypedData_Get_Struct(self, struct olemethoddata, &olemethod_datatype, pmethod); return ole_method_helpcontext(pmethod->pTypeInfo, pmethod->index); } @@ -745,7 +759,7 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole_method.c#L759 folemethod_dispid(VALUE self) { struct olemethoddata *pmethod; - Data_Get_Struct(self, struct olemethoddata, pmethod); + TypedData_Get_Struct(self, struct olemethoddata, &olemethod_datatype, pmethod); return ole_method_dispid(pmethod->pTypeInfo, pmethod->index); } @@ -776,7 +790,7 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole_method.c#L790 folemethod_offset_vtbl(VALUE self) { struct olemethoddata *pmethod; - Data_Get_Struct(self, struct olemethoddata, pmethod); + TypedData_Get_Struct(self, struct olemethoddata, &olemethod_datatype, pmethod); return ole_method_offset_vtbl(pmethod->pTypeInfo, pmethod->index); } @@ -808,7 +822,7 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole_method.c#L822 folemethod_size_params(VALUE self) { struct olemethoddata *pmethod; - Data_Get_Struct(self, struct olemethoddata, pmethod); + TypedData_Get_Struct(self, struct olemethoddata, &olemethod_datatype, pmethod); return ole_method_size_params(pmethod->pTypeInfo, pmethod->index); } @@ -839,7 +853,7 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole_method.c#L853 folemethod_size_opt_params(VALUE self) { struct olemethoddata *pmethod; - Data_Get_Struct(self, struct olemethoddata, pmethod); + TypedData_Get_Struct(self, struct olemethoddata, &olemethod_datatype, pmethod); return ole_method_size_opt_params(pmethod->pTypeInfo, pmethod->index); } @@ -892,7 +906,7 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole_method.c#L906 folemethod_params(VALUE self) { struct olemethoddata *pmethod; - Data_Get_Struct(self, struct olemethoddata, pmethod); + TypedData_Get_Struct(self, struct olemethoddata, &olemethod_datatype, pmethod); return ole_method_params(pmethod->pTypeInfo, pmethod->index); } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/