Thread overview | |||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
July 23, 2019 extern(C) names are being mangled; that's crazy, Walter says I'm crazy | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=20012 I need to know who is the crazy one here? I can't believe the idea that extern(C) functions being mangled to un-knowable generated names is what any sane user would ever expect. Surely extern(C) means extern(C)? I'd like a poll here... |
July 24, 2019 Re: extern(C) names are being mangled; that's crazy, Walter says I'm crazy | ||||
---|---|---|---|---|
| ||||
Posted in reply to Manu | On Wednesday, 24 July 2019 at 05:03:16 UTC, Manu wrote:
> https://issues.dlang.org/show_bug.cgi?id=20012
>
> I need to know who is the crazy one here?
> I can't believe the idea that extern(C) functions being mangled to
> un-knowable generated names is what any sane user would ever expect.
>
> Surely extern(C) means extern(C)?
>
> I'd like a poll here...
I just has the same problem yesterday, I just fix it by move the extern(C) out from mixin template to workaround.
|
July 24, 2019 Re: extern(C) names are being mangled; that's crazy, Walter says I'm crazy | ||||
---|---|---|---|---|
| ||||
Posted in reply to Manu | On Wednesday, 24 July 2019 at 05:03:16 UTC, Manu wrote: > https://issues.dlang.org/show_bug.cgi?id=20012 > > I need to know who is the crazy one here? > I can't believe the idea that extern(C) functions being mangled to > un-knowable generated names is what any sane user would ever expect. > > Surely extern(C) means extern(C)? > > I'd like a poll here... Just for comparison, here's what Rust does: https://doc.rust-lang.org/std/keyword.extern.html I like the fact that `extern` and `mangle` mean different things, but I don't like the way D currently implements it. Here's how I would design it. 1. `pragma(mangle)` should come in more forms. a. `pragma(mangle, C)` will mangle according to C rules b. `pragma(mangle, C++)` will mangle according to C++ rules c. `pragma(mangle, D)` will mangle according to D rules d. `pragma(mangle, "foo")` will mangle explicitly 2. `extern` should default the mangling to one of the above a. `extern(C)` should mean `extern(C) pragma(mangle, C)` b. `extern(C++)` should mean `extern(C++) pragma(mangle, C++)` c. `extern(D)` should mean `extern(D) pragma(mangle, D)` So, this code... struct S { extern(C) void foo() { } } ... would actually translate into... struct S { extern(C) pragma(mangle, C) void foo() { } } ... which, IIUC, would ultimately mean... struct S { extern(C) pragma(mangle, "foo") void foo() { } } This code... mixin template M() { extern(C) void fun() {} } mixin M!(); ... would result in ... { extern(C) pragma(mangle, C) void fun() {} } ... which, in turn, would result in ... { extern(C) pragma(mangle, "fun") void fun() {} } If the user instantiates the mixin multiple times, they will get duplicate symbol errors from the linker. If they wanted to take control, they would have to opt into a different mangling scheme such as... mixin template M() { extern(C) pragma(mangle, D) void fun() {} } ... which I, IIUC, would result in the current behavior. If the compiler cannot deterministically compute the mangling scheme specified because there is no translation from the D code, the compiler would emit a meaningful error telling the user so, and they may be able to work around it with the explicit `pragma(mangle)` form. IMO, that would be the most practical, covering the most common cases, and would also be the least surprising. So, in general, I side with Manu here, but I expect a little more from the language. Mike |
July 24, 2019 Re: extern(C) names are being mangled; that's crazy, Walter says I'm crazy | ||||
---|---|---|---|---|
| ||||
Posted in reply to Manu | On Wednesday, 24 July 2019 at 05:03:16 UTC, Manu wrote:
> https://issues.dlang.org/show_bug.cgi?id=20012
>
> I need to know who is the crazy one here?
> I can't believe the idea that extern(C) functions being mangled to
> un-knowable generated names is what any sane user would ever expect.
>
> Surely extern(C) means extern(C)?
>
> I'd like a poll here...
I'm not sure.
If there's an extern(C) in a mixin template, the prime purpose of which is to be reusable, does it make sense to instantiate that multiple times? Won't there then be multiple C-compatible symbols of the same thing, but with different semantics based on the context of the mixin template?
|
July 24, 2019 Re: extern(C) names are being mangled; that's crazy, Walter says I'm crazy | ||||
---|---|---|---|---|
| ||||
Posted in reply to Manu | I never called you crazy, or anything remotely like that. |
July 24, 2019 Re: extern(C) names are being mangled; that's crazy, Walter says I'm crazy | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mike Franklin | Mike Franklin wrote:
> a. `extern(C)` should mean `extern(C) pragma(mangle, C)`
then your code samples cannot be compiled at all, because each `extern(C)` will in turn be expaned to`extern(C) pragma(mangle, C)`, and the loop will go on. also, i won't even try to explain to somebody that "`extern(C)` means `extern(C) blah-blah`, but you see, the second "extern" is special, because... ahem... just because."
|
July 24, 2019 Re: extern(C) names are being mangled; that's crazy, Walter says I'm crazy | ||||
---|---|---|---|---|
| ||||
Posted in reply to ketmar | On Wednesday, 24 July 2019 at 09:44:19 UTC, ketmar wrote: Nice to see you here again, ketmar ... |
July 24, 2019 Re: extern(C) names are being mangled; that's crazy, Walter says I'm crazy | ||||
---|---|---|---|---|
| ||||
Posted in reply to Paolo Invernizzi | Paolo Invernizzi wrote:
> On Wednesday, 24 July 2019 at 09:44:19 UTC, ketmar wrote:
>
> Nice to see you here again, ketmar ...
thank you. i'm still lurking here, only don't have enough time for D these days. but this issue managed to trigger me somehow.
|
July 24, 2019 Re: extern(C) names are being mangled; that's crazy, Walter says I'm crazy | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright Attachments:
| On Wed., 24 Jul. 2019, 2:20 am Walter Bright via Digitalmars-d, < digitalmars-d@puremagic.com> wrote: > I never called you crazy, or anything remotely like that. > Just kill me and bring me peace. I lose my mind trying to argue with you, and get so frustrated and angry, I just have to take a week or 2 timeout. I feel like this community just grinds my life away slowly but steadily and I hate participating, but I'm in too deep. I just want to kick my goal and get on with my job! Everything is just so hard, and so very weird. Why can't stuff just be predictable? Why does everything have to have weird special case rules and strange edge cases? My biggest trouble with D recently had been trying to explain it to people, and make them not lose confidence when they run in to a long series of stuff like this. I have to try and explain weird shit like it's got a good reason with a straight face, and I just can't do that on so many accounts! This is D's biggest enemy in 2019, I'm sure of it. Anyway... I'm sorry, this is actually a distraction. I've managed to lose my laser focus on shared stuff. That's what I need today to progress. > |
July 24, 2019 Re: extern(C) names are being mangled; that's crazy, Walter says I'm crazy | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mike Franklin | On Wednesday, 24 July 2019 at 06:25:50 UTC, Mike Franklin wrote:
> 1. `pragma(mangle)` should come in more forms.
> a. `pragma(mangle, C)` will mangle according to C rules
> b. `pragma(mangle, C++)` will mangle according to C++ rules
> c. `pragma(mangle, D)` will mangle according to D rules
> d. `pragma(mangle, "foo")` will mangle explicitly
>
> 2. `extern` should default the mangling to one of the above
> a. `extern(C)` should mean `extern(C) pragma(mangle, C)`
> b. `extern(C++)` should mean `extern(C++) pragma(mangle, C++)`
> c. `extern(D)` should mean `extern(D) pragma(mangle, D)`
Yeah. Walter's approach is the only one that works well without a pragma(mangle, D), but I think pragma(mangle, D) is a better idea.
|
Copyright © 1999-2021 by the D Language Foundation