]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
build: support older GMP versions
authorPádraig Brady <P@draigBrady.com>
Mon, 8 Oct 2012 10:38:41 +0000 (11:38 +0100)
committerPádraig Brady <P@draigBrady.com>
Mon, 8 Oct 2012 22:40:08 +0000 (23:40 +0100)
The new factor code introduced usage of mpz_inits() and
mpz_clears(), which are only available since GMP >= 5,
and will result in a compile error when missing.

* m4/gmp.m4 (cu_GMP): Define HAVE_DECL_MPZ_INITS appropriately.
* src/factor (mpz_inits): New function, defined where missing.
(mpz_clears): Likewise.

m4/gmp.m4
src/factor.c

index e337e161fa8515fae4c1972d6d7e328e50e35301..59a664f744af82aa1757003b4ea584cf653acbff 100644 (file)
--- a/m4/gmp.m4
+++ b/m4/gmp.m4
@@ -30,6 +30,8 @@ AC_DEFUN([cu_GMP],
         LIB_GMP=$ac_cv_search___gmpz_init
         AC_DEFINE([HAVE_GMP], [1],
           [Define if you have GNU libgmp (or replacement)])
+        # This only available in GMP >= 5
+        AC_CHECK_DECLS([mpz_inits], [], [], [[#include <gmp.h>]])
        }],
       [AC_MSG_WARN([libgmp development library was not found or not usable.])
        AC_MSG_WARN([AC_PACKAGE_NAME will be built without GMP support.])])
index 5bfbfdcd407044815907740350b3e6124fce4a5e..d5f248a6a18e52494efc18c046900c98fca26f34 100644 (file)
@@ -89,6 +89,9 @@
 #include <stdio.h>
 #if HAVE_GMP
 # include <gmp.h>
+# if !HAVE_DECL_MPZ_INITS
+#  include <stdarg.h>
+# endif
 #endif
 
 #include <assert.h>
@@ -526,6 +529,27 @@ factor_insert_large (struct factors *factors,
 }
 
 #if HAVE_GMP
+
+# if !HAVE_DECL_MPZ_INITS
+
+#  define mpz_inits(...) mpz_va_init (mpz_init, __VA_ARGS__)
+#  define mpz_clears(...) mpz_va_init (mpz_clear, __VA_ARGS__)
+
+static void
+mpz_va_init (void (*mpz_single_init)(mpz_t), ...)
+{
+  va_list ap;
+
+  va_start (ap, mpz_single_init);
+
+  mpz_t *mpz;
+  while ((mpz = va_arg (ap, mpz_t *)))
+    mpz_single_init (*mpz);
+
+  va_end (ap);
+}
+# endif
+
 static void mp_factor (mpz_t, struct mp_factors *);
 
 static void