Skip to content

Commit

Permalink
Cleanup mpz_set_PyLong()
Browse files Browse the repository at this point in the history
  • Loading branch information
skirpichev committed Jun 13, 2024
1 parent c34d5f1 commit b1e684d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/gmpy2_convert.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ extern "C" {
# define GET_OB_DIGIT(obj) ((PyLongObject*)obj)->long_value.ob_digit
# define _PyLong_DigitCount(obj) (((PyLongObject*)obj)->long_value.lv_tag >> 3)
#else
# define GET_OB_DIGIT(obj) obj->ob_digit
# define GET_OB_DIGIT(obj) ((PyLongObject*)obj)->ob_digit
# define _PyLong_DigitCount(obj) (_PyLong_Sign(obj)<0 ? -Py_SIZE(obj):Py_SIZE(obj))
#endif

Expand Down
5 changes: 2 additions & 3 deletions src/gmpy2_convert_gmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,19 @@
static void
mpz_set_PyLong(mpz_t z, PyObject *obj)
{
PyLongObject *templong = (PyLongObject*)obj;
Py_ssize_t len = _PyLong_DigitCount(obj);

switch (len) {
case 1:
mpz_set_si(z, (sdigit)GET_OB_DIGIT(templong)[0]);
mpz_set_si(z, (sdigit)GET_OB_DIGIT(obj)[0]);
break;
case 0:
mpz_set_si(z, 0);
break;
default:
mpz_import(z, len, -1, sizeof(digit), 0,
sizeof(digit)*8 - PyLong_SHIFT,
GET_OB_DIGIT(templong));
GET_OB_DIGIT(obj));
}

int sign = 1;
Expand Down

0 comments on commit b1e684d

Please sign in to comment.