From 5d71328bca0ebb29859d574d204d74c499030232 Mon Sep 17 00:00:00 2001 From: suke Date: Fri, 23 Sep 2005 08:39:24 +0000 Subject: [PATCH] avoid core dump with WIN32OLE_EVENT. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9282 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ ext/win32ole/tests/testOLEEVENT.rb | 18 ++++++++++++++++++ ext/win32ole/tests/testall.rb | 4 ++-- ext/win32ole/win32ole.c | 16 +++++++++++++--- 4 files changed, 38 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index a140d11f72..d7030bb1a0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Fri Sep 23 17:36:48 2005 Masaki Suketa + + * ext/win32ole/win32ole.c: avoid core dump with WIN32OLE_EVENT. + [ruby-dev:27133] + Fri Sep 23 07:07:47 2005 Minero Aoki * test/ripper/depend: use --output option instead of redirect; diff --git a/ext/win32ole/tests/testOLEEVENT.rb b/ext/win32ole/tests/testOLEEVENT.rb index 368794b150..0901158642 100644 --- a/ext/win32ole/tests/testOLEEVENT.rb +++ b/ext/win32ole/tests/testOLEEVENT.rb @@ -6,6 +6,7 @@ class TestWIN32OLE_EVENT < RUNIT::TestCase @excel = WIN32OLE.new("Excel.Application") @excel.visible = true @event = "" + @event2 = "" end def test_on_event book = @excel.workbooks.Add @@ -33,6 +34,10 @@ class TestWIN32OLE_EVENT < RUNIT::TestCase @event += "handler2" end + def handler3 + @event += "handler3" + end + def test_on_event2 book = @excel.workbooks.Add begin @@ -63,6 +68,19 @@ class TestWIN32OLE_EVENT < RUNIT::TestCase assert_equal("handler2", @event) end + def test_on_event4 + book = @excel.workbooks.Add + begin + ev = WIN32OLE_EVENT.new(book, 'WorkbookEvents') + ev.on_event{ handler1 } + ev.on_event{ handler2 } + ev.on_event('SheetChange'){|arg1, arg2| handler3 } + book.Worksheets(1).Range("A1").value = "OK" + ensure + book.saved = true + end + assert_equal("handler3", @event) + end def teardown @excel.quit diff --git a/ext/win32ole/tests/testall.rb b/ext/win32ole/tests/testall.rb index 6bd3797718..a87b6bceaf 100644 --- a/ext/win32ole/tests/testall.rb +++ b/ext/win32ole/tests/testall.rb @@ -8,5 +8,5 @@ require "testOLEMETHOD" require "testOLEVARIABLE" require "testVARIANT" require "testOLETYPELIB" -# require "testOLEVARIANT" -# require "testOLEEVENT" +require "testOLEVARIANT" +require "testOLEEVENT" diff --git a/ext/win32ole/win32ole.c b/ext/win32ole/win32ole.c index 9f756c44c4..32d92b639e 100644 --- a/ext/win32ole/win32ole.c +++ b/ext/win32ole/win32ole.c @@ -79,7 +79,7 @@ #define WC2VSTR(x) ole_wc2vstr((x), TRUE) -#define WIN32OLE_VERSION "0.6.8" +#define WIN32OLE_VERSION "0.6.9" typedef HRESULT (STDAPICALLTYPE FNCOCREATEINSTANCEEX) (REFCLSID, IUnknown*, DWORD, COSERVERINFO*, DWORD, MULTI_QI*); @@ -135,6 +135,7 @@ typedef struct tagIEVENTSINKOBJ { DWORD m_dwCookie; IConnectionPoint *pConnectionPoint; ITypeInfo *pTypeInfo; + int *ptr_freed; }IEVENTSINKOBJ, *PIEVENTSINKOBJ; VALUE cWIN32OLE; @@ -186,6 +187,7 @@ struct oleparamdata { struct oleeventdata { IEVENTSINKOBJ *pEvent; + int freed; }; struct oleparam { @@ -6253,7 +6255,9 @@ ole_search_event_at(ary, ev) ret = i; break; } - else if (rb_str_cmp(ev, event_name) == 0) { + else if (TYPE(ev) == T_STRING && + TYPE(event_name) == T_STRING && + rb_str_cmp(ev, event_name) == 0) { ret = i; break; } @@ -6399,6 +6403,7 @@ EVENTSINK_Constructor() { pEv->m_dwCookie = 0; pEv->pConnectionPoint = NULL; pEv->pTypeInfo = NULL; + pEv->ptr_freed = NULL; return pEv; } @@ -6406,6 +6411,7 @@ void EVENTSINK_Destructor( PIEVENTSINKOBJ pEVObj ) { if(pEVObj != NULL) { + *(pEVObj->ptr_freed) = 1; free(pEVObj); } } @@ -6627,6 +6633,9 @@ ole_event_free(poleev) ITypeInfo *pti = NULL; IConnectionPoint *pcp = NULL; + if (poleev->freed == 1) { + return; + } if(poleev->pEvent) { pti = poleev->pEvent->pTypeInfo; if(pti) OLE_RELEASE(pti); @@ -6737,7 +6746,8 @@ fev_initialize(argc, argv, self) poleev->pEvent->pConnectionPoint = pConnectionPoint; poleev->pEvent->pTypeInfo = pTypeInfo; poleev->pEvent->m_dwCookie = dwCookie; - + poleev->freed = 0; + poleev->pEvent->ptr_freed = &(poleev->freed); rb_ary_push(ary_ole_event, self); return self; }