Skip to content

Commit

Permalink
Merge pull request #528 from skirpichev/misc
Browse files Browse the repository at this point in the history
Misc fixes
  • Loading branch information
casevh authored Nov 20, 2024
2 parents 17fb42d + 15d0675 commit 54c1145
Show file tree
Hide file tree
Showing 4 changed files with 528 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build_wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
path-type: inherit
if: ${{ matrix.os == 'windows-2022' }}
- name: Build wheels
uses: pypa/cibuildwheel@v2.18.0
uses: pypa/cibuildwheel@v2.21.3
env:
CIBW_PRERELEASE_PYTHONS: True
CIBW_SKIP: pp* *-win32
Expand Down
2 changes: 1 addition & 1 deletion src/gmpy2_convert.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ extern "C" {
# define _PyLong_DigitCount(obj) (((PyLongObject*)obj)->long_value.lv_tag >> 3)
#else
# define GET_OB_DIGIT(obj) obj->ob_digit
# define _PyLong_DigitCount(obj) (_PyLong_Sign(obj)<0 ? -Py_SIZE(obj):Py_SIZE(obj))
# define _PyLong_DigitCount(obj) (PyLong_IsNegative(obj) ? -Py_SIZE(obj):Py_SIZE(obj))
#endif

/* Since the macros are used in gmpy2's codebase, these functions are skipped
Expand Down
10 changes: 4 additions & 6 deletions src/gmpy2_convert_gmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
* some basic types such as C longs or doubles.
*/

#include "pythoncapi_compat.h"

/* ======================================================================== *
* Conversion between native Python objects and MPZ. *
* ======================================================================== */
Expand All @@ -42,13 +44,9 @@
static void
mpz_set_PyLong(mpz_t z, PyObject *obj)
{
int negative;
Py_ssize_t len;
Py_ssize_t len = _PyLong_DigitCount(obj);
PyLongObject *templong = (PyLongObject*)obj;

len = _PyLong_DigitCount(obj);
negative = _PyLong_Sign(obj) < 0;

switch (len) {
case 1:
mpz_set_si(z, (sdigit)GET_OB_DIGIT(templong)[0]);
Expand All @@ -62,7 +60,7 @@ mpz_set_PyLong(mpz_t z, PyObject *obj)
GET_OB_DIGIT(templong));
}

if (negative) {
if (PyLong_IsNegative(obj)) {
mpz_neg(z, z);
}
return;
Expand Down
Loading

0 comments on commit 54c1145

Please sign in to comment.