[Gmp-commit] /var/hg/gmp: mini-gmp tests: Use correct deallocation function.

mercurial at gmplib.org mercurial at gmplib.org
Mon Feb 25 15:48:05 CET 2013


details:   /var/hg/gmp/rev/b6058270834c
changeset: 15484:b6058270834c
user:      Niels M?ller <nisse at lysator.liu.se>
date:      Mon Feb 25 15:48:02 2013 +0100
description:
mini-gmp tests: Use correct deallocation function.

diffstat:

 ChangeLog                   |   5 +++++
 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   |   7 ++-----
 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, 35 insertions(+), 24 deletions(-)

diffs (273 lines):

diff -r 344133d14ea3 -r b6058270834c ChangeLog
--- a/ChangeLog	Mon Feb 25 11:50:49 2013 +0100
+++ b/ChangeLog	Mon Feb 25 15:48:02 2013 +0100
@@ -1,5 +1,10 @@
 2013-02-25  Niels Möller  <nisse at lysator.liu.se>
 
+	* 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.
+	
 	* mpz/limbs_finish.c (mpz_limbs_finish): New file and function.
 	* mpz/limbs_modify.c (mpz_limbs_modify): New file and function.
 	* mpz/limbs_read.c (mpz_limbs_read): New file and function.
diff -r 344133d14ea3 -r b6058270834c mini-gmp/tests/t-add.c
--- a/mini-gmp/tests/t-add.c	Mon Feb 25 11:50:49 2013 +0100
+++ b/mini-gmp/tests/t-add.c	Mon Feb 25 15:48:02 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 344133d14ea3 -r b6058270834c mini-gmp/tests/t-bitops.c
--- a/mini-gmp/tests/t-bitops.c	Mon Feb 25 11:50:49 2013 +0100
+++ b/mini-gmp/tests/t-bitops.c	Mon Feb 25 15:48:02 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 344133d14ea3 -r b6058270834c mini-gmp/tests/t-div.c
--- a/mini-gmp/tests/t-div.c	Mon Feb 25 11:50:49 2013 +0100
+++ b/mini-gmp/tests/t-div.c	Mon Feb 25 15:48:02 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 344133d14ea3 -r b6058270834c mini-gmp/tests/t-div_2exp.c
--- a/mini-gmp/tests/t-div_2exp.c	Mon Feb 25 11:50:49 2013 +0100
+++ b/mini-gmp/tests/t-div_2exp.c	Mon Feb 25 15:48:02 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 344133d14ea3 -r b6058270834c mini-gmp/tests/t-double.c
--- a/mini-gmp/tests/t-double.c	Mon Feb 25 11:50:49 2013 +0100
+++ b/mini-gmp/tests/t-double.c	Mon Feb 25 15:48:02 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);
     }
 
diff -r 344133d14ea3 -r b6058270834c mini-gmp/tests/t-gcd.c
--- a/mini-gmp/tests/t-gcd.c	Mon Feb 25 11:50:49 2013 +0100
+++ b/mini-gmp/tests/t-gcd.c	Mon Feb 25 15:48:02 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 344133d14ea3 -r b6058270834c mini-gmp/tests/t-import.c
--- a/mini-gmp/tests/t-import.c	Mon Feb 25 11:50:49 2013 +0100
+++ b/mini-gmp/tests/t-import.c	Mon Feb 25 15:48:02 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 344133d14ea3 -r b6058270834c mini-gmp/tests/t-invert.c
--- a/mini-gmp/tests/t-invert.c	Mon Feb 25 11:50:49 2013 +0100
+++ b/mini-gmp/tests/t-invert.c	Mon Feb 25 15:48:02 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 344133d14ea3 -r b6058270834c mini-gmp/tests/t-lcm.c
--- a/mini-gmp/tests/t-lcm.c	Mon Feb 25 11:50:49 2013 +0100
+++ b/mini-gmp/tests/t-lcm.c	Mon Feb 25 15:48:02 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 344133d14ea3 -r b6058270834c mini-gmp/tests/t-logops.c
--- a/mini-gmp/tests/t-logops.c	Mon Feb 25 11:50:49 2013 +0100
+++ b/mini-gmp/tests/t-logops.c	Mon Feb 25 15:48:02 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 344133d14ea3 -r b6058270834c mini-gmp/tests/t-mul.c
--- a/mini-gmp/tests/t-mul.c	Mon Feb 25 11:50:49 2013 +0100
+++ b/mini-gmp/tests/t-mul.c	Mon Feb 25 15:48:02 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 344133d14ea3 -r b6058270834c mini-gmp/tests/t-powm.c
--- a/mini-gmp/tests/t-powm.c	Mon Feb 25 11:50:49 2013 +0100
+++ b/mini-gmp/tests/t-powm.c	Mon Feb 25 15:48:02 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 344133d14ea3 -r b6058270834c mini-gmp/tests/t-root.c
--- a/mini-gmp/tests/t-root.c	Mon Feb 25 11:50:49 2013 +0100
+++ b/mini-gmp/tests/t-root.c	Mon Feb 25 15:48:02 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 344133d14ea3 -r b6058270834c mini-gmp/tests/t-scan.c
--- a/mini-gmp/tests/t-scan.c	Mon Feb 25 11:50:49 2013 +0100
+++ b/mini-gmp/tests/t-scan.c	Mon Feb 25 15:48:02 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 344133d14ea3 -r b6058270834c mini-gmp/tests/t-sqrt.c
--- a/mini-gmp/tests/t-sqrt.c	Mon Feb 25 11:50:49 2013 +0100
+++ b/mini-gmp/tests/t-sqrt.c	Mon Feb 25 15:48:02 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 344133d14ea3 -r b6058270834c mini-gmp/tests/t-str.c
--- a/mini-gmp/tests/t-str.c	Mon Feb 25 11:50:49 2013 +0100
+++ b/mini-gmp/tests/t-str.c	Mon Feb 25 15:48:02 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 344133d14ea3 -r b6058270834c mini-gmp/tests/testutils.c
--- a/mini-gmp/tests/testutils.c	Mon Feb 25 11:50:49 2013 +0100
+++ b/mini-gmp/tests/testutils.c	Mon Feb 25 15:48:02 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 344133d14ea3 -r b6058270834c mini-gmp/tests/testutils.h
--- a/mini-gmp/tests/testutils.h	Mon Feb 25 11:50:49 2013 +0100
+++ b/mini-gmp/tests/testutils.h	Mon Feb 25 15:48:02 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