
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