[PPL-devel] GMP memory allocation problem in SWI-Prolog 5.6.38 and following versions

Roberto Bagnara bagnara at cs.unipr.it
Tue Oct 2 07:42:28 CEST 2007


Starting from version 5.6.38 of SWI-Prolog, applications using SWI-Prolog and
GMP started failing.  The problem is due to the fact that SWI-Prolog overrides
the memory allocation functions used by GMP by calling mp_set_memory_functions().
I have observed two instances of the problem, one of which was reported by
users of the Parma Polyhedra Library:

1) a variable allocated in the C++ code before SWI-Prolog changes the allocation
    functions is destroyed after SWI-Prolog has done that (this results in
    a segmentation fault);
2) while executing the C++ code, the realloc function set by SWI-Prolog is
    called (this results into an invalid pointer detected by glibc).

Both instances are caused by the fact that memory allocated by GMP's default
functions is reallocated/freed by SWI-Prolog's functions.  Something that
is guaranteed to cause problems.  However, even if all memory allocation
was done by the SWI-Prolog's functions, I am sure we would have other troubles.
I am not sure what is the way out, but the problem is rather serious.
All the best,

     Roberto

-- 
Prof. Roberto Bagnara
Computer Science Group
Department of Mathematics, University of Parma, Italy
http://www.cs.unipr.it/~bagnara/
mailto:bagnara at cs.unipr.it




More information about the PPL-devel mailing list