digitalmars.D.announce - Interfacing D to existing C++ code
- Walter Bright (3/3) Jan 23 2015 Mandatory reddit link:
- FrankLike (2/5) Jan 23 2015 Great!
- Andrew Godfrey (5/5) Jan 25 2015 Is it common for a C++ library you want to interface to, to use
- Guillaume Chatelet (5/5) Jan 29 2015 Walter how far did you get to integrate with the STL ?
- Andrei Alexandrescu (4/8) Jan 29 2015 Go for it, what we have only proof of concept for now. I know it's
- Guillaume Chatelet (10/10) Jan 29 2015 I pushed some code for string here (nothing fancy yet)
- Walter Bright (2/10) Jan 29 2015 Please post this to bugzilla.
- Daniel Murphy (8/12) Jan 29 2015 The problems with constructors go beyond mangling, so the current forced...
- Paolo Invernizzi (6/22) Jan 30 2015 I've done the same for some matrix ctor of opencv: it's a pain
- Guillaume Chatelet (5/5) Jan 30 2015 Thx for the feedback !
- Sativa (33/36) Feb 01 2015 Interesting...
- Ben Boeckel via Digitalmars-d-announce (4/16) Feb 01 2015 IIRC, C++ default arguments are handled at compile time and are not part
- deadalnix (2/13) Feb 02 2015 SWIG, but the quality is not there.
Mandatory reddit link: http://www.reddit.com/r/programming/comments/2tdy5z/interfacing_d_to_legacy_c_co e_by_walter_bright/ There's been a lot of interest in this topic.
Jan 23 2015
On Friday, 23 January 2015 at 11:04:12 UTC, Walter Bright wrote:Mandatory reddit link: http://www.reddit.com/r/programming/comments/2tdy5z/interfacing_d_to_legacy_c_code_by_walter_bright/ There's been a lot of interest in this topic.Great!
Jan 23 2015
Is it common for a C++ library you want to interface to, to use std library types in its interface? Things like iterators or maybe containers. Do those hit any of the "hard" cases, so that you'd need to change the std library to resolve the issue?
Jan 25 2015
Walter how far did you get to integrate with the STL ? I started writing std::vector and std::string (linux gcc libstdc++) but maybe someone already made progress on this. It's harder than I thought and will probably require a lot of work to maintain all implementations.
Jan 29 2015
On 1/29/15 4:30 AM, Guillaume Chatelet wrote:Walter how far did you get to integrate with the STL ? I started writing std::vector and std::string (linux gcc libstdc++) but maybe someone already made progress on this. It's harder than I thought and will probably require a lot of work to maintain all implementations.Go for it, what we have only proof of concept for now. I know it's difficult, at a point I'll get on to it as well. Maintenance is parallelizable and I trust the community can take care of it. -- Andrei
Jan 29 2015
I pushed some code for string here (nothing fancy yet) https://github.com/gchatelet/dlang_cpp_std/blob/master/cpp_std.d The linker complains about missing std::basic_string<char, std::char_traits<char>, std::allocator<char> >::__ctor() where it should be std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string() So constructors and destructors are mangled 'a la D' instead of the C++ way.
Jan 29 2015
On 1/29/2015 1:58 PM, Guillaume Chatelet wrote:I pushed some code for string here (nothing fancy yet) https://github.com/gchatelet/dlang_cpp_std/blob/master/cpp_std.d The linker complains about missing std::basic_string<char, std::char_traits<char>, std::allocator<char> >::__ctor() where it should be std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string() So constructors and destructors are mangled 'a la D' instead of the C++ way.Please post this to bugzilla.
Jan 29 2015
"Walter Bright" wrote in message news:maed4o$2da6$1 digitalmars.com...The problems with constructors go beyond mangling, so the current forced D mangling is intentional to prevent wrong-code bugs. An approach that currently works is porting the code to D, being careful to exactly match the layout and functionality. When done right, this allows templated types to be constructed with any type in either language and passed back and forth without problems. This is what I've done for dmd's Array<T> in ddmd.So constructors and destructors are mangled 'a la D' instead of the C++ way.Please post this to bugzilla.
Jan 29 2015
On Friday, 30 January 2015 at 04:08:56 UTC, Daniel Murphy wrote:"Walter Bright" wrote in message news:maed4o$2da6$1 digitalmars.com...I've done the same for some matrix ctor of opencv: it's a pain but works... The main problem I've found right now it's that sometime I'm forced to choose a struct in D mapping a class in C++ just to have the right mangling for const ref methods...The problems with constructors go beyond mangling, so the current forced D mangling is intentional to prevent wrong-code bugs. An approach that currently works is porting the code to D, being careful to exactly match the layout and functionality. When done right, this allows templated types to be constructed with any type in either language and passed back and forth without problems. This is what I've done for dmd's Array<T> in ddmd.So constructors and destructors are mangled 'a la D' instead of the C++ way.Please post this to bugzilla.
Jan 30 2015
Thx for the feedback ! bug : https://issues.dlang.org/show_bug.cgi?id=14086 I worked around the name mangling issue with pragmas for now, a new version is available here : https://github.com/gchatelet/dlang_cpp_std/blob/5d52957372f7055b95d4f62ee6d9633bd620a61d/cpp_std.d
Jan 30 2015
On Friday, 23 January 2015 at 11:04:12 UTC, Walter Bright wrote:Mandatory reddit link: http://www.reddit.com/r/programming/comments/2tdy5z/interfacing_d_to_legacy_c_code_by_walter_bright/ There's been a lot of interest in this topic.Interesting... I wonder if two things could happen: 1. A tool could be written to generate the interfacing code in D from the C++ code? 2. If, in your stl example, the default argument could be automatically inferred from the mangling? What I mean is, Do we really need to know the default arguments or are we just having to explicitly use them to make the name mangling work? If it is the latter, then surely couldn't the D compiler sort of have a "wild card" type of default parameter where the compiler allows any such argument to work? i.e., unless we are actually explicitly needed the default argument in some way it seems that we can just derive it's "mangled" version from the C++ object data and use that directly in the D mangled version? Essentially the D compiler mangles what it can then substitutes the part of the mangled name in C++ for "unknown things" into the D mangled name. I just see that if we are "linking" then why would one have to "implement" anything? Just essentially "Copy" the mangling from C++ object data. 3. Hopefully a mapping table is used instead of having to actually have implementations for very compiler? e.g., essentially implement a standard ABI in D, map each C++ compilers mangling version to that instead of implementing each C++ compilers mangling. It seems that 99% of the problem is translation in nature and that one can auto generate D interfaces from C++ mangled names. (in fact, one could go a "step" further then and simply reverse C++ object code into D code)
Feb 01 2015
On Sun, Feb 01, 2015 at 22:32:36 +0000, Sativa via Digitalmars-d-announce wrote:What I mean is, Do we really need to know the default arguments or are we just having to explicitly use them to make the name mangling work? If it is the latter, then surely couldn't the D compiler sort of have a "wild card" type of default parameter where the compiler allows any such argument to work? i.e., unless we are actually explicitly needed the default argument in some way it seems that we can just derive it's "mangled" version from the C++ object data and use that directly in the D mangled version?IIRC, C++ default arguments are handled at compile time and are not part of the ABI. --Ben
Feb 01 2015
On Sunday, 1 February 2015 at 22:32:37 UTC, Sativa wrote:On Friday, 23 January 2015 at 11:04:12 UTC, Walter Bright wrote:SWIG, but the quality is not there.Mandatory reddit link: http://www.reddit.com/r/programming/comments/2tdy5z/interfacing_d_to_legacy_c_code_by_walter_bright/ There's been a lot of interest in this topic.Interesting... I wonder if two things could happen: 1. A tool could be written to generate the interfacing code in D from the C++ code?
Feb 02 2015