summaryrefslogtreecommitdiff
path: root/mpq
diff options
context:
space:
mode:
authorMarc Glisse <marc.glisse@inria.fr>2018-04-18 23:28:26 +0200
committerMarc Glisse <marc.glisse@inria.fr>2018-04-18 23:28:26 +0200
commit84effdd707b57bdfb62110b85c4ae4eb69cdac52 (patch)
treebfab2e7bb84bd6e405eb1e7f40e986634c7571fb /mpq
parent721245831ef3174a2965879bb3f8d69ac65692d7 (diff)
downloadgmp-84effdd707b57bdfb62110b85c4ae4eb69cdac52.tar.gz
Handle lazy 0 numerator in mpq.
As posted on the mailing-list 2 years ago...
Diffstat (limited to 'mpq')
-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
5 files changed, 9 insertions, 6 deletions
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;
}