[Gmp-commit] /var/hg/gmp: Use MPZ_REALLOC return value when possible.

mercurial at gmplib.org mercurial at gmplib.org
Sat May 26 15:57:49 CEST 2012


details:   /var/hg/gmp/rev/3c85b9edc71e
changeset: 15011:3c85b9edc71e
user:      Torbjorn Granlund <tege at gmplib.org>
date:      Sat May 26 15:57:43 2012 +0200
description:
Use MPZ_REALLOC return value when possible.

diffstat:

 ChangeLog          |   4 ++++
 mpz/aors.h         |   5 ++---
 mpz/aorsmul.c      |   5 ++---
 mpz/aorsmul_i.c    |   8 +++-----
 mpz/cdiv_q_ui.c    |   6 +++---
 mpz/cdiv_qr_ui.c   |  10 ++++------
 mpz/cdiv_r_ui.c    |   7 +++----
 mpz/cfdiv_r_2exp.c |   8 +++-----
 mpz/combit.c       |   8 +++-----
 mpz/dive_ui.c      |   5 ++---
 mpz/divegcd.c      |  11 ++++-------
 mpz/fdiv_q_ui.c    |   7 +++----
 mpz/fdiv_qr_ui.c   |   5 ++---
 mpz/fdiv_r_ui.c    |   5 ++---
 mpz/fib2_ui.c      |   8 +++-----
 mpz/fib_ui.c       |   5 ++---
 mpz/import.c       |   5 ++---
 mpz/inp_raw.c      |   5 ++---
 mpz/lucnum2_ui.c   |   8 +++-----
 mpz/lucnum_ui.c    |   5 ++---
 mpz/mul.c          |   8 +++-----
 mpz/n_pow_ui.c     |   3 +--
 mpz/random2.c      |   7 ++++---
 mpz/rrandomb.c     |   7 ++++---
 mpz/set.c          |   5 ++---
 mpz/set_f.c        |   5 ++---
 mpz/tdiv_q.c       |   7 +++----
 mpz/tdiv_q_ui.c    |   5 ++---
 mpz/tdiv_qr.c      |  10 +++-------
 mpz/tdiv_qr_ui.c   |   8 +++-----
 mpz/tdiv_r.c       |   8 +++-----
 mpz/tdiv_r_ui.c    |   7 +++----
 32 files changed, 87 insertions(+), 123 deletions(-)

diffs (truncated from 825 to 300 lines):

diff -r 7bf8ca53869b -r 3c85b9edc71e ChangeLog
--- a/ChangeLog	Fri May 25 10:40:47 2012 +0200
+++ b/ChangeLog	Sat May 26 15:57:43 2012 +0200
@@ -1,3 +1,7 @@
+2012-05-26  Torbjorn Granlund  <tege at gmplib.org>
+
+	* mpz: Use MPZ_REALLOC return value when possible.
+
 2012-05-25 Marco Bodrato <bodrato at mail.dm.unipi.it>
 
 	* mini-gmp/tests/t-div.c: Test all _qr, _q, _r variants.
diff -r 7bf8ca53869b -r 3c85b9edc71e mpz/aors.h
--- a/mpz/aors.h	Fri May 25 10:40:47 2012 +0200
+++ b/mpz/aors.h	Sat May 26 15:57:43 2012 +0200
@@ -1,6 +1,6 @@
 /* mpz_add, mpz_sub -- add or subtract integers.
 
-Copyright 1991, 1993, 1994, 1996, 2000, 2001, 2011 Free Software
+Copyright 1991, 1993, 1994, 1996, 2000, 2001, 2011, 2012 Free Software
 Foundation, Inc.
 
 This file is part of the GNU MP Library.
@@ -62,12 +62,11 @@
 
   /* If not space for w (and possible carry), increase space.  */
   wsize = abs_usize + 1;
-  MPZ_REALLOC (w, wsize);
+  wp = MPZ_REALLOC (w, wsize);
 
   /* These must be after realloc (u or v may be the same as w).  */
   up = PTR(u);
   vp = PTR(v);
-  wp = PTR(w);
 
   if ((usize ^ vsize) < 0)
     {
diff -r 7bf8ca53869b -r 3c85b9edc71e mpz/aorsmul.c
--- a/mpz/aorsmul.c	Fri May 25 10:40:47 2012 +0200
+++ b/mpz/aorsmul.c	Sat May 26 15:57:43 2012 +0200
@@ -1,6 +1,6 @@
 /* mpz_addmul, mpz_submul -- add or subtract multiple.
 
-Copyright 2001, 2004, 2005 Free Software Foundation, Inc.
+Copyright 2001, 2004, 2005, 2012 Free Software Foundation, Inc.
 
 This file is part of the GNU MP Library.
 
@@ -76,8 +76,7 @@
   wsize = ABS(wsize_signed);
 
   tsize = xsize + ysize;
-  MPZ_REALLOC (w, MAX (wsize, tsize) + 1);
-  wp = PTR(w);
+  wp = MPZ_REALLOC (w, MAX (wsize, tsize) + 1);
 
   if (wsize_signed == 0)
     {
diff -r 7bf8ca53869b -r 3c85b9edc71e mpz/aorsmul_i.c
--- a/mpz/aorsmul_i.c	Fri May 25 10:40:47 2012 +0200
+++ b/mpz/aorsmul_i.c	Sat May 26 15:57:43 2012 +0200
@@ -4,7 +4,7 @@
    ALMOST CERTAIN TO BE SUBJECT TO INCOMPATIBLE CHANGES OR DISAPPEAR
    COMPLETELY IN FUTURE GNU MP RELEASES.
 
-Copyright 2001, 2002, 2004, 2005 Free Software Foundation, Inc.
+Copyright 2001, 2002, 2004, 2005, 2012 Free Software Foundation, Inc.
 
 This file is part of the GNU MP Library.
 
@@ -75,8 +75,7 @@
   if (wsize_signed == 0)
     {
       /* nothing to add to, just set x*y, "sub" gives the sign */
-      MPZ_REALLOC (w, xsize+1);
-      wp = PTR (w);
+      wp = MPZ_REALLOC (w, xsize+1);
       cy = mpn_mul_1 (wp, PTR(x), xsize, y);
       wp[xsize] = cy;
       xsize += (cy != 0);
@@ -88,8 +87,7 @@
   wsize = ABS (wsize_signed);
 
   new_wsize = MAX (wsize, xsize);
-  MPZ_REALLOC (w, new_wsize+1);
-  wp = PTR (w);
+  wp = MPZ_REALLOC (w, new_wsize+1);
   xp = PTR (x);
   min_size = MIN (wsize, xsize);
 
diff -r 7bf8ca53869b -r 3c85b9edc71e mpz/cdiv_q_ui.c
--- a/mpz/cdiv_q_ui.c	Fri May 25 10:40:47 2012 +0200
+++ b/mpz/cdiv_q_ui.c	Sat May 26 15:57:43 2012 +0200
@@ -3,7 +3,8 @@
    always fit into the return type, the negative of the true remainder is
    returned.
 
-Copyright 1994, 1996, 1999, 2001, 2002, 2004 Free Software Foundation, Inc.
+Copyright 1994, 1996, 1999, 2001, 2002, 2004, 2012 Free Software Foundation,
+Inc.
 
 This file is part of the GNU MP Library.
 
@@ -41,8 +42,7 @@
     }
 
   nn = ABS(ns);
-  MPZ_REALLOC (quot, nn);
-  qp = PTR(quot);
+  qp = MPZ_REALLOC (quot, nn);
   np = PTR(dividend);
 
 #if BITS_PER_ULONG > GMP_NUMB_BITS  /* avoid warnings about shift amount */
diff -r 7bf8ca53869b -r 3c85b9edc71e mpz/cdiv_qr_ui.c
--- a/mpz/cdiv_qr_ui.c	Fri May 25 10:40:47 2012 +0200
+++ b/mpz/cdiv_qr_ui.c	Sat May 26 15:57:43 2012 +0200
@@ -3,8 +3,8 @@
    always fit into the return type, the negative of the true remainder is
    returned.
 
-Copyright 1994, 1995, 1996, 1999, 2001, 2002, 2004 Free Software Foundation,
-Inc.
+Copyright 1994, 1995, 1996, 1999, 2001, 2002, 2004, 2012 Free Software
+Foundation, Inc.
 
 This file is part of the GNU MP Library.
 
@@ -43,8 +43,7 @@
     }
 
   nn = ABS(ns);
-  MPZ_REALLOC (quot, nn);
-  qp = PTR(quot);
+  qp = MPZ_REALLOC (quot, nn);
   np = PTR(dividend);
 
 #if BITS_PER_ULONG > GMP_NUMB_BITS  /* avoid warnings about shift amount */
@@ -54,8 +53,7 @@
       mp_ptr rp;
       mp_size_t rn;
 
-      MPZ_REALLOC (rem, 2);
-      rp = PTR(rem);
+      rp = MPZ_REALLOC (rem, 2);
 
       if (nn == 1)		/* tdiv_qr requirements; tested above for 0 */
 	{
diff -r 7bf8ca53869b -r 3c85b9edc71e mpz/cdiv_r_ui.c
--- a/mpz/cdiv_r_ui.c	Fri May 25 10:40:47 2012 +0200
+++ b/mpz/cdiv_r_ui.c	Sat May 26 15:57:43 2012 +0200
@@ -3,8 +3,8 @@
    always fit into the return type, the negative of the true remainder is
    returned.
 
-Copyright 1994, 1995, 1996, 2001, 2002, 2004, 2005 Free Software Foundation,
-Inc.
+Copyright 1994, 1995, 1996, 2001, 2002, 2004, 2005, 2012 Free Software
+Foundation, Inc.
 
 This file is part of the GNU MP Library.
 
@@ -51,8 +51,7 @@
       mp_size_t rn;
       TMP_DECL;
 
-      MPZ_REALLOC (rem, 2);
-      rp = PTR(rem);
+      rp = MPZ_REALLOC (rem, 2);
 
       if (nn == 1)		/* tdiv_qr requirements; tested above for 0 */
 	{
diff -r 7bf8ca53869b -r 3c85b9edc71e mpz/cfdiv_r_2exp.c
--- a/mpz/cfdiv_r_2exp.c	Fri May 25 10:40:47 2012 +0200
+++ b/mpz/cfdiv_r_2exp.c	Sat May 26 15:57:43 2012 +0200
@@ -1,6 +1,6 @@
 /* mpz_cdiv_r_2exp, mpz_fdiv_r_2exp -- remainder from mpz divided by 2^n.
 
-Copyright 2001, 2002, 2004 Free Software Foundation, Inc.
+Copyright 2001, 2002, 2004, 2012 Free Software Foundation, Inc.
 
 This file is part of the GNU MP Library.
 
@@ -67,8 +67,7 @@
       else
 	{
 	  i = MIN (abs_usize, limb_cnt+1);
-	  MPZ_REALLOC (w, i);
-	  wp = PTR(w);
+	  wp = MPZ_REALLOC (w, i);
 	  MPN_COPY (wp, up, i);
 
 	  /* if smaller than limb_cnt then only the copy is needed */
@@ -103,9 +102,8 @@
     negate:
       /* twos complement negation to get 2**cnt-u */
 
-      MPZ_REALLOC (w, limb_cnt+1);
+      wp = MPZ_REALLOC (w, limb_cnt+1);
       up = PTR(u);
-      wp = PTR(w);
 
       /* Ones complement */
       i = MIN (abs_usize, limb_cnt+1);
diff -r 7bf8ca53869b -r 3c85b9edc71e mpz/combit.c
--- a/mpz/combit.c	Fri May 25 10:40:47 2012 +0200
+++ b/mpz/combit.c	Sat May 26 15:57:43 2012 +0200
@@ -1,6 +1,6 @@
 /* mpz_combit -- complement a specified bit.
 
-Copyright 2002, 2003 Free Software Foundation, Inc.
+Copyright 2002, 2003, 2012 Free Software Foundation, Inc.
 
 This file is part of the GNU MP Library.
 
@@ -31,8 +31,7 @@
 
   if (limb_index >= dsize)
     {
-      MPZ_REALLOC(d, limb_index + 1);
-      dp = LIMBS(d);
+      dp = MPZ_REALLOC(d, limb_index + 1);
 
       MPN_ZERO(dp + dsize, limb_index + 1 - dsize);
       dsize = limb_index + 1;
@@ -62,8 +61,7 @@
 	  mp_limb_t  c;
 
 	  /* Clearing the bit increases the magitude. We might need a carry. */
-	  MPZ_REALLOC(d, dsize + 1);
-	  dp = LIMBS(d);
+	  dp = MPZ_REALLOC(d, dsize + 1);
 
 	  __GMPN_ADD_1 (c, dp+limb_index, dp+limb_index,
 			dsize - limb_index, bit);
diff -r 7bf8ca53869b -r 3c85b9edc71e mpz/dive_ui.c
--- a/mpz/dive_ui.c	Fri May 25 10:40:47 2012 +0200
+++ b/mpz/dive_ui.c	Sat May 26 15:57:43 2012 +0200
@@ -1,6 +1,6 @@
 /* mpz_divexact_ui -- exact division mpz by ulong.
 
-Copyright 2001, 2002 Free Software Foundation, Inc.
+Copyright 2001, 2002, 2012 Free Software Foundation, Inc.
 
 This file is part of the GNU MP Library.
 
@@ -50,8 +50,7 @@
     }
   abs_size = ABS (size);
 
-  MPZ_REALLOC (dst, abs_size);
-  dst_ptr = PTR(dst);
+  dst_ptr = MPZ_REALLOC (dst, abs_size);
 
   MPN_DIVREM_OR_DIVEXACT_1 (dst_ptr, PTR(src), abs_size, (mp_limb_t) divisor);
   abs_size -= (dst_ptr[abs_size-1] == 0);
diff -r 7bf8ca53869b -r 3c85b9edc71e mpz/divegcd.c
--- a/mpz/divegcd.c	Fri May 25 10:40:47 2012 +0200
+++ b/mpz/divegcd.c	Sat May 26 15:57:43 2012 +0200
@@ -3,7 +3,7 @@
    THE FUNCTIONS IN THIS FILE ARE FOR INTERNAL USE AND ARE ALMOST CERTAIN TO
    BE SUBJECT TO INCOMPATIBLE CHANGES IN FUTURE GNU MP RELEASES.
 
-Copyright 2000, 2005, 2011 Free Software Foundation, Inc.
+Copyright 2000, 2005, 2011, 2012 Free Software Foundation, Inc.
 
 This file is part of the GNU MP Library.
 
@@ -52,9 +52,8 @@
   mp_size_t  abs_size = ABS(size);
   mp_ptr     qp;
 
-  MPZ_REALLOC (q, abs_size);
+  qp = MPZ_REALLOC (q, abs_size);
 
-  qp = PTR(q);
   mpn_bdiv_dbm1 (qp, PTR(a), abs_size, GMP_NUMB_MASK / 3);
 
   abs_size -= (qp[abs_size-1] == 0);
@@ -70,9 +69,8 @@
   mp_size_t  abs_size = ABS(size);
   mp_ptr     qp;
 
-  MPZ_REALLOC (q, abs_size);
+  qp = MPZ_REALLOC (q, abs_size);
 
-  qp = PTR(q);
   mpn_bdiv_dbm1 (qp, PTR(a), abs_size, GMP_NUMB_MASK / 5);
 
   abs_size -= (qp[abs_size-1] == 0);
@@ -87,9 +85,8 @@
   mp_size_t  abs_size = ABS(size);
   mp_ptr     qp;
 
-  MPZ_REALLOC (q, abs_size);
+  qp = MPZ_REALLOC (q, abs_size);
 
-  qp = PTR(q);
   mpn_divexact_1 (qp, PTR(a), abs_size, d);
 
   abs_size -= (qp[abs_size-1] == 0);
diff -r 7bf8ca53869b -r 3c85b9edc71e mpz/fdiv_q_ui.c


More information about the gmp-commit mailing list