Re: Issues with C++/CLI wrappers and local static variables in quantlib

Posted by Luigi Ballabio on
URL: http://quantlib.414.s1.nabble.com/Issues-with-C-CLI-wrappers-and-local-static-variables-in-quantlib-tp189p194.html

Thanks, I'll try and have a look.

Luigi


On Sat, Nov 17, 2012 at 5:59 PM, Simon Shakeshaft
<[hidden email]> wrote:

> Hi Luigi,
>
> Finally got round to forking the repository and parking the 'CLI safe'
> versions of singleton.hpp and the various currency classes.  I have added a
> comment to the existing singleton.hpp which clarifies the use of 'Construct
> on first use Idiom' and the 'static initialisation order fiasco', which is
> why the code is as is.
>
> Also to the fork I have added 2 test cases for the Thirty360 daycounter
> (BondBasis and EurobondBasis) if they are useful.
>
> And  a small correction to the flag usage in runtest.bat.
>
> [3 separate commits].
>
> Simon.
>
>
>
> -----Original Message-----
> From: Luigi Ballabio [mailto:[hidden email]]
> Sent: 31 October 2012 15:45
> To: Simon Shakeshaft
> Cc: [hidden email]
> Subject: Re: [Quantlib-users] Issues with C++/CLI wrappers and local static
> variables in quantlib
>
> Hi Simon,
>     yes, we might possibly park them somewhere for review.  If you're
> familiar with git, you could fork the quantlib repository at
> <https://github.com/lballabio/quantlib> and commit your changes there.
>  Let me know if you do that.
>
> Luigi
>
> On Mon, Oct 29, 2012 at 10:43 AM, Simon Shakeshaft
> <[hidden email]> wrote:
>> Hi Luigi,
>>
>> In the end I had to make changes to singleton.hpp and all the currency
>> classes in america.hpp, africa.hpp, asia.hpp, europe.hpp and oceania.hpp.
>> The currency classes also required the addition of a null deleter on
>> the boost::shared_ptr declaration to  overcome the CLR shutdown issues.
>>
>> It may be good just to park the code in a new folder along with a
>> readme, rather than merge/test the changes into the existing codebase?
>>
>> Simon.
>>
>> -----Original Message-----
>> From: Luigi Ballabio [mailto:[hidden email]]
>> Sent: 24 August 2012 10:28
>> To: Simon Shakeshaft
>> Cc: [hidden email]
>> Subject: Re: [Quantlib-users] Issues with C++/CLI wrappers and local
>> static variables in quantlib
>>
>> Hi Simon,
>>     we moved the instance to the local scope because we had problems
>> with other compilers, but this might not be relevant anymore.  If you
>> post a patch, I'll be happy to try it.
>>
>> Luigi
>>
>> On Mon, Aug 6, 2012 at 10:42 AM, Simon Shakeshaft
>> <[hidden email]> wrote:
>>> Hi,
>>>
>>>
>>> I've been looking at building some C++/CLI wrappers around the
>>> library, partially as an exercise to become more familiar with CLI
>>> programming and partially to compare the approach with SWIG.
>>>
>>>
>>>
>>> However, I've run into a issue which may be a compiler issue but
>>> Microsoft have it closed as 'Won't Fix'. The issue manifested it
>>> first in the Singleton [patterns] class, as I was trying to migrate
>>> the FRA example across to C#, using some of the wrapped classes I already
> had.
>>> In the Singleton class the instance() method declares a static
>>> variable of a native type with a destructor.
>>>
>>>
>>>
>>> However the compiler registers a managed destructor with atexit and
>>> when the assembly is unloaded the CLR is already shut down, and an
>>> attempt to transition back to managed code results in an exception
>>> which cannot be caught.
>>> e.g.
>>> First-chance exception at 0x76a2b9bc in app.exe: 0xC0020001: The
>>> string binding is invalid.
>>> Unhandled exception at 0x76a2b9bc in app.exe: 0xC0020001: The string
>>> binding is invalid.
>>>
>>>
>>>
>>> The case on Microsoft Connect is here:
>>>
>>> https://connect.microsoft.com/VisualStudio/feedback/details/336844/st
>>> a
>>> tic-variable-in-native-method-causes-exception-c0020001-during-proces
>>> s
>>> -exit
>>>
>>>
>>>
>>> The exception generates the annoying '... .exe has encountered a
>>> problem and needs to close' dialog.  This can be worked around by the
>>> use of the SetErrorMode(), prior to exit, however the exception is
>>> just masked at this point and the exit is not clean.
>>>
>>>
>>>
>>>
>>> It's possible to move the local static variable in the Singleton
>>> class to the class level as a private member, and I've done this on
>>> my working copy - that works fine, the exit is now clean.  However
>>> similar code exists in many of the QuantLib classes - the specific
>> currency classes are a case in point.
>>>
>>>
>>>
>>>
>>> I'd be quite happy to work through the classes and pass the changes
>>> across, if this would be useful, otherwise I can work around by using
>>> SetErrorMode() etc.
>>>
>>> Best Regards
>>> Simon
>>>
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> -
>>> --------
>>> Live Security Virtual Conference
>>> Exclusive live event will cover all the ways today's security and
>>> threat landscape has changed and how IT managers can respond.
>>> Discussions will include endpoint security, mobile security and the
>>> latest in malware threats.
>>> http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
>>> _______________________________________________
>>> QuantLib-users mailing list
>>> [hidden email]
>>> https://lists.sourceforge.net/lists/listinfo/quantlib-users
>>>
>
>

------------------------------------------------------------------------------
Monitor your physical, virtual and cloud infrastructure from a single
web console. Get in-depth insight into apps, servers, databases, vmware,
SAP, cloud infrastructure, etc. Download 30-day Free Trial.
Pricing starts from $795 for 25 servers or applications!
http://p.sf.net/sfu/zoho_dev2dev_nov
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users