summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPádraig Brady <P@draigBrady.com>2012-10-08 11:38:41 +0100
committerPádraig Brady <P@draigBrady.com>2012-10-08 23:40:08 +0100
commitcf9cd8958bbf294c30b82c2d5e9ea64ef14f37b9 (patch)
treec3cccfcf3679cb335ec7406c3d93ea5835a9a9e0 /src
parent231e40a6ba29b892daca1e4a2e464c315874e155 (diff)
downloadcoreutils-cf9cd8958bbf294c30b82c2d5e9ea64ef14f37b9.tar.xz
build: support older GMP versions
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.
Diffstat (limited to 'src')
-rw-r--r--src/factor.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/factor.c b/src/factor.c
index 5bfbfdcd4..d5f248a6a 100644
--- a/src/factor.c
+++ b/src/factor.c
@@ -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