Hi -
I'm trying to upgrade our copy of QuantLib from 0.8.0 to 1.1.0. Both the debug and release versions that I've built crash on exit if I've made a QuantLibXL call which returns an object (for Example, qlSimpleQuote(,5,5). If I don't call any QuantLib functions, or call functions that only return strings - for example qlxlVersion - excel exits normally. To make sure this is not something specific to my environment - I built a clean windows 7 (x64) machine which only has a fresh copy of office 2007 and visual studio 2005, all fully patched. Both the 1.1 build and the current svn build still crash on exit. On my previous machine I tried VS 2008 which also failed. I've tried boost 1.42 and boost 1.47. When I run excel from the VS2005 debugger, I get an error like: Unhandled exception at 0x10abec61 in excel.exe: 0xC0000005: Access violation reading location 0x10abec61. The stack trace does not show any QuantLib calls: 14cc29c2() ntdll.dll!77b49a91() [Frames below may be incorrect and/or missing, no symbols loaded for ntdll.dll] ntdll.dll!77b68f10() ntdll.dll!77b68e5c() kernel32.dll!76ba79f5() > msvcr80.dll!__crtExitProcess(int status=0) Line 683 + 0xa bytes C msvcr80.dll!doexit(int code=0, int quick=0, int retcaller=797589938) Line 584 C msvcr80.dll!exit(int code=0) Line 398 + 0xd bytes C EXCEL.EXE!2f8a41b2() EXCEL.EXE!2f88fd0a() EXCEL.EXE!2f83b610() EXCEL.EXE!2f850ab5() msctf.dll!75332b9b() msctf.dll!75332b51() msctf.dll!75332d99() msctf.dll!75332d6d() msctf.dll!75332d49() EXCEL.EXE!2f850a63() ntdll.dll!77b48133() ntdll.dll!77b48133() KernelBase.dll!7688491d() KernelBase.dll!76884933() msctf.dll!75326276() msctf.dll!7532625c() msctf.dll!7533fcef() MSO.DLL!31ab7ada() user32.dll!755c29c3() user32.dll!755c29a6() EXCEL.EXE!2f84ba96() EXCEL.EXE!2f88fbcf() user32.dll!755b6ce9() user32.dll!755b717a() user32.dll!755b7257() user32.dll!755b8e0d() user32.dll!755b8de4() uxtheme.dll!737f76a5() uxtheme.dll!737f7650() user32.dll!755b62fa() user32.dll!755b6d91() user32.dll!755b6d51() EXCEL.EXE!2f8269b5() user32.dll!755b6d91() user32.dll!755b6d51() user32.dll!755b6de8() user32.dll!755b6df3() user32.dll!755b6df3() user32.dll!755b9a21() ntdll.dll!77b2f8da() user32.dll!755b9a49() ntdll.dll!77b2011a() MSO.DLL!31b13f65() MSO.DLL!31b13f09() EXCEL.EXE!2f83e271() EXCEL.EXE!2f826935() user32.dll!755b62fa() user32.dll!755b6d3a() user32.dll!755b6ce9() user32.dll!755c0d27() user32.dll!755c0d4d() MSO.DLL!31adeded() user32.dll!755b62fa() user32.dll!755b7316() user32.dll!755b6ce9() user32.dll!755b77c4() user32.dll!755b788a() EXCEL.EXE!2f848ec2() EXCEL.EXE!2f848deb() EXCEL.EXE!2f848bcb() MSO.DLL!31aa6092() MSO.DLL!31aa5e59() MSO.DLL!31aa94f9() MSO.DLL!31aa94b1() EXCEL.EXE!2f823b60() msvcr80.dll!_onexit(int (void)* func=0x00486c5b) Line 98 + 0x5 bytes C msvcr80.dll!_LocaleUpdate::_LocaleUpdate(localeinfo_struct * plocinfo=0x0025f894) Line 264 + 0x5 bytes C++ msvcr80.dll!_ismbblead(unsigned int tst=797048832) Line 172 + 0xf bytes C++ EXCEL.EXE!2f823874() kernel32.dll!76ba339a() ntdll.dll!77b49ed2() ntdll.dll!77b49ea5() I noticed a thread like this a few years ago and never saw any resolution to it - is it a known bug? Any suggestions on how I might proceed - are other version of visual studio or boost known to work better? Thanks, Dave |
I think I've found the problem-
It looks like when CallingRanges are destroyed, they call Excel(xlfSetName, ...). However I see CallingRanges being destroyed after xlAutoClose, which calls Excel(xlfFree). I think this causes the seg faults. To fix the problem I added ReposityXL::clear() - which merely calls calllingNames_.clear(). I call ObjectHandler::ReposityXL::instance().clear() before Excel(xlfFree) - and the access violations seem to have gone away. I can submit a patch if you think this it is helpful (right now I have a patch for a heavily stripped down version that I used to isolate the bug). Best, Dave
|
Hi Dave,
On Thu, 2011-12-08 at 13:27 -0800, Dave Blob wrote: > I think I've found the problem- > > It looks like when CallingRanges are destroyed, they call Excel(xlfSetName, > ...). However I see CallingRanges being destroyed after xlAutoClose, which > calls Excel(xlfFree). I think this causes the seg faults. > > To fix the problem I added ReposityXL::clear() - which merely calls > calllingNames_.clear(). I call > ObjectHandler::ReposityXL::instance().clear() before Excel(xlfFree) - and > the access violations seem to have gone away. I can submit a patch if you > think this it is helpful (right now I have a patch for a heavily stripped > down version that I used to isolate the bug). That would be much appreciated if you could send a patch. When I package up the next release I will try to recreate the bug and test your fix. Kind Regards, Eric ------------------------------------------------------------------------------ Cloud Services Checklist: Pricing and Packaging Optimization This white paper is intended to serve as a reference, checklist and point of discussion for anyone considering optimizing the pricing and packaging model of a cloud services business. Read Now! http://www.accelacomm.com/jaw/sfnl/114/51491232/ _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
Hi Eric - Here is a patch which I believe fixes the problem. I think you can recreate the problem by running Excel 2007 from the visual studio debugger after having built the static debug xll; Load your newly built addin; Call a quantlib function that returns an object and Exit Excel. You should see an access violation. I think I misspoke a little when I described what causes Excel to fail. It seems to have something to do with some facilities not being available after a certain point as Excel shuts down. In this case, Excel calls xlAutoClose and well after it finishes the normal C++ exit proceeds and the xll calls its own destructors including one for callingRanges_; the destructor for CallingRange calls xlfSetName but those calls are no longer available. As a result, they seem to seg fault. This patch forces the last of the QuantLib's xlfSetName calls to happen before xlAutoClose finishes in a relatively simple way. Best, Dave Index: QuantLibXL/qlxl/register/addin.cpp =================================================================== --- QuantLibXL/qlxl/register/addin.cpp (revision 113) +++ QuantLibXL/qlxl/register/addin.cpp (working copy) @@ -153,6 +153,10 @@ // Unregister QuantLib functions unregisterQlFunctions(xDll); + // Clean objects out of the repository before we close the xll + // since their destructors call Excel(xlfSetName) + ObjectHandler::RepositoryXL::instance().clearCallingRangeCache(); + // Deallocate the Enumeration Registry QuantLibAddin::unregisterEnumerations(); Index: ObjectHandler/ohxl/register/addin.cpp =================================================================== --- ObjectHandler/ohxl/register/addin.cpp (revision 113) +++ ObjectHandler/ohxl/register/addin.cpp (working copy) @@ -76,6 +76,8 @@ // unregister the addin functions Excel(xlGetName, &xDll, 0); unregisterOhFunctions(xDll); + + ObjectHandler::RepositoryXL::instance().clearCallingRangeCache(); Excel(xlFree, 0, 1, &xDll); return 1; Index: ObjectHandler/ohxl/repositoryxl.cpp =================================================================== --- ObjectHandler/ohxl/repositoryxl.cpp (revision 113) +++ ObjectHandler/ohxl/repositoryxl.cpp (working copy) @@ -56,6 +56,10 @@ typedef std::map<std::string, boost::shared_ptr<CallingRange> > RangeMap; RangeMap callingRanges_; + void RepositoryXL::clearCallingRangeCache() { + callingRanges_.clear(); + } + RepositoryXL &RepositoryXL::instance() { if (instance_) { RepositoryXL *ret = dynamic_cast<RepositoryXL*>(instance_); Index: ObjectHandler/ohxl/repositoryxl.hpp =================================================================== --- ObjectHandler/ohxl/repositoryxl.hpp (revision 113) +++ ObjectHandler/ohxl/repositoryxl.hpp (working copy) @@ -51,6 +51,11 @@ virtual std::string storeObject(const std::string &objectID, const boost::shared_ptr<Object> &obj, bool overwrite = false); + //@{ + //! Method to cleanup local variables before exit. + /*! Clears the CallingRange cache + */ + virtual void clearCallingRangeCache(); //@} //! \name Error Messages > Subject: Re: [Quantlib-users] Excel 2007 crashes on exit after QLXL call that returns an object > From: [hidden email] > To: [hidden email] > CC: [hidden email] > Date: Fri, 9 Dec 2011 11:21:12 +0100 > > Hi Dave, > > On Thu, 2011-12-08 at 13:27 -0800, Dave Blob wrote: > > I think I've found the problem- > > > > It looks like when CallingRanges are destroyed, they call Excel(xlfSetName, > > ...). However I see CallingRanges being destroyed after xlAutoClose, which > > calls Excel(xlfFree). I think this causes the seg faults. > > > > To fix the problem I added ReposityXL::clear() - which merely calls > > calllingNames_.clear(). I call > > ObjectHandler::ReposityXL::instance().clear() before Excel(xlfFree) - and > > the access violations seem to have gone away. I can submit a patch if you > > think this it is helpful (right now I have a patch for a heavily stripped > > down version that I used to isolate the bug). > > That would be much appreciated if you could send a patch. When I > package up the next release I will try to recreate the bug and test your > fix. > > Kind Regards, > Eric > ------------------------------------------------------------------------------ Learn Windows Azure Live! Tuesday, Dec 13, 2011 Microsoft is holding a special Learn Windows Azure training event for developers. It will provide a great way to learn Windows Azure and what it provides. You can attend the event by watching it streamed LIVE online. Learn more at http://p.sf.net/sfu/ms-windowsazure _______________________________________________ QuantLib-users mailing list [hidden email] https://lists.sourceforge.net/lists/listinfo/quantlib-users |
Free forum by Nabble | Edit this page |