From 9ee838713311ecc3fc5aabc5c3ab3c84dc2d4e0d Mon Sep 17 00:00:00 2001 From: John Colvin Date: Sun, 13 Oct 2019 15:30:19 +0100 Subject: [PATCH] fixes missed from auto tester --- src/rt/cast_.d | 2 +- src/rt/dmain2.d | 83 ++++++++++++------------- src/rt/sections_win64.d | 4 +- test/shared/src/dynamiccast32.def | 0 test/shared/src/dynamiccast32mscoff.def | 0 test/shared/src/dynamiccast64.def | 4 ++ test/shared/win64.mak | 3 +- 7 files changed, 50 insertions(+), 46 deletions(-) create mode 100644 test/shared/src/dynamiccast32.def create mode 100644 test/shared/src/dynamiccast32mscoff.def create mode 100644 test/shared/src/dynamiccast64.def diff --git a/src/rt/cast_.d b/src/rt/cast_.d index 3b46cd1395..9582faddd5 100644 --- a/src/rt/cast_.d +++ b/src/rt/cast_.d @@ -19,7 +19,7 @@ bool compareClassInfo(ClassInfo a, ClassInfo b) { if (a is b) return true; - return a.info.name == b.info.name; + return (a && b) && a.info.name == b.info.name; } extern (C): diff --git a/src/rt/dmain2.d b/src/rt/dmain2.d index 93ceb9b219..b0e76dcb71 100644 --- a/src/rt/dmain2.d +++ b/src/rt/dmain2.d @@ -122,12 +122,12 @@ version (Windows) * opaque handle to the DLL if successfully loaded * null if failure */ - export extern (C) void* rt_loadLibrary(const char* name) + extern (C) void* rt_loadLibrary(const char* name) { return initLibrary(.LoadLibraryA(name)); } - export extern (C) void* rt_loadLibraryW(const WCHAR* name) + extern (C) void* rt_loadLibraryW(const WCHAR* name) { return initLibrary(.LoadLibraryW(name)); } @@ -145,51 +145,50 @@ version (Windows) gcSet(gc_getProxy()); } - version (Win64) - { - import rt.sections_win64; + version (Win64) + { + import rt.sections_win64; - ehGetFn ehGet = cast(ehGetFn) GetProcAddress(mod, "_d_innerEhTable"); - ehSetFn ehSet = cast(ehSetFn) GetProcAddress(mod, "_d_setEhTablePointer"); + auto ehGet = cast(ehGetFn) GetProcAddress(mod, "_d_innerEhTable"); + auto ehSet = cast(ehSetFn) GetProcAddress(mod, "_d_setEhTablePointer"); - typeof(ehGet()) libraryEh; - if (ehGet) - { - libraryEh = ehGet(); - if (ehTablesGlobal is null) - { - // first time: copy the local table into it as well as - // the new library - auto local = _d_innerEhTable(); - auto len = libraryEh.length + local.length; - auto ptr = cast(FuncTable*) malloc(typeof(ehTablesGlobal[0]).sizeof * len); - ptr[0 .. local.length] = cast(FuncTable[]) local[]; - ptr[local.length .. local.length + libraryEh.length] = cast(FuncTable[]) libraryEh[]; - ehTablesGlobal = ptr[0 .. len]; - } - else + if (ehGet) { - // otherwise we need to realloc it to append the library table - auto ptr = ehTablesGlobal.ptr; - ptr = cast(FuncTable*) realloc(cast(void*) ptr, - typeof(ehTablesGlobal[0]).sizeof * (ehTablesGlobal.length + libraryEh.length)); - if (ptr is null) - abort(); - auto orig = ehTablesGlobal.length; - cast(FuncTable[]) ptr[orig .. orig + libraryEh.length] = cast(FuncTable[]) libraryEh[]; - ehTablesGlobal = ptr[0 .. orig + libraryEh.length]; - } + auto libraryEh = ehGet(); + if (ehTablesGlobal is null) + { + // first time: copy the local table into it as well as + // the new library + auto local = _d_innerEhTable(); + auto len = libraryEh.length + local.length; + auto ptr = cast(FuncTable*) malloc(typeof(ehTablesGlobal[0]).sizeof * len); + ptr[0 .. local.length] = cast(FuncTable[]) local[]; + ptr[local.length .. local.length + libraryEh.length] = cast(FuncTable[]) libraryEh[]; + ehTablesGlobal = ptr[0 .. len]; + } + else + { + // otherwise we need to realloc it to append the library table + auto ptr = ehTablesGlobal.ptr; + ptr = cast(FuncTable*) realloc(cast(void*) ptr, + typeof(ehTablesGlobal[0]).sizeof * (ehTablesGlobal.length + libraryEh.length)); + if (ptr is null) + abort(); + auto orig = ehTablesGlobal.length; + cast(FuncTable[]) ptr[orig .. orig + libraryEh.length] = cast(FuncTable[]) libraryEh[]; + ehTablesGlobal = ptr[0 .. orig + libraryEh.length]; + } - // set the local pointer - _d_setEhTablePointer(&ehTablesGlobal); + // set the local pointer + _d_setEhTablePointer(&ehTablesGlobal); - if (ehSet) - { - // and set the remote table too so throwing from the dll also sees the whole thing - ehSet(&ehTablesGlobal); + if (ehSet) + { + // and set the remote table too so throwing from the dll also sees the whole thing + ehSet(&ehTablesGlobal); + } } } - } return mod; } @@ -202,7 +201,7 @@ version (Windows) * 1 succeeded * 0 some failure happened */ - export extern (C) int rt_unloadLibrary(void* ptr) + extern (C) int rt_unloadLibrary(void* ptr) { // should this logic just be done in the dll's DllMain instead? @@ -270,7 +269,7 @@ shared size_t _initCount; * If a C program wishes to call D code, and there's no D main(), then it * must call rt_init() and rt_term(). */ -export extern (C) int rt_init() +extern (C) int rt_init() { /* @@BUG 11380 @@ Need to synchronize rt_init/rt_term calls for version (Shared) druntime, because multiple C threads might diff --git a/src/rt/sections_win64.d b/src/rt/sections_win64.d index ec4d29614d..812a003268 100644 --- a/src/rt/sections_win64.d +++ b/src/rt/sections_win64.d @@ -231,11 +231,11 @@ version (Win64) ehTablesFull = &ehTablesLocal; } - extern(C) export void _d_setEhTablePointer(const(FuncTable)[]* ptr) { + package(rt) extern(C) void _d_setEhTablePointer(const(FuncTable)[]* ptr) { ehTablesFull = ptr; } - extern(C) export const(FuncTable)[] _d_innerEhTable() { + package(rt) extern(C) const(FuncTable)[] _d_innerEhTable() { auto pbeg = cast(const(FuncTable)*)&_deh_beg; auto pend = cast(const(FuncTable)*)&_deh_end; return pbeg[0 .. pend - pbeg]; diff --git a/test/shared/src/dynamiccast32.def b/test/shared/src/dynamiccast32.def new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/shared/src/dynamiccast32mscoff.def b/test/shared/src/dynamiccast32mscoff.def new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/shared/src/dynamiccast64.def b/test/shared/src/dynamiccast64.def new file mode 100644 index 0000000000..dc7a5bd06c --- /dev/null +++ b/test/shared/src/dynamiccast64.def @@ -0,0 +1,4 @@ +LIBRARY l +EXPORTS + _d_innerEhTable = _d_innerEhTable + _d_setEhTablePointer = _d_setEhTablePointer diff --git a/test/shared/win64.mak b/test/shared/win64.mak index ea46a6a460..bc5fc85e6b 100644 --- a/test/shared/win64.mak +++ b/test/shared/win64.mak @@ -3,6 +3,7 @@ DMD=dmd MODEL=64 DRUNTIMELIB=druntime64.lib +DEF=test\shared\src\dynamiccast$(MODEL).def test: loadlibwin dllrefcount dllgc dynamiccast @@ -23,7 +24,7 @@ dllgc: del loaddllgc.exe loaddllgc.obj dllgc.dll dllgc.obj dynamiccast: - $(DMD) -g -m$(MODEL) -conf= -Isrc -defaultlib=$(DRUNTIMELIB) -version=DLL -shared -ofdynamiccast.dll test\shared\src\dynamiccast.d test\shared\src\classdef.d + $(DMD) -g -m$(MODEL) -conf= -Isrc -defaultlib=$(DRUNTIMELIB) -version=DLL -shared -ofdynamiccast.dll test\shared\src\dynamiccast.d test\shared\src\classdef.d $(DEF) $(DMD) -g -m$(MODEL) -conf= -Isrc -defaultlib=$(DRUNTIMELIB) -ofdynamiccast.exe test\shared\src\dynamiccast.d test\shared\src\classdef.d dynamiccast.exe cmd /c "if not exist dynamiccast_endbar exit 1"