summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog10
-rw-r--r--mpq/clear.c3
-rw-r--r--mpq/clears.c3
-rw-r--r--mpq/init.c5
-rw-r--r--mpq/set_si.c2
-rw-r--r--mpq/set_ui.c2
-rw-r--r--tests/cxx/t-ops2z.cc2
7 files changed, 20 insertions, 7 deletions
diff --git a/ChangeLog b/ChangeLog
index e325da795..a005cb875 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2018-04-18 Marc Glisse <marc.glisse@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@gmplib.org>
* mpn/generic/sec_powm.c: Remove unused macros.
diff --git a/mpq/clear.c b/mpq/clear.c
index d4d72c45d..c5baa77f4 100644
--- a/mpq/clear.c
+++ b/mpq/clear.c
@@ -33,6 +33,7 @@ see https://www.gnu.org/licenses/. */
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 --git a/mpq/clears.c b/mpq/clears.c
index 35d98237d..1631067f6 100644
--- a/mpq/clears.c
+++ b/mpq/clears.c
@@ -40,7 +40,8 @@ mpq_clears (mpq_ptr x, ...)
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 --git a/mpq/init.c b/mpq/init.c
index f7f5be4d8..2bde2588e 100644
--- a/mpq/init.c
+++ b/mpq/init.c
@@ -33,8 +33,9 @@ see https://www.gnu.org/licenses/. */
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 --git a/mpq/set_si.c b/mpq/set_si.c
index 9a00c21ff..ea7e5c15b 100644
--- a/mpq/set_si.c
+++ b/mpq/set_si.c
@@ -55,7 +55,7 @@ mpq_set_si (mpq_t dest, signed long int num, unsigned long int den)
}
else
{
- PTR(NUM(dest))[0] = abs_num;
+ MPZ_NEWALLOC (NUM(dest), 1)[0] = abs_num;
SIZ(NUM(dest)) = num > 0 ? 1 : -1;
}
diff --git a/mpq/set_ui.c b/mpq/set_ui.c
index eee1f24e9..32c23dcdf 100644
--- a/mpq/set_ui.c
+++ b/mpq/set_ui.c
@@ -51,7 +51,7 @@ mpq_set_ui (mpq_t dest, unsigned long int num, unsigned long int den)
}
else
{
- PTR(NUM(dest))[0] = num;
+ MPZ_NEWALLOC (NUM(dest), 1)[0] = num;
SIZ(NUM(dest)) = 1;
}
diff --git a/tests/cxx/t-ops2z.cc b/tests/cxx/t-ops2z.cc
index 434968d20..6d0e4ad0f 100644
--- a/tests/cxx/t-ops2z.cc
+++ b/tests/cxx/t-ops2z.cc
@@ -46,7 +46,7 @@ void checkz (){
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);