[Gmp-commit] /var/hg/gmp: Handle lazy 0 numerator in mpq.

mercurial at gmplib.org mercurial at gmplib.org
Wed Apr 18 21:28:32 UTC 2018


details:   /var/hg/gmp/rev/6e5b01dd940f
changeset: 17598:6e5b01dd940f
user:      Marc Glisse <marc.glisse at inria.fr>
date:      Wed Apr 18 23:28:26 2018 +0200
description:
Handle lazy 0 numerator in mpq.
As posted on the mailing-list 2 years ago...

diffstat:

 ChangeLog            |  10 ++++++++++
 mpq/clear.c          |   3 ++-
 mpq/clears.c         |   3 ++-
 mpq/init.c           |   5 +++--
 mpq/set_si.c         |   2 +-
 mpq/set_ui.c         |   2 +-
 tests/cxx/t-ops2z.cc |   2 +-
 7 files changed, 20 insertions(+), 7 deletions(-)

diffs (93 lines):

diff -r 836813cdfe79 -r 6e5b01dd940f ChangeLog
--- a/ChangeLog	Mon Apr 16 21:51:39 2018 +0200
+++ b/ChangeLog	Wed Apr 18 23:28:26 2018 +0200
@@ -1,3 +1,13 @@
+2018-04-18  Marc Glisse  <marc.glisse at inria.fr>
+
+	* mpq/clear.c: Handle lazy numerator.
+	* mpq/clears.c: Likewise.
+	* mpq/init.c: Likewise.
+	* mpq/set_si.c: Likewise.
+	* mpq/set_ui.c: Likewise.
+
+	* tests/cxx/t-ops2z.cc: Add parentheses to quiet a warning.
+
 2018-03-23  Torbjörn Granlund  <tg at gmplib.org>
 
 	* mpn/generic/sec_powm.c: Remove unused macros.
diff -r 836813cdfe79 -r 6e5b01dd940f mpq/clear.c
--- a/mpq/clear.c	Mon Apr 16 21:51:39 2018 +0200
+++ b/mpq/clear.c	Wed Apr 18 23:28:26 2018 +0200
@@ -33,6 +33,7 @@
 void
 mpq_clear (mpq_t x)
 {
-  __GMP_FREE_FUNC_LIMBS (PTR(NUM(x)), ALLOC(NUM(x)));
+  if (ALLOC (NUM(x)))
+    __GMP_FREE_FUNC_LIMBS (PTR(NUM(x)), ALLOC(NUM(x)));
   __GMP_FREE_FUNC_LIMBS (PTR(DEN(x)), ALLOC(DEN(x)));
 }
diff -r 836813cdfe79 -r 6e5b01dd940f mpq/clears.c
--- a/mpq/clears.c	Mon Apr 16 21:51:39 2018 +0200
+++ b/mpq/clears.c	Wed Apr 18 23:28:26 2018 +0200
@@ -40,7 +40,8 @@
 
   do
     {
-      __GMP_FREE_FUNC_LIMBS (PTR(NUM(x)), ALLOC(NUM(x)));
+      if (ALLOC (NUM(x)))
+	__GMP_FREE_FUNC_LIMBS (PTR(NUM(x)), ALLOC(NUM(x)));
       __GMP_FREE_FUNC_LIMBS (PTR(DEN(x)), ALLOC(DEN(x)));
       x = va_arg (ap, mpq_ptr);
     }
diff -r 836813cdfe79 -r 6e5b01dd940f mpq/init.c
--- a/mpq/init.c	Mon Apr 16 21:51:39 2018 +0200
+++ b/mpq/init.c	Wed Apr 18 23:28:26 2018 +0200
@@ -33,8 +33,9 @@
 void
 mpq_init (mpq_t x)
 {
-  ALLOC(NUM(x)) = 1;
-  PTR(NUM(x)) = __GMP_ALLOCATE_FUNC_LIMBS (1);
+  static const mp_limb_t dummy_limb=0xc1a0;
+  ALLOC(NUM(x)) = 0;
+  PTR(NUM(x)) = (mp_ptr) &dummy_limb;
   SIZ(NUM(x)) = 0;
   ALLOC(DEN(x)) = 1;
   PTR(DEN(x)) = __GMP_ALLOCATE_FUNC_LIMBS (1);
diff -r 836813cdfe79 -r 6e5b01dd940f mpq/set_si.c
--- a/mpq/set_si.c	Mon Apr 16 21:51:39 2018 +0200
+++ b/mpq/set_si.c	Wed Apr 18 23:28:26 2018 +0200
@@ -55,7 +55,7 @@
     }
   else
     {
-      PTR(NUM(dest))[0] = abs_num;
+      MPZ_NEWALLOC (NUM(dest), 1)[0] = abs_num;
       SIZ(NUM(dest)) = num > 0 ? 1 : -1;
     }
 
diff -r 836813cdfe79 -r 6e5b01dd940f mpq/set_ui.c
--- a/mpq/set_ui.c	Mon Apr 16 21:51:39 2018 +0200
+++ b/mpq/set_ui.c	Wed Apr 18 23:28:26 2018 +0200
@@ -51,7 +51,7 @@
     }
   else
     {
-      PTR(NUM(dest))[0] = num;
+      MPZ_NEWALLOC (NUM(dest), 1)[0] = num;
       SIZ(NUM(dest)) = 1;
     }
 
diff -r 836813cdfe79 -r 6e5b01dd940f tests/cxx/t-ops2z.cc
--- a/tests/cxx/t-ops2z.cc	Mon Apr 16 21:51:39 2018 +0200
+++ b/tests/cxx/t-ops2z.cc	Wed Apr 18 23:28:26 2018 +0200
@@ -46,7 +46,7 @@
   CHECK_ALL(mpz_class,6,3,^);
   CHECK(mpz_class,unsigned long,6,2,<<);
   CHECK(mpz_class,unsigned long,6,2,>>);
-  ASSERT_ALWAYS(mpz_class(-13)<<(unsigned long)2 == (-13)*4);
+  ASSERT_ALWAYS((mpz_class(-13)<<(unsigned long)2) == (-13)*4);
   CHECK(mpz_class,unsigned long,-13,2,>>);
   ASSERT_ALWAYS(++mpz_class(7)==8);
   ASSERT_ALWAYS(++mpz_class(-8)==-7);


More information about the gmp-commit mailing list