seg fault with List.tabulate in 3.9.1
Henry Cejtin
henry@sourcelight.com
Mon, 9 Jul 2001 17:55:15 -0500
The trick we used in older versions of MLton was to memmap a page with no
permissions onto the end of the region, and then to catch SIGSEGV and to look
at the address we were trying to access. If it was in the bad page then we
knew (technically assumed) that it was the region that we had overrun.
In the signal catching function, in the struct sigcontext_struct argument,
the `cr2' member contains the address you were trying to access which caused
the fault. If this isn't enough information, I can send you some sample
code.
Given the fact that you use the Unix stack as the stack, I would have thought
that the way to go would be to have List.tabulate cons up the list in reverse
order, and then make another pass reversing it. This way you use O(1) stack
space. Of course it probably is a bit slower for short lists, and generates
ephemeral garbage, but one pair is likely smaller than a stack frame, so it
is likely more memory efficient.