Add backup mp_get_memory_functions implementation for use with old gmps
authorSven Verdoolaege <skimo@kotnet.org>
Tue, 2 Dec 2008 20:22:01 +0000 (21:22 +0100)
committerSven Verdoolaege <skimo@kotnet.org>
Tue, 2 Dec 2008 20:34:33 +0000 (21:34 +0100)
Makefile.am
configure.ac
include/isl_int.h
mp_get_memory_functions.c [new file with mode: 0644]

index 7f78b80..78ab76a 100644 (file)
@@ -33,9 +33,14 @@ if BUNDLED_PIPLIB
 PIPLIB_LA = $(top_builddir)/piplib/libpiplibMP.la
 endif
 
+if NEED_GET_MEMORY_FUNCTIONS
+GET_MEMORY_FUNCTIONS=mp_get_memory_functions.c
+endif
+
 libisl_la_SOURCES = \
        $(ISL_PIPLIB) \
        $(ISL_POLYLIB) \
+       $(GET_MEMORY_FUNCTIONS) \
        isl_affine_hull.c \
        isl_blk.c \
        isl_constraint.c \
index 8c9e208..e084a75 100644 (file)
@@ -18,6 +18,14 @@ if test "x$with_gmp_prefix" != "x"; then
        GMP_CPPFLAGS="-I$with_gmp_prefix/include"
        GMP_LDFLAGS="-L$with_gmp_prefix/lib"
 fi
+SAVE_CPPFLAGS="$CPPFLAGS"
+CPPFLAGS="$GMP_CPPFLAGS $CPPFLAGS"
+need_get_memory_functions=false
+AC_CHECK_DECLS(mp_get_memory_functions,[],[
+       need_get_memory_functions=true
+],[#include <gmp.h>])
+CPPFLAGS="$SAVE_CPPFLAGS"
+AM_CONDITIONAL(NEED_GET_MEMORY_FUNCTIONS, test x$need_get_memory_functions = xtrue)
 
 AC_DEFUN([ISL_SUBMODULE],[
        AC_ARG_WITH($1_prefix,
index 3445e55..1326664 100644 (file)
@@ -9,6 +9,13 @@
 extern "C" {
 #endif
 
+#ifndef mp_get_memory_functions
+void mp_get_memory_functions(
+               void *(**alloc_func_ptr) (size_t),
+               void *(**realloc_func_ptr) (void *, size_t, size_t),
+               void (**free_func_ptr) (void *, size_t));
+#endif
+
 /* isl_int is the basic integer type.  It currently always corresponds
  * to a gmp mpz_t, but in the future, different types such as long long
  * or cln::cl_I will be supported.
diff --git a/mp_get_memory_functions.c b/mp_get_memory_functions.c
new file mode 100644 (file)
index 0000000..e14e336
--- /dev/null
@@ -0,0 +1,14 @@
+#include <gmp.h>
+
+void mp_get_memory_functions(
+               void *(**alloc_func_ptr) (size_t),
+               void *(**realloc_func_ptr) (void *, size_t, size_t),
+               void (**free_func_ptr) (void *, size_t))
+{
+       if (alloc_func_ptr)
+               *alloc_func_ptr = __gmp_allocate_func;
+       if (realloc_func_ptr)
+               *realloc_func_ptr = __gmp_reallocate_func;
+       if (free_func_ptr)
+               *free_func_ptr = __gmp_free_func;
+}