die.sml and the Rico bug
Stephen Weeks
MLton@sourcelight.com
Tue, 5 Feb 2002 13:21:31 -0800
I am revisiting Henry'y die.sml program, which was inspired by a
program he had written for Rico, and Henry claimed showed a segfault
in previous versions of MLton. As a reminder, I have appended the
program to the end of this message. I have tried the program on my
machine, which contains 1/2G RAM and 1G swap, using mlton-20011006,
20020115, and the currently checked in sources. It appears to behave
correctly for all three versions. That is, running
die @MLton max-heap 769m -- <z.in
succeeds, but running
die @MLton max-heap 768m -- <z.in
fails with an out of memory message (where z.in contains 170,000,000
bytes).
I am now confused what was the error Henry saw, since I am unable to
duplicate it.
--------------------------------------------------------------------------------
(*
* Read in a file into keys.
*)
fun readFile fd =
let fun loop (res, size, used) =
let val n = Posix.IO.readArr (fd, { buf = res,
i = used,
sz = NONE } )
in if n = 0
then res
else let val used' = used + n
in if used' = size
then let val size' = size + size
val res' =
Word8Array.array (size',
0w0)
in Word8Array.copy { src = res,
si = 0,
len = SOME used',
dst = res',
di = 0 };
loop (res', size', used')
end
else loop (res, size, used')
end
end
in loop (Word8Array.array (4096, 0w0),
4096,
0)
end
fun main () =
let val _ = readFile Posix.FileSys.stdin
in ()
end
val _ = main ()