ruby-changes:6808
From: suke <ko1@a...>
Date: Sun, 3 Aug 2008 19:44:03 +0900 (JST)
Subject: [ruby-changes:6808] Ruby:r18324 (trunk): * ext/win32ole/win32ole.c (hash2named_arg): refactoring.
suke 2008-08-03 19:43:44 +0900 (Sun, 03 Aug 2008) New Revision: 18324 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=18324 Log: * ext/win32ole/win32ole.c (hash2named_arg): refactoring. * ext/win32ole/win32ole.c (ole_invoke, fole_respond_to, ev_on_event, fev_off_event): accepts Symbol argument. * test/win32ole/test_win32ole.rb: ditto. * test/win32ole/test_win32ole_event.rb: ditto. Modified files: trunk/ChangeLog trunk/ext/win32ole/win32ole.c trunk/test/win32ole/test_win32ole.rb trunk/test/win32ole/test_win32ole_event.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 18323) +++ ChangeLog (revision 18324) @@ -1,3 +1,14 @@ +Sun Aug 3 19:32:52 2008 Masaki Suketa <masaki.suketa@n...> + + * ext/win32ole/win32ole.c (hash2named_arg): refactoring. + + * ext/win32ole/win32ole.c (ole_invoke, fole_respond_to, ev_on_event, + fev_off_event): accepts Symbol argument. + + * test/win32ole/test_win32ole.rb: ditto. + + * test/win32ole/test_win32ole_event.rb: ditto. + Sun Aug 3 10:41:54 2008 Nobuyoshi Nakada <nobu@r...> * string.c (rb_str_shared_replace): fixed memory leak. a patch from Index: ext/win32ole/win32ole.c =================================================================== --- ext/win32ole/win32ole.c (revision 18323) +++ ext/win32ole/win32ole.c (revision 18324) @@ -118,7 +118,7 @@ #define WC2VSTR(x) ole_wc2vstr((x), TRUE) -#define WIN32OLE_VERSION "1.3.0" +#define WIN32OLE_VERSION "1.3.1" typedef HRESULT (STDAPICALLTYPE FNCOCREATEINSTANCEEX) (REFCLSID, IUnknown*, DWORD, COSERVERINFO*, DWORD, MULTI_QI*); @@ -3162,7 +3162,7 @@ rb_raise(rb_eTypeError, "wrong argument type (expected String or Symbol)"); } if (TYPE(key) == T_SYMBOL) { - key = rb_str_new2(rb_id2name(SYM2ID(key))); + key = rb_sym_to_s(key); } /* pNamedArgs[0] is <method name>, so "index + 1" */ @@ -3225,6 +3225,12 @@ op.dp.cArgs = 0; rb_scan_args(argc, argv, "1*", &cmd, ¶mS); + if(TYPE(cmd) != T_STRING && TYPE(cmd) != T_SYMBOL) { + rb_raise(rb_eTypeError, "method is wrong type (expected String or Symbol)"); + } + if (TYPE(cmd) == T_SYMBOL) { + cmd = rb_sym_to_s(cmd); + } OLEData_Get_Struct(self, pole); if(!pole->pDispatch) { rb_raise(rb_eRuntimeError, "failed to get dispatch interface"); @@ -4417,7 +4423,12 @@ DISPID DispID; HRESULT hr; rb_secure(4); - Check_SafeStr(method); + if(TYPE(method) != T_STRING && TYPE(method) != T_SYMBOL) { + rb_raise(rb_eTypeError, "wrong argument type (expected String or Symbol)"); + } + if (TYPE(method) == T_SYMBOL) { + method = rb_sym_to_s(method); + } OLEData_Get_Struct(self, pole); wcmdname = ole_vstr2wc(method); hr = pole->pDispatch->lpVtbl->GetIDsOfNames( pole->pDispatch, &IID_NULL, @@ -8143,7 +8154,12 @@ } rb_scan_args(argc, argv, "01*", &event, &args); if(!NIL_P(event)) { - Check_SafeStr(event); + if(TYPE(event) != T_STRING && TYPE(event) != T_SYMBOL) { + rb_raise(rb_eTypeError, "wrong argument type (expected String or Symbol)"); + } + if (TYPE(event) == T_SYMBOL) { + event = rb_sym_to_s(event); + } } data = rb_ary_new3(4, rb_block_proc(), event, args, is_ary_arg); add_event_call_back(self, event, data); @@ -8229,7 +8245,12 @@ rb_secure(4); rb_scan_args(argc, argv, "01", &event); if(!NIL_P(event)) { - Check_SafeStr(event); + if(TYPE(event) != T_STRING && TYPE(event) != T_SYMBOL) { + rb_raise(rb_eTypeError, "wrong argument type (expected String or Symbol)"); + } + if (TYPE(event) == T_SYMBOL) { + event = rb_sym_to_s(event); + } } events = rb_ivar_get(self, id_events); if (NIL_P(events)) { Index: test/win32ole/test_win32ole.rb =================================================================== --- test/win32ole/test_win32ole.rb (revision 18323) +++ test/win32ole/test_win32ole.rb (revision 18324) @@ -250,12 +250,19 @@ fso = WIN32OLE.new('Scripting.FileSystemObject') assert(fso.ole_respond_to?('getFolder')) assert(fso.ole_respond_to?('GETFOLDER')) + assert(fso.ole_respond_to?(:getFolder)) assert(!fso.ole_respond_to?('XXXXX')) assert_raise(TypeError) { assert_raise(fso.ole_respond_to?(1)) } end + def test_invoke + fso = WIN32OLE.new('Scripting.FileSystemObject') + assert(fso.invoke(:getFolder, ".")) + assert(fso.invoke('getFolder', ".")) + end + def test_s_const_load assert(!defined?(CONST1::SsfWINDOWS)) shell=WIN32OLE.new('Shell.Application') Index: test/win32ole/test_win32ole_event.rb =================================================================== --- test/win32ole/test_win32ole_event.rb (revision 18323) +++ test/win32ole/test_win32ole_event.rb (revision 18324) @@ -76,6 +76,16 @@ assert_match(/NavigateComplete/, @event) end + def test_on_event_symbol + ev = WIN32OLE_EVENT.new(@ie) + ev.on_event(:BeforeNavigate2) {|*args| + handler1 + } + @ie.navigate("file:///#{@f}") + wait_ie + assert_equal("handler1", @event2) + end + def test_on_event2 ev = WIN32OLE_EVENT.new(@ie, 'DWebBrowserEvents') ev.on_event('BeforeNavigate') {|*args| handler1} @@ -229,6 +239,15 @@ assert_equal("", @event2) end + def test_off_event_sym_arg + ev = WIN32OLE_EVENT.new(@ie) + ev.on_event('BeforeNavigate2'){handler1} + ev.off_event(:BeforeNavigate2) + @ie.navigate("file:///#{@f}") + wait_ie + assert_equal("", @event2) + end + def handler1 @event2 = "handler1" end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/