mirror of
https://github.com/dlang/dmd.git
synced 2025-04-28 22:20:37 +03:00
fix Issue 23387 - ImportC: identical structs defined in two C files lead to duplicate .init symbol on macOS
This commit is contained in:
parent
96df7f49dd
commit
7fe0aee2a4
4 changed files with 58 additions and 1 deletions
|
@ -657,7 +657,24 @@ Symbol *toInitializer(AggregateDeclaration ad)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
auto stag = fake_classsym(Id.ClassInfo);
|
auto stag = fake_classsym(Id.ClassInfo);
|
||||||
auto s = toSymbolX(ad, "__init", SC.extern_, stag.Stype, "Z");
|
|
||||||
|
Symbol* s;
|
||||||
|
|
||||||
|
Module m = ad.getModule();
|
||||||
|
if (m.filetype == FileType.c)
|
||||||
|
{
|
||||||
|
/* For ImportC structs, the module names are stripped from the mangled name.
|
||||||
|
* This leads to name collisions. Add the module name back in.
|
||||||
|
*/
|
||||||
|
import dmd.common.outbuffer : OutBuffer;
|
||||||
|
OutBuffer buf;
|
||||||
|
buf.writestring("__init");
|
||||||
|
buf.writestring(m.toChars());
|
||||||
|
s = toSymbolX(ad, buf.peekChars(), SC.extern_, stag.Stype, "Z");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
s = toSymbolX(ad, "__init", SC.extern_, stag.Stype, "Z");
|
||||||
|
|
||||||
s.Sfl = FLextern;
|
s.Sfl = FLextern;
|
||||||
s.Sflags |= SFLnodebug;
|
s.Sflags |= SFLnodebug;
|
||||||
if (sd)
|
if (sd)
|
||||||
|
|
5
compiler/test/runnable/imports/freer.i
Normal file
5
compiler/test/runnable/imports/freer.i
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
typedef struct Foo *FooRef;
|
||||||
|
struct Foo {
|
||||||
|
int x;
|
||||||
|
};
|
||||||
|
void free_foo(FooRef foo) { }
|
5
compiler/test/runnable/imports/maker.i
Normal file
5
compiler/test/runnable/imports/maker.i
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
typedef struct Foo *FooRef;
|
||||||
|
struct Foo {
|
||||||
|
int x;
|
||||||
|
};
|
||||||
|
FooRef make_foo(void) { return 0; }
|
30
compiler/test/runnable/test23387.d
Normal file
30
compiler/test/runnable/test23387.d
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
/* COMPILE_SEPARATELY:
|
||||||
|
* EXTRA_SOURCES: imports/maker.i imports/freer.i
|
||||||
|
*/
|
||||||
|
|
||||||
|
// https://issues.dlang.org/show_bug.cgi?id=23387
|
||||||
|
|
||||||
|
/+ maker.i
|
||||||
|
typedef struct Foo *FooRef;
|
||||||
|
struct Foo {
|
||||||
|
int x;
|
||||||
|
};
|
||||||
|
FooRef make_foo(void);
|
||||||
|
+/
|
||||||
|
import imports.maker;
|
||||||
|
|
||||||
|
|
||||||
|
/+ freer.i
|
||||||
|
typedef struct Foo *FooRef;
|
||||||
|
struct Foo {
|
||||||
|
int x;
|
||||||
|
};
|
||||||
|
void free_foo(FooRef foo);
|
||||||
|
+/
|
||||||
|
import imports.freer;
|
||||||
|
|
||||||
|
int main(){
|
||||||
|
FooRef f = make_foo();
|
||||||
|
free_foo(f);
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue