1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

avoid core dump with WIN32OLE_EVENT.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9282 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
suke 2005-09-23 08:39:24 +00:00
parent 883c6bf742
commit 5d71328bca
4 changed files with 38 additions and 5 deletions

View file

@ -1,3 +1,8 @@
Fri Sep 23 17:36:48 2005 Masaki Suketa <masaki.suketa@nifty.ne.jp>
* ext/win32ole/win32ole.c: avoid core dump with WIN32OLE_EVENT.
[ruby-dev:27133]
Fri Sep 23 07:07:47 2005 Minero Aoki <aamine@loveruby.net> Fri Sep 23 07:07:47 2005 Minero Aoki <aamine@loveruby.net>
* test/ripper/depend: use --output option instead of redirect; * test/ripper/depend: use --output option instead of redirect;

View file

@ -6,6 +6,7 @@ class TestWIN32OLE_EVENT < RUNIT::TestCase
@excel = WIN32OLE.new("Excel.Application") @excel = WIN32OLE.new("Excel.Application")
@excel.visible = true @excel.visible = true
@event = "" @event = ""
@event2 = ""
end end
def test_on_event def test_on_event
book = @excel.workbooks.Add book = @excel.workbooks.Add
@ -33,6 +34,10 @@ class TestWIN32OLE_EVENT < RUNIT::TestCase
@event += "handler2" @event += "handler2"
end end
def handler3
@event += "handler3"
end
def test_on_event2 def test_on_event2
book = @excel.workbooks.Add book = @excel.workbooks.Add
begin begin
@ -63,6 +68,19 @@ class TestWIN32OLE_EVENT < RUNIT::TestCase
assert_equal("handler2", @event) assert_equal("handler2", @event)
end 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 def teardown
@excel.quit @excel.quit

View file

@ -8,5 +8,5 @@ require "testOLEMETHOD"
require "testOLEVARIABLE" require "testOLEVARIABLE"
require "testVARIANT" require "testVARIANT"
require "testOLETYPELIB" require "testOLETYPELIB"
# require "testOLEVARIANT" require "testOLEVARIANT"
# require "testOLEEVENT" require "testOLEEVENT"

View file

@ -79,7 +79,7 @@
#define WC2VSTR(x) ole_wc2vstr((x), TRUE) #define WC2VSTR(x) ole_wc2vstr((x), TRUE)
#define WIN32OLE_VERSION "0.6.8" #define WIN32OLE_VERSION "0.6.9"
typedef HRESULT (STDAPICALLTYPE FNCOCREATEINSTANCEEX) typedef HRESULT (STDAPICALLTYPE FNCOCREATEINSTANCEEX)
(REFCLSID, IUnknown*, DWORD, COSERVERINFO*, DWORD, MULTI_QI*); (REFCLSID, IUnknown*, DWORD, COSERVERINFO*, DWORD, MULTI_QI*);
@ -135,6 +135,7 @@ typedef struct tagIEVENTSINKOBJ {
DWORD m_dwCookie; DWORD m_dwCookie;
IConnectionPoint *pConnectionPoint; IConnectionPoint *pConnectionPoint;
ITypeInfo *pTypeInfo; ITypeInfo *pTypeInfo;
int *ptr_freed;
}IEVENTSINKOBJ, *PIEVENTSINKOBJ; }IEVENTSINKOBJ, *PIEVENTSINKOBJ;
VALUE cWIN32OLE; VALUE cWIN32OLE;
@ -186,6 +187,7 @@ struct oleparamdata {
struct oleeventdata { struct oleeventdata {
IEVENTSINKOBJ *pEvent; IEVENTSINKOBJ *pEvent;
int freed;
}; };
struct oleparam { struct oleparam {
@ -6253,7 +6255,9 @@ ole_search_event_at(ary, ev)
ret = i; ret = i;
break; 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; ret = i;
break; break;
} }
@ -6399,6 +6403,7 @@ EVENTSINK_Constructor() {
pEv->m_dwCookie = 0; pEv->m_dwCookie = 0;
pEv->pConnectionPoint = NULL; pEv->pConnectionPoint = NULL;
pEv->pTypeInfo = NULL; pEv->pTypeInfo = NULL;
pEv->ptr_freed = NULL;
return pEv; return pEv;
} }
@ -6406,6 +6411,7 @@ void EVENTSINK_Destructor(
PIEVENTSINKOBJ pEVObj PIEVENTSINKOBJ pEVObj
) { ) {
if(pEVObj != NULL) { if(pEVObj != NULL) {
*(pEVObj->ptr_freed) = 1;
free(pEVObj); free(pEVObj);
} }
} }
@ -6627,6 +6633,9 @@ ole_event_free(poleev)
ITypeInfo *pti = NULL; ITypeInfo *pti = NULL;
IConnectionPoint *pcp = NULL; IConnectionPoint *pcp = NULL;
if (poleev->freed == 1) {
return;
}
if(poleev->pEvent) { if(poleev->pEvent) {
pti = poleev->pEvent->pTypeInfo; pti = poleev->pEvent->pTypeInfo;
if(pti) OLE_RELEASE(pti); if(pti) OLE_RELEASE(pti);
@ -6737,7 +6746,8 @@ fev_initialize(argc, argv, self)
poleev->pEvent->pConnectionPoint = pConnectionPoint; poleev->pEvent->pConnectionPoint = pConnectionPoint;
poleev->pEvent->pTypeInfo = pTypeInfo; poleev->pEvent->pTypeInfo = pTypeInfo;
poleev->pEvent->m_dwCookie = dwCookie; poleev->pEvent->m_dwCookie = dwCookie;
poleev->freed = 0;
poleev->pEvent->ptr_freed = &(poleev->freed);
rb_ary_push(ary_ole_event, self); rb_ary_push(ary_ole_event, self);
return self; return self;
} }