[Issue 7020] New: Exception thrown across DLL is not caught.

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Nov 26 19:47:34 PST 2011


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 at puremagic.com
        ReportedBy: zan77137 at nifty.com


--- Comment #0 from SHOO <zan77137 at nifty.com> 2011-11-26 19:46:34 PST ---
--- 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: -------


More information about the Digitalmars-d-bugs mailing list