www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 7020] New: Exception thrown across DLL is not caught.

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7020

           Summary: Exception thrown across DLL is not caught.
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: druntime
        AssignedTo: nobody puremagic.com
        ReportedBy: zan77137 nifty.com



--- 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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 26 2011
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7020


SHOO <zan77137 nifty.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |DUPLICATE



*** This issue has been marked as a duplicate of issue 1693 ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 26 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7020


dawg dawgfoto.de changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
                 CC|                            |dawg dawgfoto.de
         Resolution|DUPLICATE                   |



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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 15 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7020






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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 16 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7020




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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 16 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7020


Rainer Schuetze <r.sagitario gmx.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |r.sagitario gmx.de



PST ---
I haven't yet looked into making phobos a DLL under windows.
There is one possible solution shown in issue 4071 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 16 2012