pure virtual function call in observable update

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

pure virtual function call in observable update

Fischbein, Alan: C12 (NYK)
 
Hi,
 
This message is intended as a follow-up to:
I am experiencing the same issue as the one reported: random occurrences of "pure virtual function call" in the 'update' method in 'notifyObservers'. I tried the solution suggested by Henner Heck - using his new observable.hpp that uses "enable_shared_from_raw.hpp".
I got that file, and the new shared_ptr.hpp from the trunk referenced by Henner. I also made the changes in his post. Boost and QuantLib compile OK, but when I build my own project (managed C++), I get an array of warnings (though it does build.)
Many like this:
2>c:\program files (x86)\boost\boost_1_44\boost\thread\win32\thread_primitives.hpp(314): warning C4793: 'boost::detail::win32::interlocked_bit_test_and_set' : function compiled as native :
2>       Found an intrinsic not supported in managed code
 
plus others related to features not supported by clr/managed code.
 
Plus one these for each source file:
I_EuropeanOption.obj : warning LNK4248: unresolved typeref token (01000024) for 'boost.detail.win32._SECURITY_ATTRIBUTES'; image may not run
 
 
though I managed to get rid of these with this: http://exold.com/article/using-boost-with-managed-c
 
As I mentioned, it does build. The real problem is that when I run my project, I immediately get:
BadImageFormatException: Could not load file or assembly 'Interface.dll' or one of its dependencies.  is not a valid Win32 application. (Exception from HRESULT: 0x800700C1)
 
Interface.dll is my managed C++ project.
 
My setup:
 
Windows XP 64-bit Professional (though all code is compiled for 32-bit / x86)
Visual Studio 2010
Boost 1.44
QuantLib 1.0.1
A 'core' project that is native C++ that uses quantlib; compiled to a static library.
A 'Interface' project that is managed C++, built into a DLL. (so the code is not linked until this project is built.)
An 'add-in' project that is C#/.NET 4.0. The above error is thrown when this project tries to create an instance of a class in Interface.dll
 
Everything runs fine (except for the occasional ‘pure virtual function call’) with the original setup – not even any build warnings.
 
Does anyone have any suggestions on how to proceed? Please let me know if you need more details about my setup.
Thanks.
 
        - Alan
 
Alan Fischbein, CFA
212-205-6846
C12 Capital Management
 
 

  ________________________________  
The information contained herein (the Information) is confidential. By accepting the Information, the recipient (which shall include its directors, partners, officers, employees and representatives) acknowledges that it will use the Information only for information and discussion purposes and not for any other purpose. Any reproduction of this Information, in whole or in part, is prohibited. The recipient further agrees that the Information will not be divulged to any other party without the express written consent of C12 Capital Management LP (C12); provided, however, that the recipient may make any disclosure required by law or requested by a regulator having jurisdiction over the recipient. By accepting delivery of these materials, each recipient hereof agrees to the restrictions set forth in this disclaimer. C12 and its affiliates reserve the right to monitor and archive all email-communications.

The Information has been prepared solely for informational purposes and is not an offer to buy or sell or a solicitation of any offer to buy or sell any security or participate in a trading strategy. The Information is not intended to be, and shall not be regarded or construed as, recommendations for transactions or investment, financial or other advice of any kind or constitute or imply any commitment whatsoever, including without limitation an offer to purchase, sell or hold any security, investment, loan or other financial product (collectively, an investment) or to enter into or arrange any type of transaction, on the part of C12. Past performance is not necessarily indicative of future results.

------------------------------------------------------------------------------
Fulfilling the Lean Software Promise
Lean software platforms are now widely adopted and the benefits have been
demonstrated beyond question. Learn why your peers are replacing JEE
containers with lightweight application servers - and what you can gain
from the move. http://p.sf.net/sfu/vmware-sfemails
_______________________________________________
QuantLib-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-dev
Reply | Threaded
Open this post in threaded view
|

Re: pure virtual function call in observable update

Fischbein, Alan: C12 (NYK)
Hi Bojan,
 
        Thanks for the reply. I think understand what you're saying, but the problem appears even when my native class uses an nonCLR-supported type in its definition.
 
For example, I get the warnings if I my native class includes a reference to YieldTermStructure>
 
For example:
NativeInterestCurve.h:
 
#include <ql/termstructures/yieldtermstructure.hpp>
class NativeInterestCurve
{
        boost::shared_ptr<YieldTermStructure> TermStructure_; };
 
And the managed wrapper just references NativeInterestCurve:
 
ManagedClass.h:
 
#include NativeInterestCurve.h  // I think the problem is right here.
class ICWrapper
{
        private NativeInterestCurve* crv_;
}
 
When compiling ManagedClass.cpp, the following 4 warnings are produced with the fix to Observer described earlier: (and the project crashes on startup with BadImageFormatException.):
 
1>c:\program files (x86)\boost\boost_1_44\boost\thread\win32\thread_primitives.hpp(314): warning C4793: 'boost::detail::win32::interlocked_bit_test_and_set' : function compiled as native :
1>       Found an intrinsic not supported in managed code c:\program files
1>(x86)\boost\boost_1_44\boost\signals2\deconstruct_ptr.hpp(36): warning C4793: 'boost::signals2::detail::do_postconstruct' : function compiled as native :
1>       varargs not supported under /clr
1>c:\program files (x86)\boost\boost_1_44\boost\signals2\deconstruct_ptr.hpp(39): warning C4793: 'boost::signals2::detail::do_predestruct' : function compiled as native :
1>       varargs not supported under /clr
1>ManagedClass.cpp : warning C4793: 'QuantLib::Observer::`vcall'{4}'' : function compiled as native :
1>       non-clrcall vcall thunks must be compiled as native
 
Does this mean that even my unmanaged classes cannot reference non-CLR supported types in their definition? (as opposed to implementation.) Thanks.
 
 
        - Alan
 
Alan Fischbein, CFA
212-205-6846
C12 Capital Management
 
 
Alan Fischbein, CFA
212-205-6846
C12 Capital Management
 
 
_____________________________________________
From: Fischbein, Alan: C12 (NYK)
Sent: Thursday, April 21, 2011 3:09 PM
To: '[hidden email]'
Subject: pure virtual function call in observable update
 
 
 
Hi,
 
This message is intended as a follow-up to:
I am experiencing the same issue as the one reported: random occurrences of "pure virtual function call" in the 'update' method in 'notifyObservers'. I tried the solution suggested by Henner Heck - using his new observable.hpp that uses "enable_shared_from_raw.hpp".
I got that file, and the new shared_ptr.hpp from the trunk referenced by Henner. I also made the changes in his post. Boost and QuantLib compile OK, but when I build my own project (managed C++), I get an array of warnings (though it does build.)
Many like this:
2>c:\program files (x86)\boost\boost_1_44\boost\thread\win32\thread_primitives.hpp(314): warning C4793: 'boost::detail::win32::interlocked_bit_test_and_set' : function compiled as native :
2>       Found an intrinsic not supported in managed code
 
plus others related to features not supported by clr/managed code.
 
Plus one these for each source file:
I_EuropeanOption.obj : warning LNK4248: unresolved typeref token (01000024) for 'boost.detail.win32._SECURITY_ATTRIBUTES'; image may not run
 
 
though I managed to get rid of these with this: http://exold.com/article/using-boost-with-managed-c
 
As I mentioned, it does build. The real problem is that when I run my project, I immediately get:
BadImageFormatException: Could not load file or assembly 'Interface.dll' or one of its dependencies.  is not a valid Win32 application. (Exception from HRESULT: 0x800700C1)
 
Interface.dll is my managed C++ project.
 
My setup:
 
Windows XP 64-bit Professional (though all code is compiled for 32-bit / x86)
Visual Studio 2010
Boost 1.44
QuantLib 1.0.1
A 'core' project that is native C++ that uses quantlib; compiled to a static library.
A 'Interface' project that is managed C++, built into a DLL. (so the code is not linked until this project is built.)
An 'add-in' project that is C#/.NET 4.0. The above error is thrown when this project tries to create an instance of a class in Interface.dll
 
Everything runs fine (except for the occasional ‘pure virtual function call’) with the original setup – not even any build warnings.
 
Does anyone have any suggestions on how to proceed? Please let me know if you need more details about my setup.
Thanks.
 
        - Alan
 
Alan Fischbein, CFA
212-205-6846
C12 Capital Management
 
 

  ________________________________  
The information contained herein (the Information) is confidential. By accepting the Information, the recipient (which shall include its directors, partners, officers, employees and representatives) acknowledges that it will use the Information only for information and discussion purposes and not for any other purpose. Any reproduction of this Information, in whole or in part, is prohibited. The recipient further agrees that the Information will not be divulged to any other party without the express written consent of C12 Capital Management LP (C12); provided, however, that the recipient may make any disclosure required by law or requested by a regulator having jurisdiction over the recipient. By accepting delivery of these materials, each recipient hereof agrees to the restrictions set forth in this disclaimer. C12 and its affiliates reserve the right to monitor and archive all email-communications.

The Information has been prepared solely for informational purposes and is not an offer to buy or sell or a solicitation of any offer to buy or sell any security or participate in a trading strategy. The Information is not intended to be, and shall not be regarded or construed as, recommendations for transactions or investment, financial or other advice of any kind or constitute or imply any commitment whatsoever, including without limitation an offer to purchase, sell or hold any security, investment, loan or other financial product (collectively, an investment) or to enter into or arrange any type of transaction, on the part of C12. Past performance is not necessarily indicative of future results.

------------------------------------------------------------------------------
WhatsUp Gold - Download Free Network Management Software
The most intuitive, comprehensive, and cost-effective network
management toolset available today.  Delivers lowest initial
acquisition cost and overall TCO of any competing solution.
http://p.sf.net/sfu/whatsupgold-sd
_______________________________________________
QuantLib-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-dev
Reply | Threaded
Open this post in threaded view
|

Re: pure virtual function call in observable update

Bojan Nikolic

Hi Alan,

"Fischbein, Alan: C12 (NYK)" <[hidden email]> writes:

> Does this mean that even my unmanaged classes cannot reference non-CLR
> supported types in their definition? (as opposed to implementation.)
> Thanks.

I think in standard C++ parlance you mean "in declaration as opposed to
definition".

The answer (I think) is that you can use non-CLR compatible types only
by having them as incomplete types in your unmanaged class declaration
(i.e., the part that is in the ".h" file). In other words, you forward
declare the non-CLR compatible QuantLib types you wish to use in your
NativeInterestCurve. For example, you can do

class YieldTermStructure;
class NativeInterestCurve
{
        boost::scoped_ptr<YieldTermStructure> TermStructure_;
};

But note that you can not use boost::shared_ptr there as that requires a
complete type.

Best,
Bojan

--
Bojan Nikolic          ||          http://www.bnikolic.co.uk

------------------------------------------------------------------------------
WhatsUp Gold - Download Free Network Management Software
The most intuitive, comprehensive, and cost-effective network
management toolset available today.  Delivers lowest initial
acquisition cost and overall TCO of any competing solution.
http://p.sf.net/sfu/whatsupgold-sd
_______________________________________________
QuantLib-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-dev
Reply | Threaded
Open this post in threaded view
|

Re: pure virtual function call in observable update

imachabeli
In reply to this post by Fischbein, Alan: C12 (NYK)
Alan,
Even if you solve all problems with loading and running, your setup with mixed mode dll linking to static "quantlib +you wrapper" smells like a problem. When dll is unloaded in the ASP you might experience segmentation  fault due to a bug in the .net framework that ms does not plan to fix ("Static variable in native method causes exception" http://connect.microsoft.com/VisualStudio/feedback/details/336844/static-variable-in-native-method-causes-exception-c0020001-during-process-exit)

Just today I finished testing the project that pretty much does the same as what you try to achieve. I introduced extra native dll that links in quantlib and than mixed mode dll uses native one.
In the header that is included in the mixed dll source code there is no reference to anything from quantlib.

Native dll has interface like this
class QLWRAPPER_API ITermStructureHandleNative
        {
                protected:
                        boost::shared_ptr<TermStructureNative> ts_;
                       
                        ITermStructureHandleNative(boost::shared_ptr<TermStructureNative> ts ):  ts_(ts) {}

                public:
                        friend class ITermStructureNativeFactory;
                        double spread();
                        void setSpread(double s);

                        QLWrapDate maxDate();
                        int settlementDays() ;
                        QLWrapDate settlementDate()  ;
                       
                        ICalendarHandleNative* calendar() ;
                        double forwardRate(double t1, double t2, int c );
                        double forwardRateAct360(QLWrapDate d1, QLWrapDate d2, int c);
                        double forwardRate30360(QLWrapDate d1, QLWrapDate d2, int c);
                        double discount(QLWrapDate d1);
        };


TermStructureNative is defined in the separate header in the native dll as
        //this is just a dummy wrapper to avoid inclusion of qunatlib in ITermStructurNativeFactory.h
        class TermStructureNative
        {
                public:
                boost::shared_ptr<SimpleQuote> spreadQuote_;
                boost::shared_ptr<ForwardSpreadedTermStructure> ts_;
                TermStructureNative(boost::shared_ptr<YieldTermStructure> ts,double spread=0)
                {
                        spreadQuote_=boost::shared_ptr<SimpleQuote>(new SimpleQuote(spread));
                        Handle<Quote> hsq (spreadQuote_);
                        RelinkableHandle<YieldTermStructure> hts(ts);
                        ts_=  boost::shared_ptr<ForwardSpreadedTermStructure>(
                                new ForwardSpreadedTermStructure(hts,hsq ));
                }
}



and finally mixed mode dll

        public ref class TermStructureHandle
        {
        protected:
                        ITermStructureHandleNative* tsHandle_;
        public:
                        property double SpreadBP{ double get() { return tsHandle_->spread()*10000;} void set(double v) {tsHandle_->setSpread(v/10000); }}
                        TermStructureHandle(ITermStructureHandleNative* ts):tsHandle_(ts){}
                        double forwardRate(double t1, double t2, Compounding c ) { return tsHandle_->forwardRate(t1, t2,(int) c);}
                       
                        double forwardRateAct360(DateTime d1, DateTime  d2, Compounding c)
                        {
                                return tsHandle_->forwardRateAct360(
                                        DateTime2QLWrapDate(d1),
                                        DateTime2QLWrapDate(d2),
                                        (int) c);
                        }
                        double forwardRate30360(DateTime d1, DateTime  d2, Compounding c)
                        {
                                return tsHandle_->forwardRate30360(
                                        DateTime2QLWrapDate(d1),
                                        DateTime2QLWrapDate(d2),
                                        (int) c);
                        }

                        double discount(DateTime d1)
                        {
                                return tsHandle_->discount(
                                        DateTime2QLWrapDate(d1));
                        }


                        DateTime maxDate() { return QLWrapDate2DateTime(tsHandle_->maxDate());}
                        int settlementDays() { return tsHandle_->settlementDays();}
                        DateTime settlementDate() { return QLWrapDate2DateTime(tsHandle_->settlementDate());}
                       
                        CalendarHandle^ calendar() { return  gcnew CalendarHandle(tsHandle_-> calendar());}


                !TermStructureHandle()
                {
                        if (tsHandle_!=NULL)
                        {
                                delete tsHandle_;
                                tsHandle_=NULL;
                        }
                }
                ~TermStructureHandle()
                {
                        this->!TermStructureHandle();
                }
               

        };

This approach is the same what Bojan suggested you plus extra dll.

Fischbein, Alan: C12 (NYK) wrote
A 'core' project that is native C++ that uses quantlib; compiled to a static library.
A 'Interface' project that is managed C++, built into a DLL. (so the code is not linked until this project is built.)
An 'add-in' project that is C#/.NET 4.0. The above error is thrown when this project tries to create an instance of a class in Interface.dll