QuantLib SWIG C# - Calling Conventions (cdecl/stdcall) issue

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

QuantLib SWIG C# - Calling Conventions (cdecl/stdcall) issue

Fabrice Lecuyer

Hi all,


 (email already sent as a non member, apologies if it creates a duplicate)


I’ve been building QuantLib & QuantLib SWIG “as is” with VS14 for use with C# and came across an initial error when running in debug, where visual studio breaks giving a PInvoke stack imbalance error, as described in this old thread:

https://sourceforge.net/p/quantlib/mailman/quantlib-users/thread/33276539.post%40talk.nabble.com/#msg28797382

I first tried the solution described in this thread (modifying the SWIG generated file to add calling convention = cdecl) and all seemed ok for a while.

The next problem appeared when QuantLib C++ was throwing an error, the C# wasn’t catching it and instead crashing with a memory imbalance error. Again, this is described in the thread below, but this time without a solution.

In order to catch the thrown C++ error, I’ve had to revert to the original SWIG generated C# source file, and instead build QuantLib C++ using the stdcall calling convention (default in VS14 proj files is cdecl).

Now everything is good, but I just wanted to ask around to other C# users if this is a problem they have had, if they solved it this way that I’m safe to assume I won’t find another issue of the kind down the line, or if I’m unnecessarily complicating things.

If this is indeed the best solution, would adding build configurations for stdcall be considered? Happy to provide the updated vcproj files if yes.

 

Regards,

Fabrice.


------------------------------------------------------------------------------
Attend Shape: An AT&T Tech Expo July 15-16. Meet us at AT&T Park in San
Francisco, CA to explore cutting-edge tech and listen to tech luminaries
present their vision of the future. This family event has something for
everyone, including kids. Get more information and register today.
http://sdm.link/attshape
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: QuantLib SWIG C# - Calling Conventions (cdecl/stdcall) issue

Luigi Ballabio
Hello Fabrice,
    yes, adding the configurations would be nice, thanks.

Luigi


On Sat, Jul 2, 2016 at 12:07 PM Fabrice Lecuyer <[hidden email]> wrote:

Hi all,


 (email already sent as a non member, apologies if it creates a duplicate)


I’ve been building QuantLib & QuantLib SWIG “as is” with VS14 for use with C# and came across an initial error when running in debug, where visual studio breaks giving a PInvoke stack imbalance error, as described in this old thread:

https://sourceforge.net/p/quantlib/mailman/quantlib-users/thread/33276539.post%40talk.nabble.com/#msg28797382

I first tried the solution described in this thread (modifying the SWIG generated file to add calling convention = cdecl) and all seemed ok for a while.

The next problem appeared when QuantLib C++ was throwing an error, the C# wasn’t catching it and instead crashing with a memory imbalance error. Again, this is described in the thread below, but this time without a solution.

In order to catch the thrown C++ error, I’ve had to revert to the original SWIG generated C# source file, and instead build QuantLib C++ using the stdcall calling convention (default in VS14 proj files is cdecl).

Now everything is good, but I just wanted to ask around to other C# users if this is a problem they have had, if they solved it this way that I’m safe to assume I won’t find another issue of the kind down the line, or if I’m unnecessarily complicating things.

If this is indeed the best solution, would adding build configurations for stdcall be considered? Happy to provide the updated vcproj files if yes.

 

Regards,

Fabrice.

------------------------------------------------------------------------------
Attend Shape: An AT&T Tech Expo July 15-16. Meet us at AT&T Park in San
Francisco, CA to explore cutting-edge tech and listen to tech luminaries
present their vision of the future. This family event has something for
everyone, including kids. Get more information and register today.
http://sdm.link/attshape_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users

------------------------------------------------------------------------------

_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: QuantLib SWIG C# - Calling Conventions (cdecl/stdcall) issue

Fabrice Lecuyer
Hi Luigi,

Thanks. I've made a pull request on Github. Note I've kept it as minimal as possible, I haven't updated the examples as I do not see any use for it (plus getting some warnings due to the main functions calling convention mismatches), and made the solution build configuration only build QuantLib, not the examples.

I'd still be interested in discussing with anyone who is developing in C# to confirm this is how they circumvented the problem.

Regards,
Fabrice

On 1 August 2016 at 18:41, Luigi Ballabio <[hidden email]> wrote:
Hello Fabrice,
    yes, adding the configurations would be nice, thanks.

Luigi


On Sat, Jul 2, 2016 at 12:07 PM Fabrice Lecuyer <[hidden email]> wrote:

Hi all,


 (email already sent as a non member, apologies if it creates a duplicate)


I’ve been building QuantLib & QuantLib SWIG “as is” with VS14 for use with C# and came across an initial error when running in debug, where visual studio breaks giving a PInvoke stack imbalance error, as described in this old thread:

https://sourceforge.net/p/quantlib/mailman/quantlib-users/thread/33276539.post%40talk.nabble.com/#msg28797382

I first tried the solution described in this thread (modifying the SWIG generated file to add calling convention = cdecl) and all seemed ok for a while.

The next problem appeared when QuantLib C++ was throwing an error, the C# wasn’t catching it and instead crashing with a memory imbalance error. Again, this is described in the thread below, but this time without a solution.

In order to catch the thrown C++ error, I’ve had to revert to the original SWIG generated C# source file, and instead build QuantLib C++ using the stdcall calling convention (default in VS14 proj files is cdecl).

Now everything is good, but I just wanted to ask around to other C# users if this is a problem they have had, if they solved it this way that I’m safe to assume I won’t find another issue of the kind down the line, or if I’m unnecessarily complicating things.

If this is indeed the best solution, would adding build configurations for stdcall be considered? Happy to provide the updated vcproj files if yes.

 

Regards,

Fabrice.

------------------------------------------------------------------------------
Attend Shape: An AT&T Tech Expo July 15-16. Meet us at AT&T Park in San
Francisco, CA to explore cutting-edge tech and listen to tech luminaries
present their vision of the future. This family event has something for
everyone, including kids. Get more information and register today.
http://sdm.link/attshape_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users


------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are
consuming the most bandwidth. Provides multi-vendor support for NetFlow,
J-Flow, sFlow and other flows. Make informed decisions using capacity
planning reports. http://sdm.link/zohodev2dev
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users