ruby-changes:35073
From: suke <ko1@a...>
Date: Tue, 12 Aug 2014 23:21:32 +0900 (JST)
Subject: [ruby-changes:35073] suke:r47155 (trunk): * ext/win32ole/win32ole.c: refactoring. move some methods
suke 2014-08-12 23:21:22 +0900 (Tue, 12 Aug 2014) New Revision: 47155 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=47155 Log: * ext/win32ole/win32ole.c: refactoring. move some methods into win32ole_type.c / win32ole_method.c * ext/win32ole/win32ole.h: ditto. * ext/win32ole/win32ole_method.c: ditto. * ext/win32ole/win32ole_method.h: ditto. * ext/win32ole/win32ole_type.h: ditto. * ext/win32ole/win32ole_type.h: ditto. Modified files: trunk/ChangeLog trunk/ext/win32ole/win32ole.c trunk/ext/win32ole/win32ole.h trunk/ext/win32ole/win32ole_method.c trunk/ext/win32ole/win32ole_method.h trunk/ext/win32ole/win32ole_type.c trunk/ext/win32ole/win32ole_type.h Index: ChangeLog =================================================================== --- ChangeLog (revision 47154) +++ ChangeLog (revision 47155) @@ -1,3 +1,13 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Tue Aug 12 23:17:47 2014 Masaki Suketa <masaki.suketa@n...> + + * ext/win32ole/win32ole.c: refactoring. move some methods + into win32ole_type.c / win32ole_method.c + * ext/win32ole/win32ole.h: ditto. + * ext/win32ole/win32ole_method.c: ditto. + * ext/win32ole/win32ole_method.h: ditto. + * ext/win32ole/win32ole_type.h: ditto. + * ext/win32ole/win32ole_type.h: ditto. + Tue Aug 12 22:59:48 2014 Masaki Suketa <masaki.suketa@n...> * ext/win32ole/win32ole.c: refactoring. move Index: ext/win32ole/win32ole.c =================================================================== --- ext/win32ole/win32ole.c (revision 47154) +++ ext/win32ole/win32ole.c (revision 47155) @@ -103,7 +103,6 @@ typedef struct tagIEVENTSINKOBJ { https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole.c#L103 }IEVENTSINKOBJ, *PIEVENTSINKOBJ; VALUE cWIN32OLE; -VALUE cWIN32OLE_METHOD; VALUE cWIN32OLE_PARAM; VALUE cWIN32OLE_EVENT; VALUE cWIN32OLE_VARIANT; @@ -3752,35 +3751,6 @@ fole_missing(int argc, VALUE *argv, VALU https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole.c#L3751 } } -VALUE -ole_methods_from_typeinfo(ITypeInfo *pTypeInfo, int mask) -{ - HRESULT hr; - TYPEATTR *pTypeAttr; - WORD i; - HREFTYPE href; - ITypeInfo *pRefTypeInfo; - VALUE methods = rb_ary_new(); - hr = OLE_GET_TYPEATTR(pTypeInfo, &pTypeAttr); - if (FAILED(hr)) { - ole_raise(hr, eWIN32OLERuntimeError, "failed to GetTypeAttr"); - } - - ole_methods_sub(0, pTypeInfo, methods, mask); - for(i=0; i < pTypeAttr->cImplTypes; i++){ - hr = pTypeInfo->lpVtbl->GetRefTypeOfImplType(pTypeInfo, i, &href); - if(FAILED(hr)) - continue; - hr = pTypeInfo->lpVtbl->GetRefTypeInfo(pTypeInfo, href, &pRefTypeInfo); - if (FAILED(hr)) - continue; - ole_methods_sub(pTypeInfo, pRefTypeInfo, methods, mask); - OLE_RELEASE(pRefTypeInfo); - } - OLE_RELEASE_TYPEATTR(pTypeInfo, pTypeAttr); - return methods; -} - static HRESULT typeinfo_from_ole(struct oledata *pole, ITypeInfo **ppti) { @@ -3907,29 +3877,6 @@ fole_func_methods(VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole.c#L3877 return ole_methods( self, INVOKE_FUNC); } -VALUE -ole_type_from_itypeinfo(ITypeInfo *pTypeInfo) -{ - ITypeLib *pTypeLib; - VALUE type = Qnil; - HRESULT hr; - unsigned int index; - BSTR bstr; - - hr = pTypeInfo->lpVtbl->GetContainingTypeLib( pTypeInfo, &pTypeLib, &index ); - if(FAILED(hr)) { - return Qnil; - } - hr = pTypeLib->lpVtbl->GetDocumentation( pTypeLib, index, - &bstr, NULL, NULL, NULL); - OLE_RELEASE(pTypeLib); - if (FAILED(hr)) { - return Qnil; - } - type = create_win32ole_type(pTypeInfo, WC2VSTR(bstr)); - return type; -} - /* * call-seq: * WIN32OLE#ole_type @@ -4268,7 +4215,7 @@ fole_method_help(VALUE self, VALUE cmdna https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole.c#L4215 ITypeInfo *pTypeInfo; HRESULT hr; struct oledata *pole; - VALUE method, obj; + VALUE obj; SafeStringValue(cmdname); OLEData_Get_Struct(self, pole); @@ -4276,8 +4223,7 @@ fole_method_help(VALUE self, VALUE cmdna https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole.c#L4223 if(FAILED(hr)) ole_raise(hr, rb_eRuntimeError, "failed to get ITypeInfo"); - method = folemethod_s_allocate(cWIN32OLE_METHOD); - obj = olemethod_from_typeinfo(method, pTypeInfo, cmdname); + obj = create_win32ole_method(pTypeInfo, cmdname); OLE_RELEASE(pTypeInfo); if (obj == Qnil) Index: ext/win32ole/win32ole_method.c =================================================================== --- ext/win32ole/win32ole_method.c (revision 47154) +++ ext/win32ole/win32ole_method.c (revision 47155) @@ -1,6 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole_method.c#L1 #include "win32ole.h" 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); @@ -85,6 +87,35 @@ ole_method_sub(VALUE self, ITypeInfo *pO https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole_method.c#L87 } VALUE +ole_methods_from_typeinfo(ITypeInfo *pTypeInfo, int mask) +{ + HRESULT hr; + TYPEATTR *pTypeAttr; + WORD i; + HREFTYPE href; + ITypeInfo *pRefTypeInfo; + VALUE methods = rb_ary_new(); + hr = OLE_GET_TYPEATTR(pTypeInfo, &pTypeAttr); + if (FAILED(hr)) { + ole_raise(hr, eWIN32OLERuntimeError, "failed to GetTypeAttr"); + } + + ole_methods_sub(0, pTypeInfo, methods, mask); + for(i=0; i < pTypeAttr->cImplTypes; i++){ + hr = pTypeInfo->lpVtbl->GetRefTypeOfImplType(pTypeInfo, i, &href); + if(FAILED(hr)) + continue; + hr = pTypeInfo->lpVtbl->GetRefTypeInfo(pTypeInfo, href, &pRefTypeInfo); + if (FAILED(hr)) + continue; + ole_methods_sub(pTypeInfo, pRefTypeInfo, methods, mask); + OLE_RELEASE(pRefTypeInfo); + } + OLE_RELEASE_TYPEATTR(pTypeInfo, pTypeAttr); + return methods; +} + +static VALUE olemethod_from_typeinfo(VALUE self, ITypeInfo *pTypeInfo, VALUE name) { HRESULT hr; @@ -115,7 +146,7 @@ olemethod_from_typeinfo(VALUE self, ITyp https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole_method.c#L146 return method; } -VALUE +static VALUE ole_methods_sub(ITypeInfo *pOwnerTypeInfo, ITypeInfo *pTypeInfo, VALUE methods, int mask) { HRESULT hr; @@ -153,6 +184,15 @@ ole_methods_sub(ITypeInfo *pOwnerTypeInf https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole_method.c#L184 return methods; } +VALUE +create_win32ole_method(ITypeInfo *pTypeInfo, VALUE name) +{ + + VALUE method = folemethod_s_allocate(cWIN32OLE_METHOD); + VALUE obj = olemethod_from_typeinfo(method, pTypeInfo, name); + return obj; +} + /* * Document-class: WIN32OLE_METHOD * Index: ext/win32ole/win32ole_type.c =================================================================== --- ext/win32ole/win32ole_type.c (revision 47154) +++ ext/win32ole/win32ole_type.c (revision 47155) @@ -66,6 +66,30 @@ ITypeInfo *itypeinfo(VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole_type.c#L66 return ptype->pTypeInfo; } +VALUE +ole_type_from_itypeinfo(ITypeInfo *pTypeInfo) +{ + ITypeLib *pTypeLib; + VALUE type = Qnil; + HRESULT hr; + unsigned int index; + BSTR bstr; + + hr = pTypeInfo->lpVtbl->GetContainingTypeLib( pTypeInfo, &pTypeLib, &index ); + if(FAILED(hr)) { + return Qnil; + } + hr = pTypeLib->lpVtbl->GetDocumentation( pTypeLib, index, + &bstr, NULL, NULL, NULL); + OLE_RELEASE(pTypeLib); + if (FAILED(hr)) { + return Qnil; + } + type = create_win32ole_type(pTypeInfo, WC2VSTR(bstr)); + return type; +} + + /* * call-seq: * WIN32OLE_TYPE.ole_classes(typelib) Index: ext/win32ole/win32ole.h =================================================================== --- ext/win32ole/win32ole.h (revision 47154) +++ ext/win32ole/win32ole.h (revision 47155) @@ -115,11 +115,10 @@ VALUE ole_wc2vstr(LPWSTR pw, BOOL isfree https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole.h#L115 BOOL ole_initialized(); HRESULT ole_docinfo_from_type(ITypeInfo *pTypeInfo, BSTR *name, BSTR *helpstr, DWORD *helpcontext, BSTR *helpfile); VALUE ole_typedesc2val(ITypeInfo *pTypeInfo, TYPEDESC *pTypeDesc, VALUE typedetails); -VALUE ole_type_from_itypeinfo(ITypeInfo *pTypeInfo); VALUE make_inspect(const char *class_name, VALUE detail); VALUE ole_variant2val(VARIANT *pvar); -VALUE ole_methods_from_typeinfo(ITypeInfo *pTypeInfo, int mask); VALUE create_win32ole_param(ITypeInfo *pTypeInfo, UINT method_index, UINT index, VALUE name); + #include "win32ole_variant_m.h" #include "win32ole_typelib.h" #include "win32ole_type.h" Index: ext/win32ole/win32ole_method.h =================================================================== --- ext/win32ole/win32ole_method.h (revision 47154) +++ ext/win32ole/win32ole_method.h (revision 47155) @@ -9,7 +9,7 @@ struct olemethoddata { https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole_method.h#L9 VALUE cWIN32OLE_METHOD; VALUE folemethod_s_allocate(VALUE klass); -VALUE olemethod_from_typeinfo(VALUE self, ITypeInfo *pTypeInfo, VALUE name); -VALUE ole_methods_sub(ITypeInfo *pOwnerTypeInfo, ITypeInfo *pTypeInfo, VALUE methods, int mask); +VALUE ole_methods_from_typeinfo(ITypeInfo *pTypeInfo, int mask); +VALUE create_win32ole_method(ITypeInfo *pTypeInfo, VALUE name); void Init_win32ole_method(); #endif Index: ext/win32ole/win32ole_type.h =================================================================== --- ext/win32ole/win32ole_type.h (revision 47154) +++ ext/win32ole/win32ole_type.h (revision 47155) @@ -3,5 +3,6 @@ https://github.com/ruby/ruby/blob/trunk/ext/win32ole/win32ole_type.h#L3 VALUE cWIN32OLE_TYPE; VALUE create_win32ole_type(ITypeInfo *pTypeInfo, VALUE name); ITypeInfo *itypeinfo(VALUE self); +VALUE ole_type_from_itypeinfo(ITypeInfo *pTypeInfo); void Init_win32ole_type(); #endif -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/