Bug 2580 – Documented WinMain for D2 is wrong

Status
RESOLVED
Resolution
FIXED
Severity
critical
Priority
P2
Component
dlang.org
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2009-01-11T14:22:00Z
Last change time
2015-06-09T01:21:02Z
Keywords
spec
Assigned to
sean
Creator
smjg

Comments

Comment #0 by smjg — 2009-01-11T14:22:19Z
Currently, the form of WinMain documented for D2 is the same as that for D1. However, it's no good. _moduleUnitTests() doesn't exist in D2 for a start; a more subtle yet more serious problem is that it doesn't initialise the GC properly. After a day or three of driving myself mad trying to figure why one of my apps was unstable under D2, I've finally come up with a form for WinMain that seems to work: ---------- import std.c.windows.windows; import core.runtime; extern (Windows) int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { try { Runtime.initialize(); runModuleUnitTests(); return myWinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow); } catch (Object o) { MessageBoxA(null, toStringz(o.toString()), "Fatal Internal Error", MB_OK | MB_ICONEXCLAMATION); return 0; } finally { Runtime.terminate(); } }
Comment #1 by dfj1esp02 — 2009-01-13T05:53:08Z
Isn't proper startup code can be found in dmain2.d ?
Comment #2 by smjg — 2009-01-13T08:21:15Z
That's exactly what Runtime.initialize and Runtime.terminate do - call the "proper startup code".
Comment #3 by smjg — 2009-01-24T06:51:40Z
Correction: Runtime.initialize calls the proper startup code, and Runtime.terminate calls the proper shutdown code.
Comment #4 by sean — 2009-01-30T20:01:00Z
That looks about right. I had thought that people wouldn't want unit tests run for dynamic libraries, which is why that routine needs to be called manually. If this is incorrect then I can add it to Runtime.initialize() as well. I'll look into changing the docs.
Comment #5 by smjg — 2009-01-30T20:53:07Z
(In reply to comment #4) > That looks about right. I had thought that people wouldn't want > unit tests run for dynamic libraries, In which case they'll compile them without --unittest - problem solved. > which is why that routine needs to be called manually. If this is > incorrect then I can add it to Runtime.initialize() as well. I'll > look into changing the docs. You're right - Runtime.initialize() ought to call runModuleUnitTests(). People using the currently correct WinMain will find that the unit tests run twice, but at least they just have to remove the extra call in order to fix it.
Comment #6 by smjg — 2009-04-01T20:18:05Z
Sean, where are you at with this at the moment?
Comment #7 by sean — 2009-04-02T22:20:12Z
Okay, fixed in SVN.
Comment #8 by bugzilla — 2009-05-15T12:17:50Z
Fixed dmd 2.030