www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 2580] New: Documented WinMain for D2 is wrong

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

           Summary: Documented WinMain for D2 is wrong
           Product: D
           Version: 2.023
          Platform: PC
               URL: http://www.digitalmars.com/d/2.0/windows.html
        OS/Version: Windows
            Status: NEW
          Keywords: spec
          Severity: critical
          Priority: P2
         Component: www.digitalmars.com
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: smjg iname.com


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();
    }
}


-- 
Jan 11 2009
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2580





------- Comment #1 from maxmo pochta.ru  2009-01-13 05:53 -------
Isn't proper startup code can be found in dmain2.d ?


-- 
Jan 13 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2580





------- Comment #2 from smjg iname.com  2009-01-13 08:21 -------
That's exactly what Runtime.initialize and Runtime.terminate do - call the
"proper startup code".


-- 
Jan 13 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2580





------- Comment #3 from smjg iname.com  2009-01-24 06:51 -------
Correction: Runtime.initialize calls the proper startup code, and
Runtime.terminate calls the proper shutdown code.


-- 
Jan 24 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2580


sean invisibleduck.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|bugzilla digitalmars.com    |sean invisibleduck.org




------- Comment #4 from sean invisibleduck.org  2009-01-30 20:01 -------
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.


-- 
Jan 30 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2580





------- Comment #5 from smjg iname.com  2009-01-30 20:53 -------
(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. --
Jan 30 2009
prev sibling next sibling parent reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2580





------- Comment #6 from smjg iname.com  2009-04-01 20:18 -------
Sean, where are you at with this at the moment?


-- 
Apr 01 2009
parent Sean Kelly <sean invisibleduck.org> writes:
d-bugmail puremagic.com wrote:
 http://d.puremagic.com/issues/show_bug.cgi?id=2580
 
 ------- Comment #6 from smjg iname.com  2009-04-01 20:18 -------
 Sean, where are you at with this at the moment?

I forgot about this ticket until the release went out and I was looking through bugzilla for stuff to close. It will be fixed in the next release.
Apr 02 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2580


sean invisibleduck.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED




------- Comment #7 from sean invisibleduck.org  2009-04-02 22:20 -------
Okay, fixed in SVN.


-- 
Apr 02 2009
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2580


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
                 CC|                            |bugzilla digitalmars.com
         Resolution|                            |FIXED




--- Comment #8 from Walter Bright <bugzilla digitalmars.com>  2009-05-15
12:17:50 PDT ---
Fixed dmd 2.030

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 15 2009