[Gmp-commit] /var/hg/gmp: 2 new changesets

mercurial at gmplib.org mercurial at gmplib.org
Sat Feb 8 07:29:41 UTC 2014


details:   /var/hg/gmp/rev/c84c8bbf6191
changeset: 16279:c84c8bbf6191
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Sat Feb 08 08:28:25 2014 +0100
description:
mini-gmp/tests/t-mul.c: better memory checking.

details:   /var/hg/gmp/rev/131ad319a811
changeset: 16280:131ad319a811
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Sat Feb 08 08:29:16 2014 +0100
description:
mini-gmp: Add mpz_limbs_*, mpz_realloc2, roinit.

diffstat:

 mini-gmp/mini-gmp.c    |  42 ++++++++++++++++++++++++++++++++++++++++++
 mini-gmp/mini-gmp.h    |   9 +++++++++
 mini-gmp/tests/t-mul.c |   6 +++---
 3 files changed, 54 insertions(+), 3 deletions(-)

diffs (98 lines):

diff -r bd37f6313205 -r 131ad319a811 mini-gmp/mini-gmp.c
--- a/mini-gmp/mini-gmp.c	Thu Feb 06 08:14:38 2014 +0100
+++ b/mini-gmp/mini-gmp.c	Sat Feb 08 08:29:16 2014 +0100
@@ -1527,6 +1527,48 @@
     return 0;
 }
 
+void
+mpz_realloc2 (mpz_t x, mp_bitcnt_t n)
+{
+  mpz_realloc (x, 1 + (n - (n != 0)) / GMP_LIMB_BITS);
+}
+
+mp_srcptr
+mpz_limbs_read (mpz_srcptr x)
+{
+  return x->_mp_d;;
+}
+
+mp_ptr
+mpz_limbs_modify (mpz_t x, mp_size_t n)
+{
+  assert (n > 0);
+  return MPZ_REALLOC (x, n);
+}
+
+mp_ptr
+mpz_limbs_write (mpz_t x, mp_size_t n)
+{
+  return mpz_limbs_modify (x, n);
+}
+
+void
+mpz_limbs_finish (mpz_t x, mp_size_t xs)
+{
+  mp_size_t xn;
+  xn = mpn_normalized_size (x->_mp_d, GMP_ABS (xs));
+  x->_mp_size = xs < 0 ? -xn : xn;
+}
+
+mpz_srcptr
+mpz_roinit_n (mpz_t x, mp_srcptr xp, mp_size_t xs)
+{
+  x->_mp_alloc = 0;
+  x->_mp_d = (mp_ptr) xp;
+  mpz_limbs_finish (x, xs);
+  return x;
+}
+
 
 /* Conversions and comparison to double. */
 void
diff -r bd37f6313205 -r 131ad319a811 mini-gmp/mini-gmp.h
--- a/mini-gmp/mini-gmp.h	Thu Feb 06 08:14:38 2014 +0100
+++ b/mini-gmp/mini-gmp.h	Sat Feb 08 08:29:16 2014 +0100
@@ -235,6 +235,15 @@
 size_t mpz_size (const mpz_t);
 mp_limb_t mpz_getlimbn (const mpz_t, mp_size_t);
 
+void mpz_realloc2 (mpz_t, mp_bitcnt_t);
+mp_srcptr mpz_limbs_read (mpz_srcptr);
+mp_ptr mpz_limbs_modify (mpz_t, mp_size_t);
+mp_ptr mpz_limbs_write (mpz_t, mp_size_t);
+void mpz_limbs_finish (mpz_t, mp_size_t);
+mpz_srcptr mpz_roinit_n (mpz_t, mp_srcptr, mp_size_t);
+
+#define MPZ_ROINIT_N(xp, xs) {{0, (xs),(xp) }}
+
 void mpz_set_si (mpz_t, signed long int);
 void mpz_set_ui (mpz_t, unsigned long int);
 void mpz_set (mpz_t, const mpz_t);
diff -r bd37f6313205 -r 131ad319a811 mini-gmp/tests/t-mul.c
--- a/mini-gmp/tests/t-mul.c	Thu Feb 06 08:14:38 2014 +0100
+++ b/mini-gmp/tests/t-mul.c	Sat Feb 08 08:29:16 2014 +0100
@@ -67,12 +67,12 @@
 	}
       if (mpz_size (a) == mpz_size (b))
 	{
-	  memset (t, 0, sizeof(t));
+	  memset (t, 0x55, sizeof(t));
 	  an = mpz_size (a);
 	  if (an > 0)
 	    {
 	      mpn_mul_n (t, a->_mp_d, b->_mp_d, an);
-	      rn = 2*an - (res->_mp_d[2*an-1] == 0);
+	      rn = 2*an - (t[2*an-1] == 0);
 	      if (rn != mpz_size (ref) || mpn_cmp (t, ref->_mp_d, rn))
 		{
 		  fprintf (stderr, "mpn_mul_n failed:\n");
@@ -99,7 +99,7 @@
       an = mpz_size (a);
       if (an > 0)
 	{
-	  memset (t, 0, sizeof(t));
+	  memset (t, 0x33, sizeof(t));
 	  mpn_sqr (t, a->_mp_d, an);
 
 	  rn = 2*an - (t[2*an-1] == 0);


More information about the gmp-commit mailing list