[MLton] Bug in IntInf implementation

Wesley W. Terpstra wesley at terpstra.ca
Fri Dec 7 05:59:23 PST 2007


The version: (at least) svn/HEAD
boom.sml:
> val x : IntInf.int = 1
> val y = IntInf.<< (x, 0w838860800) (* 100MB *)
> val () = print "unreached\n"
For comparison, boom.c:
> #include <gmp.h>
>
> int main() {
>  mpz_t x;
>  mpz_init2(x, 1);
>  mpz_mul_2exp(x, x, 838860800);
>  printf("reached\n");
>  return 0;
> }

The bug:
initIntInfRes in runtime/gc/int-inf.c points a GMP limb buffer at the  
heap. It has no reason to believe the current heap can contain the  
result. Normally the mpz_* functions will gmp_realloc memory when  
needed. I have no idea what will happen when calling this on a pointer  
in the ML heap. It seems to hang.

Solution:
Use mp_set_memory_functions




More information about the MLton mailing list