[MLton-user] Linking (?) 'print' means I can only run from the mingw command line

Wesley W. Terpstra wesley at terpstra.ca
Mon Sep 15 04:30:00 PDT 2008


On Mon, Sep 15, 2008 at 11:39 AM, Wesley W. Terpstra <wesley at terpstra.ca>wrote:

> On Sun, Sep 14, 2008 at 7:07 PM, Tom 7 <twm at andrew.cmu.edu> wrote:
>
>> I'm trying to debug a problem with using mlton+mingw+SDL on windows.
>> Everything works fine when I run my app from the mingw command line, but
>> when I run it from the DOS prompt or by clicking it in explorer, it
>> terminates immediately and silently.
>
>
> I have reproduced this problem with r6841 on win2003/x64.
>

The problem is that -mwindows removes the stdin/out/err file descriptors
from the program. When you reference print, that forces the basis to create
the stdOut variable. As you suspected, this does some initialization.
Specifically, it checks if it's a tty, fstats it, then setmode/text's it.
The fstat is failing and this gets turned into an exception that causes the
program to exit. It works under msys, because msys provides *all* windows
programs with stdin/out/err.

I discovered this using 'mlton -debug true' and gdb. Set a breakpoint on
Posix_FileSys_Stat_fstat and then trace the MLton-generated assembler. fstat
fails in a "dos" terminal (info registers -> eax = return value).

There are two fixes that come to mind:
1) handle/ignore the exception from fstat (isReg posix/io.sml:187)
2) setup place-holder stdin/out/err if none exist

I tend towards option #2. stdin&out can come from openIn/Out "NUL". However,
if stderr is missing one loses exception information. Perhaps it could
create a popup window. A TextPrimIO.writer that creates a window and adds
text on write* calls shouldn't be that hard to implement.

Which do other people prefer?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mlton.org/pipermail/mlton-user/attachments/20080915/a94d2975/attachment.html


More information about the MLton-user mailing list