Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
fixes missed from auto tester
Browse files Browse the repository at this point in the history
  • Loading branch information
John-Colvin authored and adamdruppe committed Dec 21, 2019
1 parent a0c51af commit 9ee8387
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 46 deletions.
2 changes: 1 addition & 1 deletion src/rt/cast_.d
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
83 changes: 41 additions & 42 deletions src/rt/dmain2.d
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand All @@ -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;
}
Expand All @@ -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?

Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/rt/sections_win64.d
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
Empty file.
Empty file.
4 changes: 4 additions & 0 deletions test/shared/src/dynamiccast64.def
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
LIBRARY l
EXPORTS
_d_innerEhTable = _d_innerEhTable
_d_setEhTablePointer = _d_setEhTablePointer
3 changes: 2 additions & 1 deletion test/shared/win64.mak
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
DMD=dmd
MODEL=64
DRUNTIMELIB=druntime64.lib
DEF=test\shared\src\dynamiccast$(MODEL).def

test: loadlibwin dllrefcount dllgc dynamiccast

Expand All @@ -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"
Expand Down

0 comments on commit 9ee8387

Please sign in to comment.