Time exception

Stephen Weeks MLton@sourcelight.com
Sat, 21 Apr 2001 14:52:51 -0700 (PDT)


I finally figured out why I consistently get a Time exception when running even
the newest G0 MLton on one of my machines (starlinux).  First hint: the machine
has been up for 281 days.  Second hint: 281 * 24 * 60 * 60 * 100 = 2,427,840,000
> 2^31.

Recall that Posix.ProcEnv.times returns (via the times function) the elapsed
number of clock ticks since the system came up.  Despite the fact that the man
pages say that times returns a clock_t, which is a long int, in fact, times
appears to be returning an unsigned int.  That is, a call to times on starlinux
returns something like 0x90f24469, which has the high bit set.  Both MLton and
SML/NJ assume that clock_t is signed, and therefore think that the elapsed time
is negative, and raise a Time exception.

So, the following simple program causes a Time exception on any machine that has 
been up more than ~248.6 days and has CLK_TICK = 100.

val _ = Posix.ProcEnv.times()

I think that the right fix is to translate clock_t into Word.word in MLton and
to send a bug report to the SML/NJ folks.

Thoughts?