DIP87: Enhanced Foreign-Language Binding

Anon via Digitalmars-d digitalmars-d at puremagic.com
Wed Jan 20 21:46:13 PST 2016


On Thursday, 21 January 2016 at 04:42:00 UTC, Rikki Cattermole 
wrote:
> On 21/01/16 5:21 PM, Anon wrote:
>> Seeing the recent extern(C++) threads, and much concern 
>> therein, I'd
>> like to propose DIP87: http://wiki.dlang.org/DIP87
>>
>> Destroy to your heart's content.
>
> It was great until I saw:
> extern(auto, "myMoveTo:")
>
> After all:
> extern(C/C++/D/Objective-C[, string])
>
> Is that string meant for raw mangling or effect mangling in the 
> form of selector?
>
> Just no, leave @selector alone I think.

I don't know ObjC, so I had to wing it on the details there. The 
strings in
extern(<Foo>, "str") would get sent through Foo's mangler. For 
ObjC, I currently imagine those strings forming the selector, 
much the same way it is specified through @selector. That ObjC's 
mangling mostly consists of 's/:/_/g' is irrelevant. I want *all* 
language binding to happen with a uniform interface. No more 
one-off hacks for a particular language (which is exactly what 
extern(C++,ns) and @selector are).


> You have the same problem with c++ namespaces.

I don't see a problem. You'll have to be more specific.


> Perhaps this is slightly wrong.
> extern(string)
> Is the only way to force a specific mangling.

There is no extern(string) in this proposal, nor is there a way 
to force a specific mangling, which (AFAIK) was only introduced 
to allow linking to C symbols that happened to be keywords.


> Where as extern(C/C++/D/Objective-C[, string])
> with the string altering in C++ and Objective-C mode.

It mangles regardless. Any and all of the extern(<Foo>) modes 
mangle. That C's mangling is to just return the input string is 
irrelevant.


> So the only difference is extern(string) vs pragma(mangle, 
> string)
> Little harder sell, but I think might be worth it for cleaning 
> up the language.

The difference is that it can mangle symbols correctly, even if 
the symbol is a D keyword.

Currently:

extern(C++) pragma(mangle, "delegate") int delegate_();

...yields a mangled name of "delegate", and there is no way to 
get the compiler to mangle the symbol correctly. Meaning you have 
to (ab)use pragma(mangle) and provide it with the full mangled 
name yourself. And `version()` it appropriately to deal with 
gcc/clang vs MSVC/DMC mangling.

With this DIP:

extern(C++, "delegate") int delegate_();

... would yield a mangled name of "_Z8delegatev" (or similar).

I thought I did a good enough job of explaining that in the DIP 
so I wouldn't have to here.


More information about the Digitalmars-d mailing list