diff --git a/M2/Macaulay2/d/M2inits.c b/M2/Macaulay2/d/M2inits.c index a79e2ab5307..7cd8502bfe2 100644 --- a/M2/Macaulay2/d/M2inits.c +++ b/M2/Macaulay2/d/M2inits.c @@ -55,6 +55,15 @@ void *realloc_function (void *s, size_t old, size_t new) { return p; } +void our_gmp_set_memory_functions() { + /* Instead of calling __gmp_set_memory_functions we set the values ourselves. That way we can + patch mpir so the function __gmp_set_memory_functions does nothing, leaving us in control, even though + pari calls it, for example. */ + __gmp_allocate_func = (void *(*) (size_t)) getmem_atomic; + __gmp_reallocate_func = (void *(*) (void *, size_t, size_t)) getmoremem_atomic; + __gmp_free_func = freememlen; + } + int M2inits_firsttime = 1; void enterM2(void) { /* this function is called initially, and also again after we call a third party library that sets gmp's memory allocation routines */ @@ -67,12 +76,7 @@ void enterM2(void) { initializeGMP_Cwrapper(); /* this calls factory's initializeGMP() in factory/initgmp.cc, which will call __gmp_set_memory_functions just once */ } #if 1 - /* Instead of calling __gmp_set_memory_functions we set the values ourselves. That way we can - patch mpir so the function __gmp_set_memory_functions does nothing, leaving us in control, even though - pari calls it, for example. */ - __gmp_allocate_func = (void *(*) (size_t)) getmem_atomic; - __gmp_reallocate_func = (void *(*) (void *, size_t, size_t)) getmoremem_atomic; - __gmp_free_func = freememlen; + our_gmp_set_memory_functions(); #else __gmp_set_memory_functions ( /* tell gmp to use gc for memory allocation, with our error messages */ /* this function is located in mpir-1.2.1/mp_set_fns.c */ diff --git a/M2/Macaulay2/d/M2inits.h b/M2/Macaulay2/d/M2inits.h index 15785affc0e..d9c7e12f992 100644 --- a/M2/Macaulay2/d/M2inits.h +++ b/M2/Macaulay2/d/M2inits.h @@ -7,6 +7,7 @@ extern void M2inits1(), M2inits2(); extern void enterM2(); extern void check_M2init(); extern int M2inits_run, M2inits_firsttime; +extern void our_gmp_set_memory_functions(); /* get size_t */ #include diff --git a/M2/Macaulay2/d/pari-c.c b/M2/Macaulay2/d/pari-c.c index 2c88769b3e0..dcd79bcee74 100644 --- a/M2/Macaulay2/d/pari-c.c +++ b/M2/Macaulay2/d/pari-c.c @@ -55,6 +55,7 @@ static void initpari() { } if (gen_0 == NULL /* && FALSE /-* groan */ ) { pari_init_opts( PARISIZE, MAXPRIME, init_flags); + our_gmp_set_memory_functions(); /* undo the setting of the gmp memory functions done by pari_init_opts */ self_initialized = TRUE; } enterM2(); /* pari_init sets the memory allocation routines for gmp, so we have to set them back */ diff --git a/M2/Macaulay2/d/pari-c.h b/M2/Macaulay2/d/pari-c.h index 3c917b0c3a9..e5eff1bff1e 100644 --- a/M2/Macaulay2/d/pari-c.h +++ b/M2/Macaulay2/d/pari-c.h @@ -2,6 +2,7 @@ extern "C" { #endif + #include #define VARLEN 1 typedef struct { unsigned int n; __mpz_struct *el[VARLEN]; } mpz_col; typedef struct { unsigned int n; mpz_col *el[VARLEN]; } mpz_mat; diff --git a/M2/libraries/mpir/Makefile.in b/M2/libraries/mpir/Makefile.in index 7d5c11c7e66..5be7211515a 100644 --- a/M2/libraries/mpir/Makefile.in +++ b/M2/libraries/mpir/Makefile.in @@ -10,7 +10,7 @@ PRECONFIGURE = autoconf # URL = http://www.mpir.org URL = http://www.math.uiuc.edu/Macaulay2/Downloads/OtherSourceCode -PATCHFILE = @abs_srcdir@/patch-$(VERSION) +# PATCHFILE = @abs_srcdir@/patch-$(VERSION) # increase the limit, because two of the tests run by mpir's "make check" will # not run in just 400000: