Bug 7020 – Exception thrown across DLL is not caught.

Status
REOPENED
Severity
normal
Priority
P3
Component
druntime
Product
D
Version
D2
Platform
Other
OS
Windows
Creation time
2011-11-26T19:46:34Z
Last change time
2024-12-07T13:31:40Z
Keywords
dll
Assigned to
No Owner
Creator
SHOO
Moved to GitHub: dmd#17237 →

Comments

Comment #0 by zan77137 — 2011-11-26T19:46:34Z
--- mydll.d --------------------------------------- import core.runtime, core.stdc.stdio; import core.sys.windows.windows, core.sys.windows.dll; extern (Windows) BOOL DllMain(HINSTANCE hInstance, ULONG ulReason, LPVOID pvReserved) { switch (ulReason) { case DLL_PROCESS_ATTACH: Runtime.initialize(); dll_process_attach( hInstance, true ); break; case DLL_PROCESS_DETACH: _fcloseallp = null; dll_process_detach( hInstance, true ); Runtime.terminate(); break; case DLL_THREAD_ATTACH: dll_thread_attach( true, true ); break; case DLL_THREAD_DETACH: dll_thread_detach( true, true ); break; default: assert(0); } return TRUE; } extern(System) void func() { throw new Exception("Exception"); } --- module.def --------------------------------------- LIBRARY MYDLL DESCRIPTION 'DLL Module' EXETYPE NT CODE PRELOAD DISCARDABLE DATA WRITE EXPORTS func --- myexe.d --------------------------------------- import std.stdio; import core.runtime, core.sys.windows.windows; extern(System) alias void function() FuncType; void main() { auto h = cast(HMODULE) Runtime.loadLibrary("mydll.dll"); scope (exit) Runtime.unloadLibrary(h); auto fp = cast(FuncType) GetProcAddress(h, "func"); try { fp(); } catch (Throwable e) { writeln("EXE - OK"); } } -------------------------------------------- dmd -ofmydll.dll module.def mydll.d dmd -run myexe.d (CRASH) -------------------------------------------- This issue is caused by difference in TypeInfo. TypeInfo which Exception of mydll has is different from TypeInfo which Exception of myexe has in instance. Current druntime requires a comparison between the instance of TypeInfo in catch. However, IMHO this implementation is a incorrect.
Comment #1 by zan77137 — 2011-11-26T23:58:26Z
*** This issue has been marked as a duplicate of issue 1693 ***
Comment #2 by code — 2012-01-15T17:39:01Z
I strongly disagree with the expected behavior and the merged fix. https://github.com/D-Programming-Language/druntime/pull/92 Having multiple definitions of the same symbol can't work. The correct solution is to move those symbols (phobos) into a DLL and link every user against it.
Comment #3 by zan77137 — 2012-01-16T03:16:09Z
(In reply to comment #2) I examined the method, too. However, I was not able to obtain a good solution. In addition, the solution to move the Phobos/druntime/any libraries's symbol which exe contains into DLL is not correct. This is because there is not the guarantee that a version of library is the same when DLL was compiled. I have heard that this problem was the problem that was difficult in other languages... Unfortunately I cannot show the solution that is better than this. If you have good solution, please submit PullRequest.
Comment #4 by code — 2012-01-16T09:23:03Z
Yes updating library versions might cause incompatibilities. It is a matter of ABI design to avoid it. Statically linking a library multiple times into exe/dlls means you have duplicated state, e.g. the "same" function called from different dlls will use different locks. There apply the same rules as with the C runtime only that we don't yet have a /MD option to solve this issue. http://msdn.microsoft.com/en-us/library/ms235460.aspx I haven't yet looked into making phobos a DLL under windows.
Comment #5 by r.sagitario — 2012-01-16T10:43:50Z
>I haven't yet looked into making phobos a DLL under windows. There is one possible solution shown in issue 4071
Comment #6 by robert.schadek — 2024-12-07T13:31:40Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/17237 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB