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>
* 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.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

View file

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

View file

@ -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;
}