summaryrefslogtreecommitdiff
path: root/gmp-impl.h
diff options
context:
space:
mode:
authorMarco Bodrato <bodrato@mail.dm.unipi.it>2012-06-08 21:54:49 +0200
committerMarco Bodrato <bodrato@mail.dm.unipi.it>2012-06-08 21:54:49 +0200
commitd278771c99ea01862912a8bb2d074ed26798992e (patch)
treed283f61612e80d0bc072deb689192c57a367f1d7 /gmp-impl.h
parent621a1088c537d37f9c4e252d598436da428d067d (diff)
downloadgmp-d278771c99ea01862912a8bb2d074ed26798992e.tar.gz
(MPZ_NEWALLOC): New macro. Use it in mpq and some mpz.
Diffstat (limited to 'gmp-impl.h')
-rw-r--r--gmp-impl.h15
1 files changed, 15 insertions, 0 deletions
diff --git a/gmp-impl.h b/gmp-impl.h
index 4bc5697b4..ce86c3b69 100644
--- a/gmp-impl.h
+++ b/gmp-impl.h
@@ -1880,10 +1880,25 @@ __GMP_DECLSPEC void mpn_copyd (mp_ptr, mp_srcptr, mp_size_t);
__x->_mp_d = TMP_ALLOC_LIMBS (NLIMBS); \
} while (0)
+#if WANT_ASSERT
+static void *
+_mpz_newalloc (mpz_ptr z, mp_size_t n)
+{
+ void * res = _mpz_realloc(z,n);
+ /* If we are checking the code, force a random change to limbs. */
+ ((mp_ptr) res)[0] = ~ ((mp_ptr) res)[ALLOC (z) - 1];
+ return res;
+}
+#else
+#define _mpz_newalloc _mpz_realloc
+#endif
/* Realloc for an mpz_t WHAT if it has less than NEEDED limbs. */
#define MPZ_REALLOC(z,n) (UNLIKELY ((n) > ALLOC(z)) \
? (mp_ptr) _mpz_realloc(z,n) \
: PTR(z))
+#define MPZ_NEWALLOC(z,n) (UNLIKELY ((n) > ALLOC(z)) \
+ ? (mp_ptr) _mpz_newalloc(z,n) \
+ : PTR(z))
#define MPZ_EQUAL_1_P(z) (SIZ(z)==1 && PTR(z)[0] == 1)