diff options
author | Stefan Behnel <stefan_ml@behnel.de> | 2023-04-24 19:15:44 +0200 |
---|---|---|
committer | Stefan Behnel <stefan_ml@behnel.de> | 2023-04-24 19:22:00 +0200 |
commit | 1aef71764cd50e4cd2f638eac8e69fff3ced2224 (patch) | |
tree | 38450de7fe8902ddd84b9083be3e1abf0661e97c | |
parent | 3ce72e1f0ee3c02ca1e3eb7385810ee4b5d5acee (diff) | |
download | cython-1aef71764cd50e4cd2f638eac8e69fff3ced2224.tar.gz |
Use unsigned C integer type when validating the C value of a compact PyLong.
Closes https://github.com/cython/cython/pull/5394
-rw-r--r-- | Cython/Utility/TypeConversion.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/Cython/Utility/TypeConversion.c b/Cython/Utility/TypeConversion.c index 75b95df0d..9447c71f6 100644 --- a/Cython/Utility/TypeConversion.c +++ b/Cython/Utility/TypeConversion.c @@ -142,6 +142,11 @@ static CYTHON_INLINE Py_hash_t __Pyx_PyIndex_AsHash_t(PyObject*); #define __Pyx_PyLong_DigitCount(x) (((PyLongObject*)x)->long_value.lv_tag >> 3) // (>> NON_SIZE_BITS) #define __Pyx_PyLong_SignedDigitCount(x) \ ((1 - (Py_ssize_t) (((PyLongObject*)x)->long_value.lv_tag & 3)) * (Py_ssize_t) (((PyLongObject*)x)->long_value.lv_tag >> 3)) // (>> NON_SIZE_BITS) + + // CPython 3.12 requires C99 + typedef ssize_t __Pyx_compact_pylong; + typedef size_t __Pyx_compact_upylong; + #else // Py < 3.12 #define __Pyx_PyLong_IsNeg(x) (Py_SIZE(x) < 0) #define __Pyx_PyLong_IsNonNeg(x) (Py_SIZE(x) >= 0) @@ -153,9 +158,10 @@ static CYTHON_INLINE Py_hash_t __Pyx_PyIndex_AsHash_t(PyObject*); #define __Pyx_PyLong_CompactValueUnsigned(x) ((Py_SIZE(x) == 0) ? 0 : __Pyx_PyLong_Digits(x)[0]) #define __Pyx_PyLong_DigitCount(x) __Pyx_sst_abs(Py_SIZE(x)) #define __Pyx_PyLong_SignedDigitCount(x) Py_SIZE(x) - #endif typedef sdigit __Pyx_compact_pylong; + typedef digit __Pyx_compact_upylong; + #endif #if PY_VERSION_HEX >= 0x030C00A5 #define __Pyx_PyLong_Digits(x) (((PyLongObject*)x)->long_value.ob_digit) @@ -1017,7 +1023,7 @@ static CYTHON_INLINE {{TYPE}} {{FROM_PY_FUNCTION}}(PyObject *x) { //} else if (__Pyx_PyLong_IsZero(x)) { // return ({{TYPE}}) 0; } else if (__Pyx_PyLong_IsCompact(x)) { - __PYX_VERIFY_RETURN_INT({{TYPE}}, __Pyx_compact_pylong, __Pyx_PyLong_CompactValueUnsigned(x)) + __PYX_VERIFY_RETURN_INT({{TYPE}}, __Pyx_compact_upylong, __Pyx_PyLong_CompactValueUnsigned(x)) } else { const digit* digits = __Pyx_PyLong_Digits(x); assert(__Pyx_PyLong_DigitCount(x) > 1); |