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

mercurial at gmplib.org mercurial at gmplib.org
Mon Feb 25 21:30:38 CET 2013


details:   /var/hg/gmp-5.1/rev/1ea055fd8ce3
changeset: 15395:1ea055fd8ce3
user:      Niels M?ller <nisse at lysator.liu.se>
date:      Mon Feb 25 21:27:14 2013 +0100
description:
mini-gmp tests: Use correct deallocation function.

details:   /var/hg/gmp-5.1/rev/29ef0def7fbc
changeset: 15396:29ef0def7fbc
user:      Niels M?ller <nisse at lysator.liu.se>
date:      Mon Feb 25 21:29:23 2013 +0100
description:
mini-gmp tests: Use volatile for floating point variables.

diffstat:

 ChangeLog                   |  10 ++++++++++
 mini-gmp/tests/t-add.c      |   2 +-
 mini-gmp/tests/t-bitops.c   |   2 +-
 mini-gmp/tests/t-div.c      |   2 +-
 mini-gmp/tests/t-div_2exp.c |   2 +-
 mini-gmp/tests/t-double.c   |  11 +++++------
 mini-gmp/tests/t-gcd.c      |   2 +-
 mini-gmp/tests/t-import.c   |   2 +-
 mini-gmp/tests/t-invert.c   |   2 +-
 mini-gmp/tests/t-lcm.c      |   2 +-
 mini-gmp/tests/t-logops.c   |   2 +-
 mini-gmp/tests/t-mul.c      |   2 +-
 mini-gmp/tests/t-powm.c     |   2 +-
 mini-gmp/tests/t-root.c     |   2 +-
 mini-gmp/tests/t-scan.c     |   2 +-
 mini-gmp/tests/t-sqrt.c     |   2 +-
 mini-gmp/tests/t-str.c      |   7 ++-----
 mini-gmp/tests/testutils.c  |  10 ++++++++++
 mini-gmp/tests/testutils.h  |   2 ++
 19 files changed, 43 insertions(+), 25 deletions(-)

diffs (287 lines):

diff -r f57748568347 -r 29ef0def7fbc ChangeLog
--- a/ChangeLog	Tue Feb 19 16:37:31 2013 +0100
+++ b/ChangeLog	Mon Feb 25 21:29:23 2013 +0100
@@ -1,3 +1,13 @@
+2013-02-25  Niels Möller  <nisse at lysator.liu.se>
+
+	* mini-gmp/tests/t-double.c (testmain): Declare double variables
+	as volatile, to drop extended precision.
+
+	* mini-gmp/tests/testutils.c (testfree): New function. Use it
+	everywhere where test programs deallocate storage allocated via
+	the mini-gmp allocation functions, including uses of mpz_get_str
+	for various test failure messages.
+
 2013-02-19 Marco Bodrato <bodrato at mail.dm.unipi.it>
 
 	* mini-gmp/mini-gmp.c: Move asserts to work-around a compiler bug.
diff -r f57748568347 -r 29ef0def7fbc mini-gmp/tests/t-add.c
--- a/mini-gmp/tests/t-add.c	Tue Feb 19 16:37:31 2013 +0100
+++ b/mini-gmp/tests/t-add.c	Mon Feb 25 21:29:23 2013 +0100
@@ -30,7 +30,7 @@
 {
   char *buf = mpz_get_str (NULL, 16, x);
   fprintf (stderr, "%s: %s\n", label, buf);
-  free (buf);
+  testfree (buf);
 }
 
 void
diff -r f57748568347 -r 29ef0def7fbc mini-gmp/tests/t-bitops.c
--- a/mini-gmp/tests/t-bitops.c	Tue Feb 19 16:37:31 2013 +0100
+++ b/mini-gmp/tests/t-bitops.c	Mon Feb 25 21:29:23 2013 +0100
@@ -31,7 +31,7 @@
 {
   char *buf = mpz_get_str (NULL, 16, x);
   fprintf (stderr, "%s: %s\n", label, buf);
-  free (buf);
+  testfree (buf);
 }
 
 void
diff -r f57748568347 -r 29ef0def7fbc mini-gmp/tests/t-div.c
--- a/mini-gmp/tests/t-div.c	Tue Feb 19 16:37:31 2013 +0100
+++ b/mini-gmp/tests/t-div.c	Mon Feb 25 21:29:23 2013 +0100
@@ -31,7 +31,7 @@
 {
   char *buf = mpz_get_str (NULL, 16, x);
   fprintf (stderr, "%s: %s\n", label, buf);
-  free (buf);
+  testfree (buf);
 }
 
 typedef void div_qr_func (mpz_t, mpz_t, const mpz_t, const mpz_t);
diff -r f57748568347 -r 29ef0def7fbc mini-gmp/tests/t-div_2exp.c
--- a/mini-gmp/tests/t-div_2exp.c	Tue Feb 19 16:37:31 2013 +0100
+++ b/mini-gmp/tests/t-div_2exp.c	Mon Feb 25 21:29:23 2013 +0100
@@ -31,7 +31,7 @@
 {
   char *buf = mpz_get_str (NULL, 16, x);
   fprintf (stderr, "%s: %s\n", label, buf);
-  free (buf);
+  testfree (buf);
 }
 
 typedef void div_func (mpz_t, const mpz_t, mp_bitcnt_t);
diff -r f57748568347 -r 29ef0def7fbc mini-gmp/tests/t-double.c
--- a/mini-gmp/tests/t-double.c	Tue Feb 19 16:37:31 2013 +0100
+++ b/mini-gmp/tests/t-double.c	Mon Feb 25 21:29:23 2013 +0100
@@ -34,7 +34,7 @@
 {
   char *buf = mpz_get_str (NULL, 16, x);
   fprintf (stderr, "%s: %s\n", label, buf);
-  free (buf);
+  testfree (buf);
 }
 
 static const struct
@@ -61,9 +61,6 @@
   unsigned i;
   mpz_t x;
 
-  void (*freefunc) (void *, size_t);
-  mp_get_memory_functions (NULL, NULL, &freefunc);
-
   for (i = 0; values[i].s; i++)
     {
       char *s;
@@ -78,7 +75,7 @@
 		   values[i].d, s, values[i].s);
 	  abort ();
 	}
-      freefunc(s, 0);
+      testfree (s);
       mpz_clear (x);
     }
 
@@ -86,7 +83,9 @@
 
   for (i = 0; i < COUNT; i++)
     {
-      double d, f;
+      /* Use volatile, to avoid extended precision in floating point
+	 registers, e.g., on m68k and 80387. */
+      volatile double d, f;
       unsigned long m;
       int e;
 
diff -r f57748568347 -r 29ef0def7fbc mini-gmp/tests/t-gcd.c
--- a/mini-gmp/tests/t-gcd.c	Tue Feb 19 16:37:31 2013 +0100
+++ b/mini-gmp/tests/t-gcd.c	Mon Feb 25 21:29:23 2013 +0100
@@ -31,7 +31,7 @@
 {
   char *buf = mpz_get_str (NULL, 16, x);
   fprintf (stderr, "%s: %s\n", label, buf);
-  free (buf);
+  testfree (buf);
 }
 
 /* Called when g is supposed to be gcd(a,b), and g = s a + t b. */
diff -r f57748568347 -r 29ef0def7fbc mini-gmp/tests/t-import.c
--- a/mini-gmp/tests/t-import.c	Tue Feb 19 16:37:31 2013 +0100
+++ b/mini-gmp/tests/t-import.c	Mon Feb 25 21:29:23 2013 +0100
@@ -31,7 +31,7 @@
 {
   char *buf = mpz_get_str (NULL, 16, x);
   fprintf (stderr, "%s: %s\n", label, buf);
-  free (buf);
+  testfree (buf);
 }
 
 static void
diff -r f57748568347 -r 29ef0def7fbc mini-gmp/tests/t-invert.c
--- a/mini-gmp/tests/t-invert.c	Tue Feb 19 16:37:31 2013 +0100
+++ b/mini-gmp/tests/t-invert.c	Mon Feb 25 21:29:23 2013 +0100
@@ -32,7 +32,7 @@
 {
   char *buf = mpz_get_str (NULL, 16, x);
   fprintf (stderr, "%s: %s\n", label, buf);
-  free (buf);
+  testfree (buf);
 }
 
 void
diff -r f57748568347 -r 29ef0def7fbc mini-gmp/tests/t-lcm.c
--- a/mini-gmp/tests/t-lcm.c	Tue Feb 19 16:37:31 2013 +0100
+++ b/mini-gmp/tests/t-lcm.c	Mon Feb 25 21:29:23 2013 +0100
@@ -31,7 +31,7 @@
 {
   char *buf = mpz_get_str (NULL, 16, x);
   fprintf (stderr, "%s: %s\n", label, buf);
-  free (buf);
+  testfree (buf);
 }
 
 void
diff -r f57748568347 -r 29ef0def7fbc mini-gmp/tests/t-logops.c
--- a/mini-gmp/tests/t-logops.c	Tue Feb 19 16:37:31 2013 +0100
+++ b/mini-gmp/tests/t-logops.c	Mon Feb 25 21:29:23 2013 +0100
@@ -31,7 +31,7 @@
 {
   char *buf = mpz_get_str (NULL, 16, x);
   fprintf (stderr, "%s: %s\n", label, buf);
-  free (buf);
+  testfree (buf);
 }
 
 void
diff -r f57748568347 -r 29ef0def7fbc mini-gmp/tests/t-mul.c
--- a/mini-gmp/tests/t-mul.c	Tue Feb 19 16:37:31 2013 +0100
+++ b/mini-gmp/tests/t-mul.c	Mon Feb 25 21:29:23 2013 +0100
@@ -35,7 +35,7 @@
 {
   char *buf = mpz_get_str (NULL, 16, x);
   fprintf (stderr, "%s: %s\n", label, buf);
-  free (buf);
+  testfree (buf);
 }
 
 void
diff -r f57748568347 -r 29ef0def7fbc mini-gmp/tests/t-powm.c
--- a/mini-gmp/tests/t-powm.c	Tue Feb 19 16:37:31 2013 +0100
+++ b/mini-gmp/tests/t-powm.c	Mon Feb 25 21:29:23 2013 +0100
@@ -31,7 +31,7 @@
 {
   char *buf = mpz_get_str (NULL, 16, x);
   fprintf (stderr, "%s: %s\n", label, buf);
-  free (buf);
+  testfree (buf);
 }
 
 void
diff -r f57748568347 -r 29ef0def7fbc mini-gmp/tests/t-root.c
--- a/mini-gmp/tests/t-root.c	Tue Feb 19 16:37:31 2013 +0100
+++ b/mini-gmp/tests/t-root.c	Mon Feb 25 21:29:23 2013 +0100
@@ -31,7 +31,7 @@
 {
   char *buf = mpz_get_str (NULL, 16, x);
   fprintf (stderr, "%s: %s\n", label, buf);
-  free (buf);
+  testfree (buf);
 }
 
 /* Called when s is supposed to be floor(root(u,z)), and r = u - s^z */
diff -r f57748568347 -r 29ef0def7fbc mini-gmp/tests/t-scan.c
--- a/mini-gmp/tests/t-scan.c	Tue Feb 19 16:37:31 2013 +0100
+++ b/mini-gmp/tests/t-scan.c	Mon Feb 25 21:29:23 2013 +0100
@@ -31,7 +31,7 @@
 {
   char *buf = mpz_get_str (NULL, 16, x);
   fprintf (stderr, "%s: %s\n", label, buf);
-  free (buf);
+  testfree (buf);
 }
 
 void
diff -r f57748568347 -r 29ef0def7fbc mini-gmp/tests/t-sqrt.c
--- a/mini-gmp/tests/t-sqrt.c	Tue Feb 19 16:37:31 2013 +0100
+++ b/mini-gmp/tests/t-sqrt.c	Mon Feb 25 21:29:23 2013 +0100
@@ -31,7 +31,7 @@
 {
   char *buf = mpz_get_str (NULL, 16, x);
   fprintf (stderr, "%s: %s\n", label, buf);
-  free (buf);
+  testfree (buf);
 }
 
 /* Called when s is supposed to be floor(sqrt(u)), and r = u - s^2 */
diff -r f57748568347 -r 29ef0def7fbc mini-gmp/tests/t-str.c
--- a/mini-gmp/tests/t-str.c	Tue Feb 19 16:37:31 2013 +0100
+++ b/mini-gmp/tests/t-str.c	Mon Feb 25 21:29:23 2013 +0100
@@ -36,7 +36,7 @@
 {
   char *buf = mpz_get_str (NULL, 16, x);
   fprintf (stderr, "%s: %s\n", label, buf);
-  free (buf);
+  testfree (buf);
 }
 
 static void
@@ -143,9 +143,6 @@
 
   FILE *tmp;
 
-  void (*freefunc) (void *, size_t);
-  mp_get_memory_functions (NULL, NULL, &freefunc);
-
   test_small ();
 
   mpz_init (a);
@@ -310,7 +307,7 @@
 		}
 	    }
 	  free (ap);
-	  freefunc (bp, 0);
+	  testfree (bp);
 	}
     }
   mpz_clear (a);
diff -r f57748568347 -r 29ef0def7fbc mini-gmp/tests/testutils.c
--- a/mini-gmp/tests/testutils.c	Tue Feb 19 16:37:31 2013 +0100
+++ b/mini-gmp/tests/testutils.c	Mon Feb 25 21:29:23 2013 +0100
@@ -100,6 +100,16 @@
   free (block_check (p));
 }
 
+/* Free memory allocated via mini-gmp allocation function. */
+void
+testfree (void *p)
+{
+  void (*freefunc) (void *, size_t);
+  mp_get_memory_functions (NULL, NULL, &freefunc);
+
+  freefunc (p, 0);
+}
+
 int
 main (int argc, char **argv)
 {
diff -r f57748568347 -r 29ef0def7fbc mini-gmp/tests/testutils.h
--- a/mini-gmp/tests/testutils.h	Tue Feb 19 16:37:31 2013 +0100
+++ b/mini-gmp/tests/testutils.h	Mon Feb 25 21:29:23 2013 +0100
@@ -27,3 +27,5 @@
 void testmain (int argc, char **argv);
 
 void testhalves (int count, void (*tested_fun) (int));
+
+void testfree (void *p);


More information about the gmp-commit mailing list