www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - plans for interfacing to C++

reply Trass3r <un known.com> writes:
There were some discussions about adding namespace support with something  
like extern(C++, namespace) IIRC. Don't know the result though.

Then there's this small patch  
(http://d.puremagic.com/issues/show_bug.cgi?id=4620) which allows very  
interesting stuff, even simple templates. It's rotting.

So what are the current plans?
Not being able to access C++ libraries directly is a real blocker. We  
should really try to improve the situation.
Jan 08 2012
next sibling parent reply Walter Bright <newshound2 digitalmars.com> writes:
On 1/8/2012 7:54 PM, Trass3r wrote:
 There were some discussions about adding namespace support with something like
 extern(C++, namespace) IIRC. Don't know the result though.

 Then there's this small patch
 (http://d.puremagic.com/issues/show_bug.cgi?id=4620) which allows very
 interesting stuff, even simple templates. It's rotting.
Wanna do a pull request for it?
 So what are the current plans?
 Not being able to access C++ libraries directly is a real blocker. We should
 really try to improve the situation.
I'm working as fast as I can :-)
Jan 09 2012
next sibling parent reply Zachary Lund <admin computerquip.com> writes:
How would this work exactly? Especially on Windows, libraries tend to 
not be compatible with each other. Will a C++ library be required to be 
compiled and linked with a certain toolset?

On 01/09/2012 03:16 AM, Walter Bright wrote:
 On 1/8/2012 7:54 PM, Trass3r wrote:
 There were some discussions about adding namespace support with
 something like
 extern(C++, namespace) IIRC. Don't know the result though.

 Then there's this small patch
 (http://d.puremagic.com/issues/show_bug.cgi?id=4620) which allows very
 interesting stuff, even simple templates. It's rotting.
Wanna do a pull request for it?
 So what are the current plans?
 Not being able to access C++ libraries directly is a real blocker. We
 should
 really try to improve the situation.
I'm working as fast as I can :-)
Jan 09 2012
parent Walter Bright <newshound2 digitalmars.com> writes:
On 1/9/2012 1:25 AM, Zachary Lund wrote:
 How would this work exactly? Especially on Windows, libraries tend to not be
 compatible with each other. Will a C++ library be required to be compiled and
 linked with a certain toolset?
Yes, as it is already.
Jan 09 2012
prev sibling parent Trass3r <un known.com> writes:
 Then there's this small patch
 (http://d.puremagic.com/issues/show_bug.cgi?id=4620) which allows very
 interesting stuff, even simple templates. It's rotting.
Wanna do a pull request for it?
Just wanted to point at it. I'd like to have some discussion. See Martin Nowak's post for example. In the end we need a consistent way to interface with C++.
 So what are the current plans?
 Not being able to access C++ libraries directly is a real blocker. We  
 should
 really try to improve the situation.
I'm working as fast as I can :-)
I do believe that :)
Jan 09 2012
prev sibling next sibling parent deadalnix <deadalnix gmail.com> writes:
Le 09/01/2012 04:54, Trass3r a écrit :
 There were some discussions about adding namespace support with
 something like extern(C++, namespace) IIRC. Don't know the result though.

 Then there's this small patch
 (http://d.puremagic.com/issues/show_bug.cgi?id=4620) which allows very
 interesting stuff, even simple templates. It's rotting.

 So what are the current plans?
 Not being able to access C++ libraries directly is a real blocker. We
 should really try to improve the situation.
I was npot aware of this existing. This is awesome.
Jan 09 2012
prev sibling next sibling parent "Martin Nowak" <dawg dawgfoto.de> writes:
Am 09.01.2012, 04:54 Uhr, schrieb Trass3r <un known.com>:

 There were some discussions about adding namespace support with  
 something like extern(C++, namespace) IIRC. Don't know the result though.

 Then there's this small patch  
 (http://d.puremagic.com/issues/show_bug.cgi?id=4620) which allows very  
 interesting stuff, even simple templates. It's rotting.

 So what are the current plans?
 Not being able to access C++ libraries directly is a real blocker. We  
 should really try to improve the situation.
IMHO this patch is rather flawed - Don't construct C++ classes as value types. You would need to know the exact size of the type and D can't preserve semantics for copy and assign. - D and C++ templates don't really map.
Jan 09 2012
prev sibling parent reply Trass3r <un known.com> writes:
 There were some discussions about adding namespace support with  
 something like extern(C++, namespace) IIRC. Don't know the result though.
Hmm another difficulty is how to switch between mangling schemes.
Jan 09 2012
next sibling parent Zachary Lund <admin computerquip.com> writes:
On 01/09/2012 06:36 AM, Trass3r wrote:
 There were some discussions about adding namespace support with
 something like extern(C++, namespace) IIRC. Don't know the result though.
Hmm another difficulty is how to switch between mangling schemes.
Given Walter's comment, I don't think they plan to.
Jan 09 2012
prev sibling parent reply Michel Fortin <michel.fortin michelf.com> writes:
On 2012-01-09 12:36:35 +0000, Trass3r <un known.com> said:

 There were some discussions about adding namespace support with  
 something like extern(C++, namespace) IIRC. Don't know the result 
 though.
Hmm another difficulty is how to switch between mangling schemes.
One thing that could be done is instead of the namespace argument, have a mangled name argument. Then use CTFE to build the mangled name (if you want to). This would also solve the problem we have on OS X where some C functions use a mangled name with a '$' in them thanks to the use of some GCC attribute in the system headers. Or maybe it should be a pragma instead. -- Michel Fortin michel.fortin michelf.com http://michelf.com/
Jan 09 2012
parent reply "Trass3r" <un known.com> writes:
On Monday, 9 January 2012 at 18:04:58 UTC, Michel Fortin wrote:
 Hmm another difficulty is how to switch between mangling 
 schemes.
One thing that could be done is instead of the namespace argument, have a mangled name argument. Then use CTFE to build the mangled name (if you want to). This would also solve the problem we have on OS X where some C functions use a mangled name with a '$' in them thanks to the use of some GCC attribute in the system headers. Or maybe it should be a pragma instead.
Interesting idea. But how to do it properly? A namespace or a class may have lots of functions and I really wouldn't want to be forced to write pragma(mangledName, gccmangle("Bla", ...)) before every declaration.
Jan 09 2012
parent reply deadalnix <deadalnix gmail.com> writes:
Le 09/01/2012 19:19, Trass3r a écrit :
 On Monday, 9 January 2012 at 18:04:58 UTC, Michel Fortin wrote:
 Hmm another difficulty is how to switch between mangling schemes.
One thing that could be done is instead of the namespace argument, have a mangled name argument. Then use CTFE to build the mangled name (if you want to). This would also solve the problem we have on OS X where some C functions use a mangled name with a '$' in them thanks to the use of some GCC attribute in the system headers. Or maybe it should be a pragma instead.
Interesting idea. But how to do it properly? A namespace or a class may have lots of functions and I really wouldn't want to be forced to write pragma(mangledName, gccmangle("Bla", ...)) before every declaration.
mangled("encrypted klingon here") void foo(); Where encrypted klingon can be generated using CTFE.
Jan 10 2012
next sibling parent sclytrack <sclytrack fake.com> writes:
On 01/10/2012 10:28 AM, deadalnix wrote:
 Le 09/01/2012 19:19, Trass3r a écrit :
 On Monday, 9 January 2012 at 18:04:58 UTC, Michel Fortin wrote:
 Hmm another difficulty is how to switch between mangling schemes.
One thing that could be done is instead of the namespace argument, have a mangled name argument. Then use CTFE to build the mangled name (if you want to). This would also solve the problem we have on OS X where some C functions use a mangled name with a '$' in them thanks to the use of some GCC attribute in the system headers. Or maybe it should be a pragma instead.
Interesting idea. But how to do it properly? A namespace or a class may have lots of functions and I really wouldn't want to be forced to write pragma(mangledName, gccmangle("Bla", ...)) before every declaration.
mangled("encrypted klingon here") void foo(); Where encrypted klingon can be generated using CTFE.
It's like the vapi files. (Vala) //encrypted klingon here. [CCode (cname = "gtk_cell_area_class_find_cell_property")] public class unowned GLib.ParamSpec find_cell_property (string property_name); //alias here With the alias in D you can use the original.
Jan 10 2012
prev sibling next sibling parent "Martin Nowak" <dawg dawgfoto.de> writes:
On Tue, 10 Jan 2012 10:28:54 +0100, deadalnix <deadalnix gmail.com> wrot=
e:

 Le 09/01/2012 19:19, Trass3r a =C3=A9crit :
 On Monday, 9 January 2012 at 18:04:58 UTC, Michel Fortin wrote:
 Hmm another difficulty is how to switch between mangling schemes.
One thing that could be done is instead of the namespace argument, have a mangled name argument. Then use CTFE to build the mangled nam=
e
 (if you want to).

 This would also solve the problem we have on OS X where some C
 functions use a mangled name with a '$' in them thanks to the use of=
 some GCC attribute in the system headers.

 Or maybe it should be a pragma instead.
Interesting idea. But how to do it properly? A namespace or a class may have lots of functions and I really wouldn=
't
 want to be forced to write pragma(mangledName, gccmangle("Bla", ...))=
 before every declaration.
mangled("encrypted klingon here") void foo(); Where encrypted klingon can be generated using CTFE.
Quite nice. It also makes pretty clear that one is responsible to avoid symbol collisions.
Jan 10 2012
prev sibling next sibling parent reply Michel Fortin <michel.fortin michelf.com> writes:
On 2012-01-10 09:28:54 +0000, deadalnix <deadalnix gmail.com> said:

 Le 09/01/2012 19:19, Trass3r a écrit :
 On Monday, 9 January 2012 at 18:04:58 UTC, Michel Fortin wrote:
 Hmm another difficulty is how to switch between mangling schemes.
One thing that could be done is instead of the namespace argument, have a mangled name argument. Then use CTFE to build the mangled name (if you want to). This would also solve the problem we have on OS X where some C functions use a mangled name with a '$' in them thanks to the use of some GCC attribute in the system headers. Or maybe it should be a pragma instead.
Interesting idea. But how to do it properly? A namespace or a class may have lots of functions and I really wouldn't want to be forced to write pragma(mangledName, gccmangle("Bla", ...)) before every declaration.
mangled("encrypted klingon here") void foo(); Where encrypted klingon can be generated using CTFE.
Another idea which would be much less verbose: extern(C++, gccmangle) void foo(); Here, gccmangle is a CTFE-capable function that'd be called like this: gccmangle("foo"); So if you need a namespace argument, just add one: extern(C++, gccmangle, "bar::baz") void foo(); which would call the function like this to get the mangled name: gccmangle("foo","bar::baz"); The syntax doesn't sound quite right to me, hopefully someone can make it better. -- Michel Fortin michel.fortin michelf.com http://michelf.com/
Jan 10 2012
parent "Trass3r" <un known.com> writes:
On Tuesday, 10 January 2012 at 12:09:14 UTC, Michel Fortin wrote:
 Another idea which would be much less verbose:

 	extern(C++, gccmangle)
 	void foo();

 Here, gccmangle is a CTFE-capable function that'd be called 
 like this:

 	gccmangle("foo");

 So if you need a namespace argument, just add one:

 	extern(C++, gccmangle, "bar::baz")
 	void foo();

 which would call the function like this to get the mangled name:

 	gccmangle("foo","bar::baz");

 The syntax doesn't sound quite right to me, hopefully someone 
 can make it better.
At least you could use extern(...) : and extern(...) {} this way.
Jan 10 2012
prev sibling parent "Trass3r" <un known.com> writes:
On Tuesday, 10 January 2012 at 09:27:03 UTC, deadalnix wrote:
 Le 09/01/2012 19:19, Trass3r a écrit :
 On Monday, 9 January 2012 at 18:04:58 UTC, Michel Fortin wrote:
 Or maybe it should be a pragma instead.
Interesting idea. But how to do it properly? A namespace or a class may have lots of functions and I really wouldn't want to be forced to write pragma(mangledName, gccmangle("Bla", ...)) before every declaration.
mangled("encrypted klingon here") void foo(); Where encrypted klingon can be generated using CTFE.
And how is this any better than pragma??
Jan 10 2012