Skip to content

Commit f75c7ad

Browse files
committed
py/mpz: In mpz_clone, remove unused check for NULL dig.
This path for src->deg==NULL is never used because mpz_clone() is always called with an argument that has a non-zero integer value, and hence has some digits allocated to it (mpz_clone() is a static function private to mpz.c all callers of this function first check if the integer value is zero and if so take a special-case path, bypassing the call to mpz_clone()). There is some unused and commented-out functions that may actually pass a zero-valued mpz to mpz_clone(), so some TODOs are added to these function in case they are needed in the future.
1 parent 77a62d8 commit f75c7ad

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

py/mpz.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -705,17 +705,14 @@ STATIC void mpz_need_dig(mpz_t *z, size_t need) {
705705
}
706706

707707
STATIC mpz_t *mpz_clone(const mpz_t *src) {
708+
assert(src->alloc != 0);
708709
mpz_t *z = m_new_obj(mpz_t);
709710
z->neg = src->neg;
710711
z->fixed_dig = 0;
711712
z->alloc = src->alloc;
712713
z->len = src->len;
713-
if (src->dig == NULL) {
714-
z->dig = NULL;
715-
} else {
716-
z->dig = m_new(mpz_dig_t, z->alloc);
717-
memcpy(z->dig, src->dig, src->alloc * sizeof(mpz_dig_t));
718-
}
714+
z->dig = m_new(mpz_dig_t, z->alloc);
715+
memcpy(z->dig, src->dig, src->alloc * sizeof(mpz_dig_t));
719716
return z;
720717
}
721718

@@ -983,6 +980,7 @@ these functions are unused
983980
/* returns abs(z)
984981
*/
985982
mpz_t *mpz_abs(const mpz_t *z) {
983+
// TODO: handle case of z->alloc=0
986984
mpz_t *z2 = mpz_clone(z);
987985
z2->neg = 0;
988986
return z2;
@@ -991,6 +989,7 @@ mpz_t *mpz_abs(const mpz_t *z) {
991989
/* returns -z
992990
*/
993991
mpz_t *mpz_neg(const mpz_t *z) {
992+
// TODO: handle case of z->alloc=0
994993
mpz_t *z2 = mpz_clone(z);
995994
z2->neg = 1 - z2->neg;
996995
return z2;
@@ -1408,6 +1407,7 @@ these functions are unused
14081407
*/
14091408
mpz_t *mpz_gcd(const mpz_t *z1, const mpz_t *z2) {
14101409
if (z1->len == 0) {
1410+
// TODO: handle case of z2->alloc=0
14111411
mpz_t *a = mpz_clone(z2);
14121412
a->neg = 0;
14131413
return a;

0 commit comments

Comments
 (0)