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

mercurial at gmplib.org mercurial at gmplib.org
Sun Jan 20 08:03:58 CET 2013


details:   /var/hg/gmp/rev/793314580d5c
changeset: 15321:793314580d5c
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Sun Jan 20 07:53:37 2013 +0100
description:
mini-gmp/tests: New function, to test default memory functions.

details:   /var/hg/gmp/rev/1c3fe15c96dc
changeset: 15322:1c3fe15c96dc
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Sun Jan 20 07:53:55 2013 +0100
description:
ChangeLog

details:   /var/hg/gmp/rev/71f41ff18d73
changeset: 15323:71f41ff18d73
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Sun Jan 20 08:03:45 2013 +0100
description:
mini-gmp/mini-gmp.c (mpz_init_set_str): New function.

details:   /var/hg/gmp/rev/1277bdc8c937
changeset: 15324:1277bdc8c937
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Sun Jan 20 08:03:55 2013 +0100
description:
ChangeLog

diffstat:

 ChangeLog                  |  11 +++++++++++
 mini-gmp/mini-gmp.c        |   7 +++++++
 mini-gmp/mini-gmp.h        |   3 ++-
 mini-gmp/tests/t-logops.c  |  11 +++++++++--
 mini-gmp/tests/t-str.c     |   5 ++---
 mini-gmp/tests/testutils.c |  22 ++++++++++++++++++++++
 mini-gmp/tests/testutils.h |   2 ++
 7 files changed, 55 insertions(+), 6 deletions(-)

diffs (152 lines):

diff -r af30d0d6a6d9 -r 1277bdc8c937 ChangeLog
--- a/ChangeLog	Sun Jan 20 00:53:20 2013 +0100
+++ b/ChangeLog	Sun Jan 20 08:03:55 2013 +0100
@@ -1,3 +1,14 @@
+2013-01-20 Marco Bodrato <bodrato at mail.dm.unipi.it>
+
+	* mini-gmp/tests/testutils.c (testhalves): New function, test
+	default memory functions.	
+	* mini-gmp/tests/testutils.h (testhalves): Declare it
+	* mini-gmp/tests/t-logops.c: Use testhalves.
+
+	* mini-gmp/mini-gmp.c (mpz_init_set_str): New function.
+	* mini-gmp/mini-gmp.h (mpz_init_set_str): Declare it.
+	* mini-gmp/tests/t-str.c: Test mpz_init_set_str.
+
 2013-01-20  Torbjorn Granlund  <tege at gmplib.org>
 
 	* tests/memory.c (PTRLIMB): New macro, used for conformant casting.
diff -r af30d0d6a6d9 -r 1277bdc8c937 mini-gmp/mini-gmp.c
--- a/mini-gmp/mini-gmp.c	Sun Jan 20 00:53:20 2013 +0100
+++ b/mini-gmp/mini-gmp.c	Sun Jan 20 08:03:55 2013 +0100
@@ -3946,6 +3946,13 @@
   return 0;
 }
 
+int
+mpz_init_set_str (mpz_t r, const char *sp, int base)
+{
+  mpz_init (r);
+  return mpz_set_str (r, sp, base);
+}
+
 size_t
 mpz_out_str (FILE *stream, int base, const mpz_t x)
 {
diff -r af30d0d6a6d9 -r 1277bdc8c937 mini-gmp/mini-gmp.h
--- a/mini-gmp/mini-gmp.h	Sun Jan 20 00:53:20 2013 +0100
+++ b/mini-gmp/mini-gmp.h	Sun Jan 20 08:03:55 2013 +0100
@@ -1,6 +1,6 @@
 /* mini-gmp, a minimalistic implementation of a GNU GMP subset.
 
-Copyright 2011, 2012 Free Software Foundation, Inc.
+Copyright 2011, 2012, 2013 Free Software Foundation, Inc.
 
 This file is part of the GNU MP Library.
 
@@ -223,6 +223,7 @@
 size_t mpz_sizeinbase (const mpz_t, int);
 char *mpz_get_str (char *, int, const mpz_t);
 int mpz_set_str (mpz_t, const char *, int);
+int mpz_init_set_str (mpz_t, const char *, int);
 
 /* This long list taken from gmp.h. */
 /* For reference, "defined(EOF)" cannot be used here.  In g++ 2.95.4,
diff -r af30d0d6a6d9 -r 1277bdc8c937 mini-gmp/tests/t-logops.c
--- a/mini-gmp/tests/t-logops.c	Sun Jan 20 00:53:20 2013 +0100
+++ b/mini-gmp/tests/t-logops.c	Sun Jan 20 08:03:55 2013 +0100
@@ -35,7 +35,7 @@
 }
 
 void
-testmain (int argc, char **argv)
+testlogops (int count)
 {
   unsigned i;
   mpz_t a, b, res, ref;
@@ -46,7 +46,7 @@
   mpz_init (res);
   mpz_init (ref);
 
-  for (i = 0; i < COUNT; i++)
+  for (i = 0; i < count; i++)
     {
       mini_random_op3 (OP_AND, MAXBITS, a, b, ref);
       mpz_and (res, a, b);
@@ -111,3 +111,10 @@
   mpz_clear (res);
   mpz_clear (ref);
 }
+
+void
+testmain (int argc, char **argv)
+{
+  testhalves (COUNT*2/3, testlogops);
+  testlogops (COUNT/3);
+}
diff -r af30d0d6a6d9 -r 1277bdc8c937 mini-gmp/tests/t-str.c
--- a/mini-gmp/tests/t-str.c	Sun Jan 20 00:53:20 2013 +0100
+++ b/mini-gmp/tests/t-str.c	Sun Jan 20 08:03:55 2013 +0100
@@ -89,12 +89,11 @@
   };
   unsigned i;
   mpz_t a, b;
-  mpz_init (a);
   mpz_init (b);
 
   for (i = 0; data[i].input; i++)
     {
-      int res = mpz_set_str (a, data[i].input, 0);
+      int res = mpz_init_set_str (a, data[i].input, 0);
       if (data[i].decimal)
 	{
 	  if (res != 0)
@@ -125,9 +124,9 @@
 		   res, data[i].input);
 	  abort ();
 	}
+      mpz_clear (a);
     }
 
-  mpz_clear (a);
   mpz_clear (b);
 }
 
diff -r af30d0d6a6d9 -r 1277bdc8c937 mini-gmp/tests/testutils.c
--- a/mini-gmp/tests/testutils.c	Sun Jan 20 00:53:20 2013 +0100
+++ b/mini-gmp/tests/testutils.c	Sun Jan 20 08:03:55 2013 +0100
@@ -119,3 +119,25 @@
     }
   return 0;
 }
+
+void
+testhalves (int count, void (*tested_fun) (int))
+{
+  void (*freefunc) (void *, size_t);
+  void *(*reallocfunc) (void *, size_t, size_t);
+  void *(*allocfunc) (size_t);
+  size_t initial_alloc;
+
+  mp_get_memory_functions (&allocfunc, &reallocfunc, &freefunc);
+  initial_alloc = total_alloc; 
+  (*tested_fun) (count / 2);
+  if (initial_alloc != total_alloc)
+    {
+      fprintf (stderr, "First half, memory leaked: %lu bytes.\n",
+	       (unsigned long) total_alloc - initial_alloc);
+      abort ();
+    }
+  mp_set_memory_functions (NULL, NULL, NULL);
+  (*tested_fun) (count / 2);
+  mp_set_memory_functions (allocfunc, reallocfunc, freefunc);
+}
diff -r af30d0d6a6d9 -r 1277bdc8c937 mini-gmp/tests/testutils.h
--- a/mini-gmp/tests/testutils.h	Sun Jan 20 00:53:20 2013 +0100
+++ b/mini-gmp/tests/testutils.h	Sun Jan 20 08:03:55 2013 +0100
@@ -20,3 +20,5 @@
 #include "mini-random.h"
 
 void testmain (int argc, char **argv);
+
+void testhalves (int count, void (*tested_fun) (int));


More information about the gmp-commit mailing list