1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-09 13:30:26 +02:00

Only install libgc as GMP allocator with mini-gmp

* libguile/numbers.c (scm_install_gmp_memory_functions): Default to 1
only if mini-gmp is enabled.
This commit is contained in:
Andy Wingo 2021-03-08 22:28:25 +01:00
parent f46477f6f5
commit ee1ed277ce

View file

@ -1,4 +1,4 @@
/* Copyright 1995-2016,2018-2020 /* Copyright 1995-2016,2018-2021
Free Software Foundation, Inc. Free Software Foundation, Inc.
Portions Copyright 1990-1993 by AT&T Bell Laboratories and Bellcore. Portions Copyright 1990-1993 by AT&T Bell Laboratories and Bellcore.
@ -156,10 +156,24 @@ VARARG_MPZ_ITERATOR (mpz_clear)
/* the macro above will not work as is with fractions */ /* the macro above will not work as is with fractions */
/* Default to 1, because as we used to hard-code `free' as the /* In the context of Guile, it's most efficient for GMP to use libgc to
deallocator, we know that overriding these functions with allocate MPZ values. That way Guile doesn't need to install
instrumented `malloc' / `free' is OK. */ finalizers, which have significant overhead. Using libgc to allocate
int scm_install_gmp_memory_functions = 1; digits also allows Guile's GC to adequately measure the memory cost
of MPZ values.
However, if the Guile process is linked to some other user of GMP,
then probably the references from the other user of GMP to MPZ values
aren't visible to the garbage collector. So libgc could prematurely
collect values from that other GMP user.
This isn't theoretical -- it happens for Guile-GnuTLS. GnuTLS uses
GMP, and so does Guile. But if Guile installs libgc as the allocator
for MPZ values, we break GnuTLS.
Therefore we only install libgc as the GMP allocator if we are using
mini-gmp, which we know isn't shared with any external library. */
int scm_install_gmp_memory_functions = SCM_ENABLE_MINI_GMP;
static SCM flo0; static SCM flo0;
static SCM exactly_one_half; static SCM exactly_one_half;
static SCM flo_log10e; static SCM flo_log10e;