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

mercurial at gmplib.org mercurial at gmplib.org
Mon Jan 7 16:24:24 CET 2013


details:   /var/hg/gmp/rev/ba7aa29f4e4c
changeset: 15237:ba7aa29f4e4c
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Mon Jan 07 15:49:25 2013 +0100
description:
mini-gmp/README: Document base limitation for conversions.

details:   /var/hg/gmp/rev/53da2d2777a6
changeset: 15238:53da2d2777a6
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Mon Jan 07 15:53:33 2013 +0100
description:
mini-gmp/mini-gmp.c (mpz_set_str): Remove goto.

details:   /var/hg/gmp/rev/c31228ea8a69
changeset: 15239:c31228ea8a69
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Mon Jan 07 15:57:17 2013 +0100
description:
mini-gmp/mini-gmp.c: Add a couple of assert and remove typos.

details:   /var/hg/gmp/rev/562a998702fe
changeset: 15240:562a998702fe
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Mon Jan 07 16:02:51 2013 +0100
description:
mini-gmp/mini-gmp.c (mpz_expor): Return *countp = 0 when operand is 0.

details:   /var/hg/gmp/rev/da5d476a381a
changeset: 15241:da5d476a381a
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Mon Jan 07 16:05:41 2013 +0100
description:
mini-gmp/mini-gmp.c (mpz_{im,ex}port): Correctly use order/endianess.

details:   /var/hg/gmp/rev/7e7063a0f563
changeset: 15242:7e7063a0f563
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Mon Jan 07 16:06:01 2013 +0100
description:
Changelog

diffstat:

 ChangeLog           |   7 +++++++
 mini-gmp/README     |   4 +++-
 mini-gmp/mini-gmp.c |  40 +++++++++++++++++++++-------------------
 3 files changed, 31 insertions(+), 20 deletions(-)

diffs (147 lines):

diff -r 2ef43d173ab0 -r 7e7063a0f563 ChangeLog
--- a/ChangeLog	Sat Jan 05 20:12:13 2013 +0100
+++ b/ChangeLog	Mon Jan 07 16:06:01 2013 +0100
@@ -1,3 +1,10 @@
+2013-01-07 Marco Bodrato <bodrato at mail.dm.unipi.it>
+
+	* mini-gmp/README: Document base limitation for conversions.
+	* mini-gmp/mini-gmp.c (mpz_set_str): Remove goto.
+	* mini-gmp/mini-gmp.c (mpz_import): Correctly use order/endianess.
+	(mpz_export): Likewise.
+
 2013-01-05  Torbjorn Granlund  <tege at gmplib.org>
 
 	* longlong.h (aarch64): Make add_ssaaaa and sub_ddmmss actually work.
diff -r 2ef43d173ab0 -r 7e7063a0f563 mini-gmp/README
--- a/mini-gmp/README	Sat Jan 05 20:12:13 2013 +0100
+++ b/mini-gmp/README	Mon Jan 07 16:06:01 2013 +0100
@@ -1,4 +1,4 @@
-Copyright 2011, 2012 Free Software Foundation, Inc.
+Copyright 2011, 2012, 2013 Free Software Foundation, Inc.
 
 This file is part of the GNU MP Library.
 
@@ -31,6 +31,8 @@
 functions are fully compatible with the corresponding GMP functions,
 as specified in the GMP manual, with a few exceptions:
 
+  mpz_set_str, mpz_init_set_str, mpz_get_str, mpz_out_str and
+  mpz_sizeinbase support only |base| <= 36;
   mpz_export and mpz_import support only NAILS = 0.
 
   The REALLOC_FUNC and FREE_FUNC registered with
diff -r 2ef43d173ab0 -r 7e7063a0f563 mini-gmp/mini-gmp.c
--- a/mini-gmp/mini-gmp.c	Sat Jan 05 20:12:13 2013 +0100
+++ b/mini-gmp/mini-gmp.c	Mon Jan 07 16:06:01 2013 +0100
@@ -3946,16 +3946,15 @@
       else if (*sp >= 'A' && *sp <= 'Z')
 	digit = *sp - 'A' + 10;
       else
+	digit = base; /* fail */
+
+      if (digit >= base)
 	{
-	fail:
 	  gmp_free (dp);
 	  r->_mp_size = 0;
 	  return -1;
 	}
 
-      if (digit >= base)
-	goto fail;
-
       dp[dn++] = digit;
     }
 
@@ -4033,23 +4032,24 @@
 
   assert (order == 1 || order == -1);
   assert (endian >= -1 && endian <= 1);
+  assert (size > 0);
 
   if (endian == 0)
     endian = gmp_detect_endian ();
 
   p = (unsigned char *) src;
 
+  word_step = (order != endian) ? 2 * size : 0;
+	
   /* Process bytes from the least significant end, so point p at the
      least significant word. */
   if (order == 1)
     {
       p += size * (count - 1);
-      word_step = -(ptrdiff_t) size;
+      word_step = - word_step;
     }
-  else
-    word_step = size;
-
-  /* And at east significant byte of that word. */
+
+  /* And at least significant byte of that word. */
   if (endian == 1)
     p += (size - 1);
 
@@ -4074,7 +4074,7 @@
     rp[i++] = limb;
   assert (i == rn);
 
-  r->_mp_size = rn;
+  r->_mp_size = mpn_normalized_size (rp, i);
 }
 
 void *
@@ -4098,12 +4098,13 @@
 
   assert (order == 1 || order == -1);
   assert (endian >= -1 && endian <= 1);
+  assert (size > 0);
 
   un = GMP_ABS (u->_mp_size);
-  if (!un)
-    return r;
-
   count = (un * sizeof (mp_limb_t) + size - 1) / size;
+
+  if (un) {
+
   if (!r)
     r = gmp_xalloc (count * size);
 
@@ -4112,21 +4113,21 @@
 
   p = (unsigned char *) r;
 
+  word_step = (order != endian) ? 2 * size : 0;
+
   /* Process bytes from the least significant end, so point p at the
      least significant word. */
   if (order == 1)
     {
       p += size * (count - 1);
-      word_step = -(ptrdiff_t) size;
+      word_step = - word_step;
     }
-  else
-    word_step = size;
-
-  /* And at east significant byte of that word. */
+
+  /* And at least significant byte of that word. */
   if (endian == 1)
     p += (size - 1);
 
-  for (limb = 0, bytes = 0, i = 0, k = 0; i < un; k++, p += word_step)
+  for (bytes = 0, i = 0, k = 0; k < count; k++, p += word_step)
     {
       size_t j;
       for (j = 0; j < size; j++, p -= (ptrdiff_t) endian)
@@ -4144,6 +4145,7 @@
     }
   assert (i == un);
   assert (k == count);
+  }
 
   if (countp)
     *countp = count;


More information about the gmp-commit mailing list