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

ruby-changes:36584

From: suke <ko1@a...>
Date: Mon, 1 Dec 2014 20:03:26 +0900 (JST)
Subject: [ruby-changes:36584] suke:r48665 (trunk): * ext/win32ole/win32ole.c: use typed data for WIN32OLE.

suke	2014-12-01 20:03:13 +0900 (Mon, 01 Dec 2014)

  New Revision: 48665

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

  Log:
    * ext/win32ole/win32ole.c: use typed data for WIN32OLE.
    * ext/win32ole/win32ole.h: ditto.
    * ext/win32ole/win32ole_event.c: ditto.

  Modified files:
    trunk/ChangeLog
    trunk/ext/win32ole/win32ole.c
    trunk/ext/win32ole/win32ole.h
    trunk/ext/win32ole/win32ole_event.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 48664)
+++ ChangeLog	(revision 48665)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Mon Dec  1 20:01:12 2014  Masaki Suketa <masaki.suketa@n...>
+
+	* ext/win32ole/win32ole.c: use typed data for WIN32OLE.
+	* ext/win32ole/win32ole.h: ditto.
+	* ext/win32ole/win32ole_event.c: ditto.
+
 Mon Dec  1 17:20:42 2014  Nobuyoshi Nakada  <nobu@r...>
 
 	* win32/Makefile.sub (verconf.h): so depends on verconf.mk, which
Index: ext/win32ole/win32ole.c
===================================================================
--- ext/win32ole/win32ole.c	(revision 48664)
+++ ext/win32ole/win32ole.c	(revision 48665)
@@ -97,7 +97,8 @@ static void load_conv_function51932(void https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole.c#L97
 static UINT ole_init_cp(void);
 static void ole_freeexceptinfo(EXCEPINFO *pExInfo);
 static VALUE ole_excepinfo2msg(EXCEPINFO *pExInfo);
-static void ole_free(struct oledata *pole);
+static void ole_free(void *ptr);
+static size_t ole_size(const void *ptr);
 static LPWSTR ole_mb2wc(char *pm, int len);
 static VALUE ole_ary_m_entry(VALUE val, LONG *pid);
 static VALUE is_all_index_under(LONG *pid, long *pub, long dim);
@@ -168,6 +169,12 @@ static VALUE fole_activex_initialize(VAL https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole.c#L169
 static void init_enc2cp(void);
 static void free_enc2cp(void);
 
+static const rb_data_type_t ole_datatype = {
+    "win32ole",
+    {NULL, ole_free, ole_size,},
+    0, 0, RUBY_TYPED_FREE_IMMEDIATELY
+};
+
 static HRESULT (STDMETHODCALLTYPE mf_QueryInterface)(
     IMessageFilter __RPC_FAR * This,
     /* [in] */ REFIID riid,
@@ -813,12 +820,26 @@ ole_initialize(void) https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole.c#L820
 }
 
 static void
-ole_free(struct oledata *pole)
+ole_free(void *ptr)
 {
+    struct oledata *pole = ptr;
     OLE_FREE(pole->pDispatch);
     free(pole);
 }
 
+static size_t ole_size(const void *ptr)
+{
+    return ptr ? sizeof(struct oledata) : 0;
+}
+
+struct oledata *
+oledata_get_struct(VALUE ole)
+{
+    struct oledata *pole;
+    TypedData_Get_Struct(ole, struct oledata, &ole_datatype, pole);
+    return pole;
+}
+
 LPWSTR
 ole_vstr2wc(VALUE vstr)
 {
@@ -1216,9 +1237,9 @@ ole_val_ary2variant_ary(VALUE val, VARIA https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole.c#L1237
 void
 ole_val2variant(VALUE val, VARIANT *var)
 {
-    struct oledata *pole;
+    struct oledata *pole = NULL;
     if(rb_obj_is_kind_of(val, cWIN32OLE)) {
-        Data_Get_Struct(val, struct oledata, pole);
+        pole = oledata_get_struct(val);
         OLE_ADDREF(pole->pDispatch);
         V_VT(var) = VT_DISPATCH;
         V_DISPATCH(var) = pole->pDispatch;
@@ -1310,8 +1331,8 @@ default_inspect(VALUE self, const char * https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole.c#L1331
 static VALUE
 ole_set_member(VALUE self, IDispatch *dispatch)
 {
-    struct oledata *pole;
-    Data_Get_Struct(self, struct oledata, pole);
+    struct oledata *pole = NULL;
+    pole = oledata_get_struct(self);
     if (pole->pDispatch) {
         OLE_RELEASE(pole->pDispatch);
         pole->pDispatch = NULL;
@@ -1327,7 +1348,7 @@ fole_s_allocate(VALUE klass) https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole.c#L1348
     struct oledata *pole;
     VALUE obj;
     ole_initialize();
-    obj = Data_Make_Struct(klass,struct oledata,0,ole_free,pole);
+    obj = TypedData_Make_Struct(klass, struct oledata, &ole_datatype, pole);
     pole->pDispatch = NULL;
     return obj;
 }
@@ -2007,7 +2028,7 @@ fole_s_const_load(int argc, VALUE *argv, https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole.c#L2028
 {
     VALUE ole;
     VALUE klass;
-    struct oledata *pole;
+    struct oledata *pole = NULL;
     ITypeInfo *pTypeInfo;
     ITypeLib *pTypeLib;
     unsigned int index;
@@ -2023,7 +2044,7 @@ fole_s_const_load(int argc, VALUE *argv, https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole.c#L2044
         rb_raise(rb_eTypeError, "2nd parameter must be Class or Module");
     }
     if (rb_obj_is_kind_of(ole, cWIN32OLE)) {
-        OLEData_Get_Struct(ole, pole);
+        pole = oledata_get_struct(ole);
         hr = pole->pDispatch->lpVtbl->GetTypeInfo(pole->pDispatch,
                                                   0, lcid, &pTypeInfo);
         if(FAILED(hr)) {
@@ -2089,8 +2110,8 @@ reference_count(struct oledata * pole) https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole.c#L2110
 static VALUE
 fole_s_reference_count(VALUE self, VALUE obj)
 {
-    struct oledata * pole;
-    OLEData_Get_Struct(obj, pole);
+    struct oledata * pole = NULL;
+    pole = oledata_get_struct(obj);
     return INT2NUM(reference_count(pole));
 }
 
@@ -2107,8 +2128,8 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole.c#L2128
 fole_s_free(VALUE self, VALUE obj)
 {
     ULONG n = 0;
-    struct oledata * pole;
-    OLEData_Get_Struct(obj, pole);
+    struct oledata * pole = NULL;
+    pole = oledata_get_struct(obj);
     if(pole->pDispatch) {
         if (reference_count(pole) > 0) {
             n = OLE_RELEASE(pole->pDispatch);
@@ -2516,7 +2537,7 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole.c#L2537
 ole_invoke(int argc, VALUE *argv, VALUE self, USHORT wFlags, BOOL is_bracket)
 {
     LCID    lcid = cWIN32OLE_lcid;
-    struct oledata *pole;
+    struct oledata *pole = NULL;
     HRESULT hr;
     VALUE cmd;
     VALUE paramS;
@@ -2552,7 +2573,7 @@ ole_invoke(int argc, VALUE *argv, VALUE https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole.c#L2573
     if (RB_TYPE_P(cmd, T_SYMBOL)) {
 	cmd = rb_sym_to_s(cmd);
     }
-    OLEData_Get_Struct(self, pole);
+    pole = oledata_get_struct(self);
     if(!pole->pDispatch) {
         rb_raise(rb_eRuntimeError, "failed to get dispatch interface");
     }
@@ -2773,7 +2794,7 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole.c#L2794
 ole_invoke2(VALUE self, VALUE dispid, VALUE args, VALUE types, USHORT dispkind)
 {
     HRESULT hr;
-    struct oledata *pole;
+    struct oledata *pole = NULL;
     unsigned int argErr = 0;
     EXCEPINFO excepinfo;
     VARIANT result;
@@ -2791,7 +2812,7 @@ ole_invoke2(VALUE self, VALUE dispid, VA https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole.c#L2812
     memset(&excepinfo, 0, sizeof(EXCEPINFO));
     memset(&dispParams, 0, sizeof(DISPPARAMS));
     VariantInit(&result);
-    OLEData_Get_Struct(self, pole);
+    pole = oledata_get_struct(self);
 
     dispParams.cArgs = RARRAY_LEN(args);
     dispParams.rgvarg = ALLOCA_N(VARIANTARG, dispParams.cArgs);
@@ -3081,7 +3102,7 @@ fole_getproperty_with_bracket(int argc, https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole.c#L3102
 static VALUE
 ole_propertyput(VALUE self, VALUE property, VALUE value)
 {
-    struct oledata *pole;
+    struct oledata *pole = NULL;
     unsigned argErr;
     unsigned int index;
     HRESULT hr;
@@ -3103,7 +3124,7 @@ ole_propertyput(VALUE self, VALUE proper https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole.c#L3124
     VariantInit(&propertyValue[1]);
     memset(&excepinfo, 0, sizeof(excepinfo));
 
-    OLEData_Get_Struct(self, pole);
+    pole = oledata_get_struct(self);
 
     /* get ID from property name */
     pBuf[0]  = ole_vstr2wc(property);
@@ -3147,8 +3168,8 @@ ole_propertyput(VALUE self, VALUE proper https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole.c#L3168
 static VALUE
 fole_free(VALUE self)
 {
-    struct oledata *pole;
-    OLEData_Get_Struct(self, pole);
+    struct oledata *pole = NULL;
+    pole = oledata_get_struct(self);
     OLE_FREE(pole->pDispatch);
     pole->pDispatch = NULL;
     return Qnil;
@@ -3197,7 +3218,7 @@ fole_each(VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole.c#L3218
 {
     LCID    lcid = cWIN32OLE_lcid;
 
-    struct oledata *pole;
+    struct oledata *pole = NULL;
 
     unsigned int argErr;
     EXCEPINFO excepinfo;
@@ -3216,7 +3237,7 @@ fole_each(VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole.c#L3237
     dispParams.cArgs = 0;
     memset(&excepinfo, 0, sizeof(excepinfo));
 
-    OLEData_Get_Struct(self, pole);
+    pole = oledata_get_struct(self);
     hr = pole->pDispatch->lpVtbl->Invoke(pole->pDispatch, DISPID_NEWENUM,
                                          &IID_NULL, lcid,
                                          DISPATCH_METHOD | DISPATCH_PROPERTYGET,
@@ -3332,9 +3353,9 @@ ole_methods(VALUE self, int mask) https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole.c#L3353
     ITypeInfo *pTypeInfo;
     HRESULT hr;
     VALUE methods;
-    struct oledata *pole;
+    struct oledata *pole = NULL;
 
-    OLEData_Get_Struct(self, pole);
+    pole = oledata_get_struct(self);
     methods = rb_ary_new();
 
     hr = typeinfo_from_ole(pole, &pTypeInfo);
@@ -3425,11 +3446,11 @@ fole_type(VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole.c#L3446
 {
     ITypeInfo *pTypeInfo;
     HRESULT hr;
-    struct oledata *pole;
+    struct oledata *pole = NULL;
     LCID  lcid = cWIN32OLE_lcid;
     VALUE type = Qnil;
 
-    OLEData_Get_Struct(self, pole);
+    pole = oledata_get_struct(self);
 
     hr = pole->pDispatch->lpVtbl->GetTypeInfo( pole->pDispatch, 0, lcid, &pTypeInfo );
     if(FAILED(hr)) {
@@ -3457,13 +3478,13 @@ fole_type(VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole.c#L3478
 static VALUE
 fole_typelib(VALUE self)
 {
-    struct oledata *pole;
+    struct oledata *pole = NULL;
     HRESULT hr;
     ITypeInfo *pTypeInfo;
     LCID  lcid = cWIN32OLE_lcid;
     VALUE vtlib = Qnil;
 
-    OLEData_Get_Struct(self, pole);
+    pole = oledata_get_struct(self);
     hr = pole->pDispatch->lpVtbl->GetTypeInfo(pole->pDispatch,
                                               0, lcid, &pTypeInfo);
     if(FAILED(hr)) {
@@ -3493,7 +3514,7 @@ fole_query_interface(VALUE self, VALUE s https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole.c#L3514
     HRESULT hr;
     OLECHAR *pBuf;
     IID iid;
-    struct oledata *pole;
+    struct oledata *pole = NULL;
     IDispatch *pDispatch;
     void *p;
 
@@ -3506,7 +3527,7 @@ fole_query_interface(VALUE self, VALUE s https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole.c#L3527
                   StringValuePtr(str_iid));
     }
 
-    OLEData_Get_Struct(self, pole);
+    pole = oledata_get_struct(self);
     if(!pole->pDispatch) {
         rb_raise(rb_eRuntimeError, "failed to get dispatch interface");
     }
@@ -3535,7 +3556,7 @@ fole_query_interface(VALUE self, VALUE s https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole.c#L3556
 static VALUE
 fole_respond_to(VALUE self, VALUE method)
 {
-    struct oledata *pole;
+    struct oledata *pole = NULL;
     BSTR wcmdname;
     DISPID DispID;
     HRESULT hr;
@@ -3545,7 +3566,7 @@ fole_respond_to(VALUE self, VALUE method https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole.c#L3566
     if (RB_TYPE_P(method, T_SYMBOL)) {
         method = rb_sym_to_s(method);
     }
-    OLEData_Get_Struct(self, pole);
+    pole = oledata_get_struct(self);
     wcmdname = ole_vstr2wc(method);
     hr = pole->pDispatch->lpVtbl->GetIDsOfNames( pole->pDispatch, &IID_NULL,
 	    &wcmdname, 1, cWIN32OLE_lcid, &DispID);
@@ -3748,11 +3769,11 @@ fole_method_help(VALUE self, VALUE cmdna https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole.c#L3769
 {
     ITypeInfo *pTypeInfo;
     HRESULT hr;
-    struct oledata *pole;
+    struct oledata *pole = NULL;
     VALUE obj;
 
     SafeStringValue(cmdname);
-    OLEData_Get_Struct(self, pole);
+    pole = oledata_get_struct(self);
     hr = typeinfo_from_ole(pole, &pTypeInfo);
     if(FAILED(hr))
         ole_raise(hr, rb_eRuntimeError, "failed to get ITypeInfo");
@@ -3789,13 +3810,13 @@ fole_method_help(VALUE self, VALUE cmdna https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole.c#L3810
 static VALUE
 fole_activex_initialize(VALUE self)
 {
-    struct oledata *pole;
+    struct oledata *pole = NULL;
     IPersistMemory *pPersistMemory;
     void *p;
 
     HRESULT hr = S_OK;
 
-    OLEData_Get_Struct(self, pole);
+    pole = oledata_get_struct(self);
 
     hr = pole->pDispatch->lpVtbl->QueryInterface(pole->pDispatch, &IID_IPersistMemory, &p);
     pPersistMemory = p;
@@ -3819,10 +3840,10 @@ typelib_from_val(VALUE obj, ITypeLib **p https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole.c#L3840
 {
     LCID lcid = cWIN32OLE_lcid;
     HRESULT hr;
-    struct oledata *pole;
+    struct oledata *pole = NULL;
     unsigned int index;
     ITypeInfo *pTypeInfo;
-    OLEData_Get_Struct(obj, pole);
+    pole = oledata_get_struct(obj);
     hr = pole->pDispatch->lpVtbl->GetTypeInfo(pole->pDispatch,
                                               0, lcid, &pTypeInfo);
     if (FAILED(hr)) {
Index: ext/win32ole/win32ole_event.c
===================================================================
--- ext/win32ole/win32ole_event.c	(revision 48664)
+++ ext/win32ole/win32ole_event.c	(revision 48665)
@@ -485,7 +485,7 @@ find_iid(VALUE ole, char *pitf, IID *pii https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole_event.c#L485
     ITypeInfo *pImplTypeInfo;
     TYPEATTR *pImplTypeAttr;
 
-    struct oledata *pole;
+    struct oledata *pole = NULL;
     unsigned int index;
     unsigned int count;
     int type;
@@ -495,7 +495,7 @@ find_iid(VALUE ole, char *pitf, IID *pii https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole_event.c#L495
     BOOL is_found = FALSE;
     LCID    lcid = cWIN32OLE_lcid;
 
-    OLEData_Get_Struct(ole, pole);
+    pole = oledata_get_struct(ole);
 
     pDispatch = pole->pDispatch;
 
@@ -709,9 +709,9 @@ find_default_source(VALUE ole, IID *piid https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole_event.c#L709
     TYPEATTR *pTypeAttr;
     TYPEATTR *pTypeAttr2 = NULL;
 
-    struct oledata *pole;
+    struct oledata *pole = NULL;
 
-    OLEData_Get_Struct(ole, pole);
+    pole = oledata_get_struct(ole);
     pDispatch = pole->pDispatch;
     hr = pDispatch->lpVtbl->QueryInterface(pDispatch,
                                            &IID_IProvideClassInfo2,
@@ -896,7 +896,7 @@ ev_advise(int argc, VALUE *argv, VALUE s https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole_event.c#L896
 {
 
     VALUE ole, itf;
-    struct oledata *pole;
+    struct oledata *pole = NULL;
     char *pitf;
     HRESULT hr;
     IID iid;
@@ -930,7 +930,7 @@ ev_advise(int argc, VALUE *argv, VALUE s https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole_event.c#L930
         ole_raise(hr, rb_eRuntimeError, "interface not found");
     }
 
-    OLEData_Get_Struct(ole, pole);
+    pole = oledata_get_struct(ole);
     pDispatch = pole->pDispatch;
     hr = pDispatch->lpVtbl->QueryInterface(pDispatch,
                                            &IID_IConnectionPointContainer,
Index: ext/win32ole/win32ole.h
===================================================================
--- ext/win32ole/win32ole.h	(revision 48664)
+++ ext/win32ole/win32ole.h	(revision 48665)
@@ -112,16 +112,10 @@ struct oledata { https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole.h#L112
     IDispatch *pDispatch;
 };
 
-#define OLEData_Get_Struct(obj, pole) {\
-    Data_Get_Struct(obj, struct oledata, pole);\
-    if(!pole->pDispatch) {\
-        rb_raise(rb_eRuntimeError, "failed to get Dispatch Interface");\
-    }\
-}
-
 VALUE cWIN32OLE;
 LCID cWIN32OLE_lcid;
 
+struct oledata *oledata_get_struct(VALUE obj);
 LPWSTR ole_vstr2wc(VALUE vstr);
 LONG reg_open_key(HKEY hkey, const char *name, HKEY *phkey);
 LONG reg_open_vkey(HKEY hkey, VALUE key, HKEY *phkey);

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

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