From 1c0d4f38d4f1093df0e9460d82e4331d3d3946b6 Mon Sep 17 00:00:00 2001 From: Case Van Horsen Date: Sun, 2 Jun 2024 22:31:23 -0700 Subject: [PATCH] Improved fix for type mismatch in GET_OB_DIGIT and related macros. --- src/gmpy2_convert.h | 4 ++-- src/gmpy2_convert_gmp.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/gmpy2_convert.h b/src/gmpy2_convert.h index a12f745d..665266ee 100644 --- a/src/gmpy2_convert.h +++ b/src/gmpy2_convert.h @@ -146,8 +146,8 @@ extern "C" { #endif #if PY_VERSION_HEX >= 0x030C0000 -# define GET_OB_DIGIT(obj) obj->long_value.ob_digit -# define _PyLong_DigitCount(obj) (obj->long_value.lv_tag >> 3) +# 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 _PyLong_DigitCount(obj) (_PyLong_Sign(obj)<0 ? -Py_SIZE(obj):Py_SIZE(obj)) diff --git a/src/gmpy2_convert_gmp.c b/src/gmpy2_convert_gmp.c index fb387e67..e7575d22 100644 --- a/src/gmpy2_convert_gmp.c +++ b/src/gmpy2_convert_gmp.c @@ -46,7 +46,7 @@ mpz_set_PyLong(mpz_t z, PyObject *obj) Py_ssize_t len; PyLongObject *templong = (PyLongObject*)obj; - len = _PyLong_DigitCount(templong); + len = _PyLong_DigitCount(obj); negative = _PyLong_Sign(obj) < 0; switch (len) {