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

Matthew Fluet fluet at tti-c.org
Mon Sep 15 10:22:09 PDT 2008


On Mon, 15 Sep 2008, Wesley W. Terpstra wrote:
> 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.

What happens to an 'fprintf(stderr,...);' or an 'fwrite(s,size,n,stderr);' 
statement with -mwindows? An exception raised during the evaluation of the 
Basis Library will be printed using functions from 
<src>/runtime/basis/Stdio.c.  (See 
<src>/basis-library/primitive/prim2.sml.)

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

Correct.

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

How does one determine that stdin/out/err 'exist'?  It seems as though 
they exist as values/handles, but don't support the full range of 
operations.

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

As noted above, this wouldn't help in this situation, because the 
exception printer (that is in scope for the evaluating the Basis Library) 
doesn't go through TextIO.print.



More information about the MLton-user mailing list