diff --git a/docs/api.rst b/docs/api.rst index 08cf7f0..c623633 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -278,13 +278,15 @@ Python 3.14 See `PyConfig_Get() documentation `__. - Not available on the limited C API. + Not available on PyPy nor on the limited C API. .. c:function:: int PyConfig_GetInt(const char *name, int *value) See `PyConfig_GetInt() documentation `__. - Not available on the limited C API. + Available on Python 3.9 and newer. + + Not available on PyPy nor on the limited C API. .. c:function:: int PyUnstable_Object_IsUniquelyReferenced(PyObject *op) @@ -573,31 +575,31 @@ Python 3.11 See `PyCode_GetCellvars() documentation `__. - Not available on PyPy nor on limited C API 3.10 and older. + Not available on PyPy nor on limited C API. .. c:function:: PyObject* PyCode_GetCode(PyCodeObject *code) See `PyCode_GetCode() documentation `__. - Not available on PyPy nor on limited C API 3.10 and older. + Not available on PyPy nor on limited C API. .. c:function:: PyObject* PyCode_GetFreevars(PyCodeObject *code) See `PyCode_GetFreevars() documentation `__. - Not available on PyPy nor on limited C API 3.10 and older. + Not available on PyPy nor on limited C API. .. c:function:: PyObject* PyCode_GetVarnames(PyCodeObject *code) See `PyCode_GetVarnames() documentation `__. - Not available on PyPy nor on limited C API 3.10 and older. + Not available on PyPy nor on limited C API. .. c:function:: PyObject* PyFrame_GetBuiltins(PyFrameObject *frame) See `PyFrame_GetBuiltins() documentation `__. - Not available on PyPy nor on limited C API 3.10 and older. + Not available on PyPy nor on limited C API. .. c:function:: PyObject* PyFrame_GetGlobals(PyFrameObject *frame) @@ -609,63 +611,65 @@ Python 3.11 See `PyFrame_GetLasti() documentation `__. - Not available on PyPy nor on limited C API 3.10 and older. + Not available on PyPy nor on limited C API. .. c:function:: PyObject* PyFrame_GetLocals(PyFrameObject *frame) See `PyFrame_GetLocals() documentation `__. - Not available on PyPy nor on limited C API 3.10 and older. + Not available on PyPy nor on limited C API. .. c:function:: void PyThreadState_EnterTracing(PyThreadState *tstate) See `PyThreadState_EnterTracing() documentation `__. - Not available on PyPy nor on limited C API 3.10 and older. + Not available on PyPy nor on limited C API. .. c:function:: void PyThreadState_LeaveTracing(PyThreadState *tstate) See `PyThreadState_LeaveTracing() documentation `__. - Not available on PyPy nor on limited C API 3.10 and older. + Not available on PyPy nor on limited C API. .. c:function:: int PyFloat_Pack2(double x, unsigned char *p, int le) Pack a C double as the IEEE 754 binary16 half-precision format. - Availability: Python 3.6 and newer. Not available on PyPy nor on limited C - API 3.10 and older. + Availability: Python 3.6 and newer. + + Not available on PyPy nor on limited C API. .. c:function:: int PyFloat_Pack4(double x, unsigned char *p, int le) Pack a C double as the IEEE 754 binary32 single precision format. - Not available on PyPy nor on limited C API 3.10 and older. + Not available on PyPy nor on limited C API. .. c:function:: int PyFloat_Pack8(double x, unsigned char *p, int le) Pack a C double as the IEEE 754 binary64 double precision format. - Not available on PyPy nor on limited C API 3.10 and older. + Not available on PyPy nor on limited C API. .. c:function:: double PyFloat_Unpack2(const unsigned char *p, int le) Unpack the IEEE 754 binary16 half-precision format as a C double. - Availability: Python 3.6 and newer. Not available on PyPy nor on limited C - API 3.10 and older. + Availability: Python 3.6 and newer. + + Not available on PyPy nor on limited C API. .. c:function:: double PyFloat_Unpack4(const unsigned char *p, int le) Unpack the IEEE 754 binary32 single precision format as a C double. - Not available on PyPy nor on limited C API 3.10 and older. + Not available on PyPy nor on limited C API. .. c:function:: double PyFloat_Unpack8(const unsigned char *p, int le) Unpack the IEEE 754 binary64 double precision format as a C double. - Not available on PyPy nor on limited C API 3.10 and older. + Not available on PyPy nor on limited C API. .. c:function:: PyObject* PyType_GetName(PyTypeObject *type) diff --git a/pythoncapi_compat.h b/pythoncapi_compat.h index 0ab84e1..ed7d91a 100644 --- a/pythoncapi_compat.h +++ b/pythoncapi_compat.h @@ -24,14 +24,14 @@ extern "C" { #include // fclose() #include // memcpy() -// Python 3.11.0b4 added PyFrame_Back() to Python.h -#if PY_VERSION_HEX < 0x030b00B4 && !defined(PYPY_VERSION) -# include "frameobject.h" // PyFrameObject, PyFrame_GetBack() +// Python 3.11 added PyFrame_Back() to Python.h +#if PY_VERSION_HEX < 0x030B0000 && !defined(PYPY_VERSION) +# include "frameobject.h" // PyFrameObject, PyFrame_GetBack() #endif #ifndef _Py_CAST -# define _Py_CAST(type, expr) ((type)(expr)) +# define _Py_CAST(type, expr) ((type)(expr)) #endif // Static inline functions should use _Py_NULL rather than using directly NULL @@ -48,50 +48,62 @@ extern "C" { // Cast argument to PyObject* type. #ifndef _PyObject_CAST -# define _PyObject_CAST(op) _Py_CAST(PyObject*, op) +# define _PyObject_CAST(op) _Py_CAST(PyObject*, op) #endif #ifndef _PyVarObject_CAST -# define _PyVarObject_CAST(op) _Py_CAST(PyVarObject*, (op)) +# define _PyVarObject_CAST(op) _Py_CAST(PyVarObject*, (op)) #endif #ifndef Py_BUILD_ASSERT -# define Py_BUILD_ASSERT(cond) \ - do { (void)sizeof(char [1 - 2 * !(cond)]); } while(0) +# define Py_BUILD_ASSERT(cond) \ + do { (void)sizeof(char [1 - 2 * !(cond)]); } while(0) #endif + +#ifndef _Py_PACK_VERSION +# define _Py_PACK_FULL_VERSION(X, Y, Z, LEVEL, SERIAL) ( \ + (((X) & 0xff) << 24) | \ + (((Y) & 0xff) << 16) | \ + (((Z) & 0xff) << 8) | \ + (((LEVEL) & 0xf) << 4) | \ + (((SERIAL) & 0xf) << 0)) + +# define _Py_PACK_VERSION(X, Y) _Py_PACK_FULL_VERSION(X, Y, 0, 0, 0) +#endif + + #ifndef _Py_COMP_DIAG_PUSH -# if defined(__clang__) -# define _Py_COMP_DIAG_PUSH _Pragma("clang diagnostic push") -# define _Py_COMP_DIAG_IGNORE_DEPR_DECLS \ - _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"") -# define _Py_COMP_DIAG_POP _Pragma("clang diagnostic pop") -# elif defined(__GNUC__) \ - && ((__GNUC__ >= 5) || (__GNUC__ == 4) && (__GNUC_MINOR__ >= 6)) -# define _Py_COMP_DIAG_PUSH _Pragma("GCC diagnostic push") -# define _Py_COMP_DIAG_IGNORE_DEPR_DECLS \ - _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") -# define _Py_COMP_DIAG_POP _Pragma("GCC diagnostic pop") -# elif defined(_MSC_VER) -# define _Py_COMP_DIAG_PUSH __pragma(warning(push)) -# define _Py_COMP_DIAG_IGNORE_DEPR_DECLS __pragma(warning(disable: 4996)) -# define _Py_COMP_DIAG_POP __pragma(warning(pop)) -# else -# define _Py_COMP_DIAG_PUSH -# define _Py_COMP_DIAG_IGNORE_DEPR_DECLS -# define _Py_COMP_DIAG_POP -# endif -#endif - - -#if (PY_VERSION_HEX >= 0x030D0000 \ - && (!defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030d0000)) +# if defined(__clang__) +# define _Py_COMP_DIAG_PUSH _Pragma("clang diagnostic push") +# define _Py_COMP_DIAG_IGNORE_DEPR_DECLS \ + _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"") +# define _Py_COMP_DIAG_POP _Pragma("clang diagnostic pop") +# elif defined(__GNUC__) \ + && ((__GNUC__ >= 5) || (__GNUC__ == 4) && (__GNUC_MINOR__ >= 6)) +# define _Py_COMP_DIAG_PUSH _Pragma("GCC diagnostic push") +# define _Py_COMP_DIAG_IGNORE_DEPR_DECLS \ + _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") +# define _Py_COMP_DIAG_POP _Pragma("GCC diagnostic pop") +# elif defined(_MSC_VER) +# define _Py_COMP_DIAG_PUSH __pragma(warning(push)) +# define _Py_COMP_DIAG_IGNORE_DEPR_DECLS __pragma(warning(disable: 4996)) +# define _Py_COMP_DIAG_POP __pragma(warning(pop)) +# else +# define _Py_COMP_DIAG_PUSH +# define _Py_COMP_DIAG_IGNORE_DEPR_DECLS +# define _Py_COMP_DIAG_POP +# endif +#endif + +#if (PY_VERSION_HEX >= _Py_PACK_VERSION(3, 13) \ + && (!defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= _Py_PACK_VERSION(3, 13))) // "%T" format was added to Python 3.13 # define PYTHONCAPI_COMPAT_EXPECT_TYPE(ERRMSG, OBJ) \ PyErr_Format(PyExc_TypeError, ERRMSG "%T", (OBJ)) #elif !defined(Py_LIMITED_API) # define PYTHONCAPI_COMPAT_EXPECT_TYPE(ERRMSG, OBJ) \ PyErr_Format(PyExc_TypeError, ERRMSG "%s", Py_TYPE(OBJ)->tp_name) -#elif Py_LIMITED_API+0 >= 0x030b0000 +#elif Py_LIMITED_API+0 >= _Py_PACK_VERSION(3, 11) # define PYTHONCAPI_COMPAT_EXPECT_TYPE(ERRMSG, OBJ) \ do { \ PyObject *_type_name = PyType_GetName(Py_TYPE(OBJ)); \ @@ -113,8 +125,8 @@ extern "C" { #endif -// bpo-42262 added Py_NewRef() to Python 3.10.0a3 -#if PY_VERSION_HEX < 0x030A00A3 && !defined(Py_NewRef) +// bpo-42262 added Py_NewRef() to Python 3.10 +#if PY_VERSION_HEX < _Py_PACK_VERSION(3, 10) && !defined(Py_NewRef) static inline PyObject* _Py_NewRef(PyObject *obj) { Py_INCREF(obj); @@ -124,8 +136,8 @@ static inline PyObject* _Py_NewRef(PyObject *obj) #endif -// bpo-42262 added Py_XNewRef() to Python 3.10.0a3 -#if PY_VERSION_HEX < 0x030A00A3 && !defined(Py_XNewRef) +// bpo-42262 added Py_XNewRef() to Python 3.10 +#if PY_VERSION_HEX < _Py_PACK_VERSION(3, 10) && !defined(Py_XNewRef) static inline PyObject* _Py_XNewRef(PyObject *obj) { Py_XINCREF(obj); @@ -135,8 +147,8 @@ static inline PyObject* _Py_XNewRef(PyObject *obj) #endif -// bpo-39573 added Py_SET_REFCNT() to Python 3.9.0a4 -#if PY_VERSION_HEX < 0x030900A4 && !defined(Py_SET_REFCNT) +// bpo-39573 added Py_SET_REFCNT() to Python 3.9 +#if PY_VERSION_HEX < _Py_PACK_VERSION(3, 9) && !defined(Py_SET_REFCNT) static inline void _Py_SET_REFCNT(PyObject *ob, Py_ssize_t refcnt) { ob->ob_refcnt = refcnt; @@ -146,21 +158,22 @@ static inline void _Py_SET_REFCNT(PyObject *ob, Py_ssize_t refcnt) // bpo-43753 added Py_Is(), Py_IsNone(), Py_IsTrue() and Py_IsFalse() -// to Python 3.10.0b1. +// to Python 3.10. // PyPy 3.11 provides Py_Is() and Py_IsNone(). // PyPy 3.12 provides Py_IsTrue() and Py_IsFalse(). -#if PY_VERSION_HEX < 0x030A00B1 && !defined(Py_Is) +#if PY_VERSION_HEX < _Py_PACK_VERSION(3, 10) && !defined(Py_Is) # define Py_Is(x, y) ((x) == (y)) # define Py_IsNone(x) Py_Is(x, Py_None) #endif -#if (PY_VERSION_HEX < 0x030A00B1 || defined(PYPY_VERSION)) && !defined(Py_IsTrue) +#if (!defined(Py_IsTrue) \ + && (PY_VERSION_HEX < _Py_PACK_VERSION(3, 10) || defined(PYPY_VERSION))) # define Py_IsTrue(x) Py_Is(x, Py_True) # define Py_IsFalse(x) Py_Is(x, Py_False) #endif -// bpo-39573 added Py_SET_TYPE() to Python 3.9.0a4 -#if PY_VERSION_HEX < 0x030900A4 && !defined(Py_SET_TYPE) +// bpo-39573 added Py_SET_TYPE() to Python 3.9 +#if PY_VERSION_HEX < _Py_PACK_VERSION(3, 9) && !defined(Py_SET_TYPE) static inline void _Py_SET_TYPE(PyObject *ob, PyTypeObject *type) { ob->ob_type = type; @@ -169,8 +182,8 @@ static inline void _Py_SET_TYPE(PyObject *ob, PyTypeObject *type) #endif -// bpo-39573 added Py_SET_SIZE() to Python 3.9.0a4 -#if PY_VERSION_HEX < 0x030900A4 && !defined(Py_SET_SIZE) +// bpo-39573 added Py_SET_SIZE() to Python 3.9 +#if PY_VERSION_HEX < _Py_PACK_VERSION(3, 9) && !defined(Py_SET_SIZE) static inline void _Py_SET_SIZE(PyVarObject *ob, Py_ssize_t size) { ob->ob_size = size; @@ -179,11 +192,11 @@ static inline void _Py_SET_SIZE(PyVarObject *ob, Py_ssize_t size) #endif -// bpo-40421 added PyFrame_GetCode() to Python 3.9.0b1 +// bpo-40421 added PyFrame_GetCode() to Python 3.9 // PyPy added PyFrame_GetCode() to PyPy3.12 v8.0.0 -#if (PY_VERSION_HEX < 0x030900B1 \ - || (defined(PYPY_VERSION) && PY_VERSION_HEX < 0x030C0000)) \ - && !defined(Py_LIMITED_API) +#if (PY_VERSION_HEX < _Py_PACK_VERSION(3, 9) \ + || (defined(PYPY_VERSION) && PY_VERSION_HEX < _Py_PACK_VERSION(3, 12))) \ + && !defined(Py_LIMITED_API) static inline PyCodeObject* PyFrame_GetCode(PyFrameObject *frame) { assert(frame != _Py_NULL); @@ -192,7 +205,7 @@ static inline PyCodeObject* PyFrame_GetCode(PyFrameObject *frame) } #endif -#if !defined(Py_LIMITED_API) || PY_VERSION_HEX >= 0x030900B1 +#if !defined(Py_LIMITED_API) || PY_VERSION_HEX >= _Py_PACK_VERSION(3, 9) static inline PyCodeObject* _PyFrame_GetCodeBorrow(PyFrameObject *frame) { PyCodeObject *code = PyFrame_GetCode(frame); @@ -202,8 +215,9 @@ static inline PyCodeObject* _PyFrame_GetCodeBorrow(PyFrameObject *frame) #endif -// bpo-40421 added PyFrame_GetBack() to Python 3.9.0b1 -#if PY_VERSION_HEX < 0x030900B1 && !defined(PYPY_VERSION) && !defined(Py_LIMITED_API) +// bpo-40421 added PyFrame_GetBack() to Python 3.9 +#if (PY_VERSION_HEX < _Py_PACK_VERSION(3, 9) \ + && !defined(PYPY_VERSION) && !defined(Py_LIMITED_API)) static inline PyFrameObject* PyFrame_GetBack(PyFrameObject *frame) { assert(frame != _Py_NULL); @@ -221,9 +235,9 @@ static inline PyFrameObject* _PyFrame_GetBackBorrow(PyFrameObject *frame) #endif -// bpo-40421 added PyFrame_GetLocals() to Python 3.11.0a7 -#if (PY_VERSION_HEX < 0x030B00A7 \ - && !defined(PYPY_VERSION) && !defined(Py_LIMITED_API)) +// bpo-40421 added PyFrame_GetLocals() to Python 3.11 +#if (PY_VERSION_HEX < _Py_PACK_VERSION(3, 11) \ + && !defined(PYPY_VERSION) && !defined(Py_LIMITED_API)) static inline PyObject* PyFrame_GetLocals(PyFrameObject *frame) { if (PyFrame_FastToLocalsWithError(frame) < 0) { @@ -234,9 +248,9 @@ static inline PyObject* PyFrame_GetLocals(PyFrameObject *frame) #endif -// bpo-40421 added PyFrame_GetGlobals() to Python 3.11.0a7 -#if (PY_VERSION_HEX < 0x030B00A7 \ - && !defined(PYPY_VERSION) && !defined(Py_LIMITED_API)) +// bpo-40421 added PyFrame_GetGlobals() to Python 3.11 +#if (PY_VERSION_HEX < _Py_PACK_VERSION(3, 11) \ + && !defined(PYPY_VERSION) && !defined(Py_LIMITED_API)) static inline PyObject* PyFrame_GetGlobals(PyFrameObject *frame) { return Py_NewRef(frame->f_globals); @@ -244,9 +258,9 @@ static inline PyObject* PyFrame_GetGlobals(PyFrameObject *frame) #endif -// bpo-40421 added PyFrame_GetBuiltins() to Python 3.11.0a7 -#if (PY_VERSION_HEX < 0x030B00A7 \ - && !defined(PYPY_VERSION) && !defined(Py_LIMITED_API)) +// bpo-40421 added PyFrame_GetBuiltins() to Python 3.11 +#if (PY_VERSION_HEX < _Py_PACK_VERSION(3, 11) \ + && !defined(PYPY_VERSION) && !defined(Py_LIMITED_API)) static inline PyObject* PyFrame_GetBuiltins(PyFrameObject *frame) { return Py_NewRef(frame->f_builtins); @@ -254,13 +268,13 @@ static inline PyObject* PyFrame_GetBuiltins(PyFrameObject *frame) #endif -// bpo-40421 added PyFrame_GetLasti() to Python 3.11.0b1 -#if (PY_VERSION_HEX < 0x030B00B1 \ - && !defined(PYPY_VERSION) && !defined(Py_LIMITED_API)) +// bpo-40421 added PyFrame_GetLasti() to Python 3.11 +#if (PY_VERSION_HEX < _Py_PACK_VERSION(3, 11) \ + && !defined(PYPY_VERSION) && !defined(Py_LIMITED_API)) static inline int PyFrame_GetLasti(PyFrameObject *frame) { -#if PY_VERSION_HEX >= 0x030A00A7 - // bpo-27129: Since Python 3.10.0a7, f_lasti is an instruction offset, +#if PY_VERSION_HEX >= _Py_PACK_VERSION(3, 10) + // bpo-27129: Since Python 3.10, f_lasti is an instruction offset, // not a bytes offset anymore. Python uses 16-bit "wordcode" (2 bytes) // instructions. if (frame->f_lasti < 0) { @@ -274,8 +288,9 @@ static inline int PyFrame_GetLasti(PyFrameObject *frame) #endif -// gh-91248 added PyFrame_GetVar() to Python 3.12.0a2 -#if PY_VERSION_HEX < 0x030C00A2 && !defined(PYPY_VERSION) && !defined(Py_LIMITED_API) +// gh-91248 added PyFrame_GetVar() to Python 3.12 +#if (PY_VERSION_HEX < _Py_PACK_VERSION(3, 12) \ + && !defined(PYPY_VERSION) && !defined(Py_LIMITED_API)) static inline PyObject* PyFrame_GetVar(PyFrameObject *frame, PyObject *name) { PyObject *locals, *value; @@ -299,8 +314,9 @@ static inline PyObject* PyFrame_GetVar(PyFrameObject *frame, PyObject *name) #endif -// gh-91248 added PyFrame_GetVarString() to Python 3.12.0a2 -#if PY_VERSION_HEX < 0x030C00A2 && !defined(PYPY_VERSION) && !defined(Py_LIMITED_API) +// gh-91248 added PyFrame_GetVarString() to Python 3.12 +#if (PY_VERSION_HEX < _Py_PACK_VERSION(3, 12) \ + && !defined(PYPY_VERSION) && !defined(Py_LIMITED_API)) static inline PyObject* PyFrame_GetVarString(PyFrameObject *frame, const char *name) { @@ -318,9 +334,9 @@ PyFrame_GetVarString(PyFrameObject *frame, const char *name) // Added to Python 3.9 and limited C API 3.9. // Added to PyPy 3.11. -#if ((PY_VERSION_HEX < 0x030900A5 \ - || (defined(PYPY_VERSION) && PY_VERSION_HEX < 0x030B0000)) \ - && !defined(Py_LIMITED_API)) +#if ((PY_VERSION_HEX < _Py_PACK_VERSION(3, 9) \ + || (defined(PYPY_VERSION) && PY_VERSION_HEX < _Py_PACK_VERSION(3, 11))) \ + && !defined(Py_LIMITED_API)) static inline PyInterpreterState * PyThreadState_GetInterpreter(PyThreadState *tstate) { @@ -330,9 +346,9 @@ PyThreadState_GetInterpreter(PyThreadState *tstate) #endif -// bpo-40429 added PyThreadState_GetFrame() to Python 3.9.0b1 -#if (PY_VERSION_HEX < 0x030900B1 \ - && !defined(PYPY_VERSION) && !defined(Py_LIMITED_API)) +// bpo-40429 added PyThreadState_GetFrame() to Python 3.9 +#if (PY_VERSION_HEX < _Py_PACK_VERSION(3, 9) \ + && !defined(PYPY_VERSION) && !defined(Py_LIMITED_API)) static inline PyFrameObject* PyThreadState_GetFrame(PyThreadState *tstate) { assert(tstate != _Py_NULL); @@ -340,8 +356,8 @@ static inline PyFrameObject* PyThreadState_GetFrame(PyThreadState *tstate) } #endif -#if ((!defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03090000) \ - && !defined(PYPY_VERSION)) +#if ((!defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= _Py_PACK_VERSION(3, 9)) \ + && !defined(PYPY_VERSION)) static inline PyFrameObject* _PyThreadState_GetFrameBorrow(PyThreadState *tstate) { @@ -355,9 +371,9 @@ _PyThreadState_GetFrameBorrow(PyThreadState *tstate) // Added to Python 3.9 and limited C API 3.9. On Windows, it's not available // before stable ABI 3.10. // Added to PyPy3.12 v8.0.0. -#if ((PY_VERSION_HEX < 0x030900A5 \ - || (defined(PYPY_VERSION) && PY_VERSION_HEX < 0x030C0000)) \ - && !defined(Py_LIMITED_API)) +#if ((PY_VERSION_HEX < _Py_PACK_VERSION(3, 9) \ + || (defined(PYPY_VERSION) && PY_VERSION_HEX < _Py_PACK_VERSION(3, 12))) \ + && !defined(Py_LIMITED_API)) static inline PyInterpreterState* PyInterpreterState_Get(void) { PyThreadState *tstate; @@ -376,9 +392,10 @@ static inline PyInterpreterState* PyInterpreterState_Get(void) #endif -// bpo-39947 added PyThreadState_GetID() to Python 3.9.0a6 -#if (0x030700A1 <= PY_VERSION_HEX && PY_VERSION_HEX < 0x030900A6 \ - && !defined(PYPY_VERSION) && !defined(Py_LIMITED_API)) +// bpo-39947 added PyThreadState_GetID() to Python 3.9 +#if (_Py_PACK_VERSION(3, 7) <= PY_VERSION_HEX \ + && PY_VERSION_HEX < _Py_PACK_VERSION(3, 9) \ + && !defined(PYPY_VERSION) && !defined(Py_LIMITED_API)) static inline uint64_t PyThreadState_GetID(PyThreadState *tstate) { assert(tstate != _Py_NULL); @@ -386,13 +403,13 @@ static inline uint64_t PyThreadState_GetID(PyThreadState *tstate) } #endif -// bpo-43760 added PyThreadState_EnterTracing() to Python 3.11.0a2 -#if (PY_VERSION_HEX < 0x030B00A2 \ - && !defined(PYPY_VERSION) && !defined(Py_LIMITED_API)) +// bpo-43760 added PyThreadState_EnterTracing() to Python 3.11 +#if (PY_VERSION_HEX < _Py_PACK_VERSION(3, 11) \ + && !defined(PYPY_VERSION) && !defined(Py_LIMITED_API)) static inline void PyThreadState_EnterTracing(PyThreadState *tstate) { tstate->tracing++; -#if PY_VERSION_HEX >= 0x030A00A1 +#if PY_VERSION_HEX >= _Py_PACK_VERSION(3, 10) tstate->cframe->use_tracing = 0; #else tstate->use_tracing = 0; @@ -400,15 +417,15 @@ static inline void PyThreadState_EnterTracing(PyThreadState *tstate) } #endif -// bpo-43760 added PyThreadState_LeaveTracing() to Python 3.11.0a2 -#if (PY_VERSION_HEX < 0x030B00A2 \ - && !defined(PYPY_VERSION) && !defined(Py_LIMITED_API)) +// bpo-43760 added PyThreadState_LeaveTracing() to Python 3.11 +#if (PY_VERSION_HEX < _Py_PACK_VERSION(3, 11) \ + && !defined(PYPY_VERSION) && !defined(Py_LIMITED_API)) static inline void PyThreadState_LeaveTracing(PyThreadState *tstate) { int use_tracing = (tstate->c_tracefunc != _Py_NULL || tstate->c_profilefunc != _Py_NULL); tstate->tracing--; -#if PY_VERSION_HEX >= 0x030A00A1 +#if PY_VERSION_HEX >= _Py_PACK_VERSION(3, 10) tstate->cframe->use_tracing = use_tracing; #else tstate->use_tracing = use_tracing; @@ -417,11 +434,11 @@ static inline void PyThreadState_LeaveTracing(PyThreadState *tstate) #endif -// bpo-37194 added PyObject_CallNoArgs() to Python 3.9.0a1 +// bpo-37194 added PyObject_CallNoArgs() to Python 3.9 // PyObject_CallNoArgs() added to PyPy 3.9.16-v7.3.11 #if (!defined(PyObject_CallNoArgs) \ - && (PY_VERSION_HEX < 0x030900A1 \ - || (defined(Py_LIMITED_API) && Py_LIMITED_API+0 < 0x03090000))) + && (PY_VERSION_HEX < _Py_PACK_VERSION(3, 9) \ + || (defined(Py_LIMITED_API) && Py_LIMITED_API+0 < _Py_PACK_VERSION(3, 9)))) static inline PyObject* PyObject_CallNoArgs(PyObject *func) { return PyObject_CallFunctionObjArgs(func, NULL); @@ -430,9 +447,9 @@ static inline PyObject* PyObject_CallNoArgs(PyObject *func) // bpo-39245 made PyObject_CallOneArg() public (previously called -// _PyObject_CallOneArg) in Python 3.9.0a4 +// _PyObject_CallOneArg) in Python 3.9 // PyObject_CallOneArg() added to PyPy 3.9.16-v7.3.11 -#if !defined(PyObject_CallOneArg) && PY_VERSION_HEX < 0x030900A4 +#if !defined(PyObject_CallOneArg) && PY_VERSION_HEX < _Py_PACK_VERSION(3, 9) static inline PyObject* PyObject_CallOneArg(PyObject *func, PyObject *arg) { return PyObject_CallFunctionObjArgs(func, arg, NULL); @@ -440,11 +457,14 @@ static inline PyObject* PyObject_CallOneArg(PyObject *func, PyObject *arg) #endif -// bpo-1635741 added PyModule_AddObjectRef() to Python 3.10.0a3. +// bpo-1635741 added PyModule_AddObjectRef() to Python 3.10. // The function was aded to the limited C API 3.10. -#if (PY_VERSION_HEX < 0x030A00A3 \ - || (defined(Py_LIMITED_API) && Py_LIMITED_API+0 < 0x030a0000) \ - && !(0x030A0000 <= PY_VERSION_HEX && PY_VERSION_HEX < 0x030B0000)) +// In Python 3.10, the function is available in any limited C API version. +#if (PY_VERSION_HEX < _Py_PACK_VERSION(3, 10) \ + || (defined(Py_LIMITED_API) \ + && Py_LIMITED_API+0 < _Py_PACK_VERSION(3, 10) \ + && !(_Py_PACK_VERSION(3, 10) <= PY_VERSION_HEX \ + && PY_VERSION_HEX < _Py_PACK_VERSION(3, 11)))) static inline int PyModule_AddObjectRef(PyObject *module, const char *name, PyObject *value) { @@ -468,10 +488,10 @@ PyModule_AddObjectRef(PyObject *module, const char *name, PyObject *value) #endif -// bpo-40024 added PyModule_AddType() to Python 3.9.0a5 +// bpo-40024 added PyModule_AddType() to Python 3.9 // On Windows, PyModule_AddType() was added to limited C API 3.9. -#if (PY_VERSION_HEX < 0x030900A5 \ - || (defined(Py_LIMITED_API) && Py_LIMITED_API+0 < 0x03090000)) +#if (PY_VERSION_HEX < _Py_PACK_VERSION(3, 9) \ + || (defined(Py_LIMITED_API) && Py_LIMITED_API+0 < _Py_PACK_VERSION(3, 9))) static inline int PyModule_AddType(PyObject *module, PyTypeObject *type) { #ifndef Py_LIMITED_API @@ -517,20 +537,22 @@ static inline int PyModule_AddType(PyObject *module, PyTypeObject *type) #endif -// bpo-40241 added PyObject_GC_IsTracked() to Python 3.9.0a6. -// bpo-4688 added _PyObject_GC_IS_TRACKED() to Python 2.7.0a2. +// bpo-40241 added PyObject_GC_IsTracked() to Python 3.9. +// bpo-4688 added _PyObject_GC_IS_TRACKED() to Python 2.7. // On Windows, PyObject_GC_IsTracked() was only added to limited C API 3.10. -#if PY_VERSION_HEX < 0x030900A6 && !defined(PYPY_VERSION) && !defined(Py_LIMITED_API) +#if (PY_VERSION_HEX < _Py_PACK_VERSION(3, 9) \ + && !defined(PYPY_VERSION) && !defined(Py_LIMITED_API)) static inline int PyObject_GC_IsTracked(PyObject* obj) { return (PyObject_IS_GC(obj) && _PyObject_GC_IS_TRACKED(obj)); } #endif -// bpo-40241 added PyObject_GC_IsFinalized() to Python 3.9.0a6. +// bpo-40241 added PyObject_GC_IsFinalized() to Python 3.9. // bpo-18112 added _PyGCHead_FINALIZED() to Python 3.4.0 final. // On Windows, PyObject_GC_IsFinalized() was only added to limited C API 3.10. -#if PY_VERSION_HEX < 0x030900A6 && !defined(PYPY_VERSION) && !defined(Py_LIMITED_API) +#if (PY_VERSION_HEX < _Py_PACK_VERSION(3, 9) \ + && !defined(PYPY_VERSION) && !defined(Py_LIMITED_API)) static inline int PyObject_GC_IsFinalized(PyObject *obj) { PyGC_Head *gc = _Py_CAST(PyGC_Head*, obj) - 1; @@ -539,8 +561,8 @@ static inline int PyObject_GC_IsFinalized(PyObject *obj) #endif -// bpo-39573 added Py_IS_TYPE() to Python 3.9.0a4 -#if PY_VERSION_HEX < 0x030900A4 && !defined(Py_IS_TYPE) +// bpo-39573 added Py_IS_TYPE() to Python 3.9 +#if PY_VERSION_HEX < _Py_PACK_VERSION(3, 9) && !defined(Py_IS_TYPE) static inline int _Py_IS_TYPE(PyObject *ob, PyTypeObject *type) { return Py_TYPE(ob) == type; } @@ -548,11 +570,12 @@ static inline int _Py_IS_TYPE(PyObject *ob, PyTypeObject *type) { #endif -// bpo-46906 added PyFloat_Pack2() and PyFloat_Unpack2() to Python 3.11a7. -// bpo-11734 added _PyFloat_Pack2() and _PyFloat_Unpack2() to Python 3.6.0b1. -// Python 3.11a2 moved _PyFloat_Pack2() and _PyFloat_Unpack2() to the internal -// C API: Python 3.11a2-3.11a6 versions are not supported. -#if PY_VERSION_HEX <= 0x030B00A1 && !defined(PYPY_VERSION) && !defined(Py_LIMITED_API) +// bpo-46906 added PyFloat_Pack2() and PyFloat_Unpack2() to Python 3.11. +// bpo-11734 added _PyFloat_Pack2() and _PyFloat_Unpack2() to Python 3.6. +// Python 3.11 moved _PyFloat_Pack2() and _PyFloat_Unpack2() to the internal +// C API. +#if (PY_VERSION_HEX <= _Py_PACK_VERSION(3, 11) \ + && !defined(PYPY_VERSION) && !defined(Py_LIMITED_API)) static inline int PyFloat_Pack2(double x, char *p, int le) { return _PyFloat_Pack2(x, (unsigned char*)p, le); } @@ -562,11 +585,11 @@ static inline double PyFloat_Unpack2(const char *p, int le) // bpo-46906 added PyFloat_Pack4(), PyFloat_Pack8(), PyFloat_Unpack4() and -// PyFloat_Unpack8() to Python 3.11a7. -// Python 3.11a2 moved _PyFloat_Pack4(), _PyFloat_Pack8(), _PyFloat_Unpack4() -// and _PyFloat_Unpack8() to the internal C API: Python 3.11a2-3.11a6 versions -// are not supported. -#if PY_VERSION_HEX <= 0x030B00A1 && !defined(PYPY_VERSION) && !defined(Py_LIMITED_API) +// PyFloat_Unpack8() to Python 3.11. +// Python 3.11 moved _PyFloat_Pack4(), _PyFloat_Pack8(), _PyFloat_Unpack4() +// and _PyFloat_Unpack8() to the internal C API. +#if (PY_VERSION_HEX <= _Py_PACK_VERSION(3, 11) \ + && !defined(PYPY_VERSION) && !defined(Py_LIMITED_API)) static inline int PyFloat_Pack4(double x, char *p, int le) { return _PyFloat_Pack4(x, (unsigned char*)p, le); } @@ -581,8 +604,9 @@ static inline double PyFloat_Unpack8(const char *p, int le) #endif -// gh-92154 added PyCode_GetCode() to Python 3.11.0b1 -#if PY_VERSION_HEX < 0x030B00B1 && !defined(PYPY_VERSION) && !defined(Py_LIMITED_API) +// gh-92154 added PyCode_GetCode() to Python 3.11 +#if (PY_VERSION_HEX < _Py_PACK_VERSION(3, 11) \ + && !defined(PYPY_VERSION) && !defined(Py_LIMITED_API)) static inline PyObject* PyCode_GetCode(PyCodeObject *code) { return Py_NewRef(code->co_code); @@ -591,7 +615,8 @@ static inline PyObject* PyCode_GetCode(PyCodeObject *code) // gh-95008 added PyCode_GetVarnames() to Python 3.11.0rc1 -#if PY_VERSION_HEX < 0x030B00C1 && !defined(PYPY_VERSION) && !defined(Py_LIMITED_API) +#if (PY_VERSION_HEX < _Py_PACK_VERSION(3, 11) \ + && !defined(PYPY_VERSION) && !defined(Py_LIMITED_API)) static inline PyObject* PyCode_GetVarnames(PyCodeObject *code) { return Py_NewRef(code->co_varnames); @@ -599,7 +624,8 @@ static inline PyObject* PyCode_GetVarnames(PyCodeObject *code) #endif // gh-95008 added PyCode_GetFreevars() to Python 3.11.0rc1 -#if PY_VERSION_HEX < 0x030B00C1 && !defined(PYPY_VERSION) && !defined(Py_LIMITED_API) +#if (PY_VERSION_HEX < _Py_PACK_VERSION(3, 11) \ + && !defined(PYPY_VERSION) && !defined(Py_LIMITED_API)) static inline PyObject* PyCode_GetFreevars(PyCodeObject *code) { return Py_NewRef(code->co_freevars); @@ -607,7 +633,8 @@ static inline PyObject* PyCode_GetFreevars(PyCodeObject *code) #endif // gh-95008 added PyCode_GetCellvars() to Python 3.11.0rc1 -#if PY_VERSION_HEX < 0x030B00C1 && !defined(PYPY_VERSION) && !defined(Py_LIMITED_API) +#if (PY_VERSION_HEX < _Py_PACK_VERSION(3, 11) \ + && !defined(PYPY_VERSION) && !defined(Py_LIMITED_API)) static inline PyObject* PyCode_GetCellvars(PyCodeObject *code) { return Py_NewRef(code->co_cellvars); @@ -615,7 +642,7 @@ static inline PyObject* PyCode_GetCellvars(PyCodeObject *code) #endif -// Py_UNUSED() was added to Python 3.4.0b2. +// Py_UNUSED() was added to Python 3.4. #ifndef Py_UNUSED # if defined(__GNUC__) || defined(__clang__) # define Py_UNUSED(name) _unused_ ## name __attribute__((unused)) @@ -625,9 +652,9 @@ static inline PyObject* PyCode_GetCellvars(PyCodeObject *code) #endif -// PyImport_AddModuleRef() was added to Python 3.13.0a1 and limited C API 3.13 -#if (PY_VERSION_HEX < 0x030D00A0 \ - || (defined(Py_LIMITED_API) && Py_LIMITED_API+0 < 0x030d0000)) +// PyImport_AddModuleRef() was added to Python 3.13 and limited C API 3.13 +#if (PY_VERSION_HEX < _Py_PACK_VERSION(3, 13) \ + || (defined(Py_LIMITED_API) && Py_LIMITED_API+0 < _Py_PACK_VERSION(3, 13))) static inline PyObject* PyImport_AddModuleRef(const char *name) { return Py_XNewRef(PyImport_AddModule(name)); @@ -635,11 +662,11 @@ static inline PyObject* PyImport_AddModuleRef(const char *name) #endif -// gh-105927 added PyWeakref_GetRef() to Python 3.13.0a1 -#if (PY_VERSION_HEX < 0x030D0000 \ - || (defined(Py_LIMITED_API) && Py_LIMITED_API+0 < 0x030D0000)) +// gh-105927 added PyWeakref_GetRef() to Python 3.13 +#if (PY_VERSION_HEX < _Py_PACK_VERSION(3, 13) \ + || (defined(Py_LIMITED_API) && Py_LIMITED_API+0 < _Py_PACK_VERSION(3, 13))) -#if defined(Py_LIMITED_API) && Py_LIMITED_API+0 < 0x030D0000 && PY_VERSION_HEX >= 0x030F0000 +#if defined(Py_LIMITED_API) && Py_LIMITED_API+0 < _Py_PACK_VERSION(3, 13) && PY_VERSION_HEX >= _Py_PACK_VERSION(3, 15) // Function removed from Python 3.15 C API, but it remains available // in the stable ABI PyAPI_FUNC(PyObject *) PyWeakref_GetObject(PyObject *ref); @@ -673,14 +700,14 @@ _Py_COMP_DIAG_POP #endif -// bpo-36974 added PY_VECTORCALL_ARGUMENTS_OFFSET to Python 3.8b1 +// bpo-36974 added PY_VECTORCALL_ARGUMENTS_OFFSET to Python 3.8 #ifndef PY_VECTORCALL_ARGUMENTS_OFFSET -# define PY_VECTORCALL_ARGUMENTS_OFFSET (_Py_CAST(size_t, 1) << (8 * sizeof(size_t) - 1)) +# define PY_VECTORCALL_ARGUMENTS_OFFSET (_Py_CAST(size_t, 1) << (8 * sizeof(size_t) - 1)) #endif -// bpo-36974 added PyVectorcall_NARGS() to Python 3.8b1 -#if (PY_VERSION_HEX < 0x030800B1 \ - || (defined(Py_LIMITED_API) && PY_VERSION_HEX < 0x030C0000)) +// bpo-36974 added PyVectorcall_NARGS() to Python 3.8 +#if (PY_VERSION_HEX < _Py_PACK_VERSION(3, 8) \ + || (defined(Py_LIMITED_API) && PY_VERSION_HEX < _Py_PACK_VERSION(3, 12))) static inline Py_ssize_t PyVectorcall_NARGS(size_t n) { return n & ~PY_VECTORCALL_ARGUMENTS_OFFSET; @@ -688,15 +715,16 @@ static inline Py_ssize_t PyVectorcall_NARGS(size_t n) #endif -// gh-105922 added PyObject_Vectorcall() to Python 3.9.0a4 -#if (PY_VERSION_HEX < 0x030900A4 \ - || (defined(Py_LIMITED_API) && Py_LIMITED_API+0 < 0x030C0000)) +// gh-105922 added PyObject_Vectorcall() to Python 3.9 +#if (PY_VERSION_HEX < _Py_PACK_VERSION(3, 9) \ + || (defined(Py_LIMITED_API) && Py_LIMITED_API+0 < _Py_PACK_VERSION(3, 12))) static inline PyObject* PyObject_Vectorcall(PyObject *callable, PyObject *const *args, size_t nargsf, PyObject *kwnames) { -#if PY_VERSION_HEX >= 0x030800B1 && !defined(PYPY_VERSION) && !defined(Py_LIMITED_API) - // bpo-36974 added _PyObject_Vectorcall() to Python 3.8.0b1 +#if (PY_VERSION_HEX >= _Py_PACK_VERSION(3, 8) \ + && !defined(PYPY_VERSION) && !defined(Py_LIMITED_API)) + // bpo-36974 added _PyObject_Vectorcall() to Python 3.8 return _PyObject_Vectorcall(callable, args, nargsf, kwnames); #else PyObject *posargs = NULL, *kwargs = NULL; @@ -782,14 +810,15 @@ PyObject_Vectorcall(PyObject *callable, PyObject *const *args, // gh-106521 added PyObject_GetOptionalAttr() and -// PyObject_GetOptionalAttrString() to Python 3.13.0a1 -#if (PY_VERSION_HEX < 0x030D00A1 \ - || (defined(Py_LIMITED_API) && Py_LIMITED_API+0 < 0x030d0000)) +// PyObject_GetOptionalAttrString() to Python 3.13 +#if (PY_VERSION_HEX < _Py_PACK_VERSION(3, 13) \ + || (defined(Py_LIMITED_API) && Py_LIMITED_API+0 < _Py_PACK_VERSION(3, 13))) static inline int PyObject_GetOptionalAttr(PyObject *obj, PyObject *attr_name, PyObject **result) { - // bpo-32571 added _PyObject_LookupAttr() to Python 3.7.0b1 -#if PY_VERSION_HEX >= 0x030700B1 && !defined(PYPY_VERSION) && !defined(Py_LIMITED_API) + // bpo-32571 added _PyObject_LookupAttr() to Python 3.7 +#if (PY_VERSION_HEX >= _Py_PACK_VERSION(3, 7) \ + && !defined(PYPY_VERSION) && !defined(Py_LIMITED_API)) return _PyObject_LookupAttr(obj, attr_name, result); #else *result = PyObject_GetAttr(obj, attr_name); @@ -824,9 +853,9 @@ PyObject_GetOptionalAttrString(PyObject *obj, const char *attr_name, PyObject ** // gh-106307 added PyObject_GetOptionalAttr() and -// PyMapping_GetOptionalItemString() to Python 3.13.0a1 -#if (PY_VERSION_HEX < 0x030D00A1 \ - || (defined(Py_LIMITED_API) && Py_LIMITED_API+0 < 0x030d0000)) +// PyMapping_GetOptionalItemString() to Python 3.13 +#if (PY_VERSION_HEX < _Py_PACK_VERSION(3, 13) \ + || (defined(Py_LIMITED_API) && Py_LIMITED_API+0 < _Py_PACK_VERSION(3, 13))) static inline int PyMapping_GetOptionalItem(PyObject *obj, PyObject *key, PyObject **result) { @@ -857,8 +886,8 @@ PyMapping_GetOptionalItemString(PyObject *obj, const char *key, PyObject **resul #endif // gh-108511 added PyMapping_HasKeyWithError() and -// PyMapping_HasKeyStringWithError() to Python 3.13.0a1 -#if PY_VERSION_HEX < 0x030D00A1 +// PyMapping_HasKeyStringWithError() to Python 3.13 +#if PY_VERSION_HEX < _Py_PACK_VERSION(3, 13) static inline int PyMapping_HasKeyWithError(PyObject *obj, PyObject *key) { @@ -880,9 +909,9 @@ PyMapping_HasKeyStringWithError(PyObject *obj, const char *key) // gh-108511 added PyObject_HasAttrWithError() and -// PyObject_HasAttrStringWithError() to Python 3.13.0a1 -#if (PY_VERSION_HEX < 0x030D00A1 \ - || (defined(Py_LIMITED_API) && Py_LIMITED_API+0 < 0x030d0000)) +// PyObject_HasAttrStringWithError() to Python 3.13 +#if (PY_VERSION_HEX < _Py_PACK_VERSION(3, 13) \ + || (defined(Py_LIMITED_API) && Py_LIMITED_API+0 < _Py_PACK_VERSION(3, 13))) static inline int PyObject_HasAttrWithError(PyObject *obj, PyObject *attr) { @@ -904,9 +933,9 @@ PyObject_HasAttrStringWithError(PyObject *obj, const char *attr) // gh-106004 added PyDict_GetItemRef() and PyDict_GetItemStringRef() -// to Python 3.13.0a1 -#if (PY_VERSION_HEX < 0x030D00A1 \ - || (defined(Py_LIMITED_API) && Py_LIMITED_API+0 < 0x030D0000)) +// to Python 3.13 +#if (PY_VERSION_HEX < _Py_PACK_VERSION(3, 13) \ + || (defined(Py_LIMITED_API) && Py_LIMITED_API+0 < _Py_PACK_VERSION(3, 13))) static inline int PyDict_GetItemRef(PyObject *mp, PyObject *key, PyObject **result) { @@ -939,9 +968,9 @@ PyDict_GetItemStringRef(PyObject *mp, const char *key, PyObject **result) #endif -// gh-106307 added PyModule_Add() to Python 3.13.0a1 -#if (PY_VERSION_HEX < 0x030D00A1 \ - || (defined(Py_LIMITED_API) && Py_LIMITED_API+0 < 0x030d0000)) +// gh-106307 added PyModule_Add() to Python 3.13 +#if (PY_VERSION_HEX < _Py_PACK_VERSION(3, 13) \ + || (defined(Py_LIMITED_API) && Py_LIMITED_API+0 < _Py_PACK_VERSION(3, 13))) static inline int PyModule_Add(PyObject *mod, const char *name, PyObject *value) { @@ -952,16 +981,16 @@ PyModule_Add(PyObject *mod, const char *name, PyObject *value) #endif -// gh-108014 added Py_IsFinalizing() to Python 3.13.0a1 (limited C API). +// gh-108014 added Py_IsFinalizing() to Python 3.13 (limited C API). // bpo-1856 added _Py_Finalizing to Python 3.2.1b1. // _Py_IsFinalizing() was added to PyPy 7.3.0. -#if ((PY_VERSION_HEX < 0x030D00A1) \ - && (!defined(PYPY_VERSION_NUM) || PYPY_VERSION_NUM >= 0x7030000) \ - && !defined(Py_LIMITED_API)) +#if ((PY_VERSION_HEX < _Py_PACK_VERSION(3, 13)) \ + && (!defined(PYPY_VERSION_NUM) || PYPY_VERSION_NUM >= 0x7030000) \ + && !defined(Py_LIMITED_API)) static inline int Py_IsFinalizing(void) { -#if PY_VERSION_HEX >= 0x030700A1 - // _Py_IsFinalizing() was added to Python 3.7.0a1. +#if PY_VERSION_HEX >= _Py_PACK_VERSION(3, 7) + // _Py_IsFinalizing() was added to Python 3.7. return _Py_IsFinalizing(); #else return (_Py_Finalizing != NULL); @@ -970,8 +999,8 @@ static inline int Py_IsFinalizing(void) #endif -// gh-108323 added PyDict_ContainsString() to Python 3.13.0a1 -#if PY_VERSION_HEX < 0x030D00A1 +// gh-108323 added PyDict_ContainsString() to Python 3.13 +#if PY_VERSION_HEX < _Py_PACK_VERSION(3, 13) static inline int PyDict_ContainsString(PyObject *op, const char *key) { PyObject *key_obj = PyUnicode_FromString(key); @@ -985,9 +1014,9 @@ static inline int PyDict_ContainsString(PyObject *op, const char *key) #endif -// gh-108445 added PyLong_AsInt() to Python 3.13.0a1 -#if (PY_VERSION_HEX < 0x030D00A1 \ - || (defined(Py_LIMITED_API) && Py_LIMITED_API+0 < 0x030d0000)) +// gh-108445 added PyLong_AsInt() to Python 3.13 +#if (PY_VERSION_HEX < _Py_PACK_VERSION(3, 13) \ + || (defined(Py_LIMITED_API) && Py_LIMITED_API+0 < _Py_PACK_VERSION(3, 13))) static inline int PyLong_AsInt(PyObject *obj) { #if defined(PYPY_VERSION) || defined(Py_LIMITED_API) @@ -1008,8 +1037,8 @@ static inline int PyLong_AsInt(PyObject *obj) #endif -// gh-107073 added PyObject_VisitManagedDict() to Python 3.13.0a1 -#if PY_VERSION_HEX < 0x030D00A1 && !defined(Py_LIMITED_API) +// gh-107073 added PyObject_VisitManagedDict() to Python 3.13 +#if PY_VERSION_HEX < _Py_PACK_VERSION(3, 13) && !defined(Py_LIMITED_API) static inline int PyObject_VisitManagedDict(PyObject *obj, visitproc visit, void *arg) { @@ -1032,9 +1061,9 @@ PyObject_ClearManagedDict(PyObject *obj) } #endif -// gh-108867 added PyThreadState_GetUnchecked() to Python 3.13.0a1 +// gh-108867 added PyThreadState_GetUnchecked() to Python 3.13 // Python 3.5.2 added _PyThreadState_UncheckedGet(). -#if PY_VERSION_HEX < 0x030D00A1 && !defined(Py_LIMITED_API) +#if PY_VERSION_HEX < _Py_PACK_VERSION(3, 13) && !defined(Py_LIMITED_API) static inline PyThreadState* PyThreadState_GetUnchecked(void) { @@ -1043,14 +1072,14 @@ PyThreadState_GetUnchecked(void) #endif // gh-110289 added PyUnicode_EqualToUTF8() and PyUnicode_EqualToUTF8AndSize() -// to Python 3.13.0a1 -#if (PY_VERSION_HEX < 0x030D00A1 \ - || (defined(Py_LIMITED_API) && Py_LIMITED_API+0 < 0x030D0000)) +// to Python 3.13 +#if (PY_VERSION_HEX < _Py_PACK_VERSION(3, 13) \ + || (defined(Py_LIMITED_API) && Py_LIMITED_API+0 < _Py_PACK_VERSION(3, 13))) static inline int PyUnicode_EqualToUTF8AndSize(PyObject *unicode, const char *str, Py_ssize_t str_len) { Py_ssize_t len; -#if defined(Py_LIMITED_API) && Py_LIMITED_API+0 < 0x030a0000 +#if defined(Py_LIMITED_API) && Py_LIMITED_API+0 < _Py_PACK_VERSION(3, 10) PyObject *bytes; #endif const void *utf8; @@ -1075,7 +1104,7 @@ PyUnicode_EqualToUTF8AndSize(PyObject *unicode, const char *str, Py_ssize_t str_ else #endif { -#if defined(Py_LIMITED_API) && Py_LIMITED_API+0 < 0x030a0000 +#if defined(Py_LIMITED_API) && Py_LIMITED_API+0 < _Py_PACK_VERSION(3, 10) bytes = PyUnicode_AsUTF8String(unicode); if (bytes == NULL) { // Memory allocation failure. The API cannot report error, @@ -1103,7 +1132,7 @@ PyUnicode_EqualToUTF8AndSize(PyObject *unicode, const char *str, Py_ssize_t str_ else { res = (memcmp(utf8, str, (size_t)len) == 0); } -#if defined(Py_LIMITED_API) && Py_LIMITED_API+0 < 0x030a0000 +#if defined(Py_LIMITED_API) && Py_LIMITED_API+0 < _Py_PACK_VERSION(3, 10) Py_DECREF(bytes); #endif @@ -1120,8 +1149,8 @@ PyUnicode_EqualToUTF8(PyObject *unicode, const char *str) #endif -// gh-111138 added PyList_Extend() and PyList_Clear() to Python 3.13.0a2 -#if PY_VERSION_HEX < 0x030D00A2 || defined(Py_LIMITED_API) +// gh-111138 added PyList_Extend() and PyList_Clear() to Python 3.13 +#if PY_VERSION_HEX < _Py_PACK_VERSION(3, 13) || defined(Py_LIMITED_API) static inline int PyList_Extend(PyObject *list, PyObject *iterable) { @@ -1135,8 +1164,8 @@ PyList_Clear(PyObject *list) } #endif -// gh-111262 added PyDict_Pop() and PyDict_PopString() to Python 3.13.0a2 -#if PY_VERSION_HEX < 0x030D00A2 || defined(Py_LIMITED_API) +// gh-111262 added PyDict_Pop() and PyDict_PopString() to Python 3.13 +#if PY_VERSION_HEX < _Py_PACK_VERSION(3, 13) || defined(Py_LIMITED_API) static inline int PyDict_Pop(PyObject *dict, PyObject *key, PyObject **result) { @@ -1150,10 +1179,11 @@ PyDict_Pop(PyObject *dict, PyObject *key, PyObject **result) return -1; } - // bpo-16991 added _PyDict_Pop() to Python 3.5.0b2. - // Python 3.6.0b3 changed _PyDict_Pop() first argument type to PyObject*. - // Python 3.13.0a1 removed _PyDict_Pop(). -#if defined(PYPY_VERSION) || PY_VERSION_HEX >= 0x030D0000 || defined(Py_LIMITED_API) + // bpo-16991 added _PyDict_Pop() to Python 3.5. + // Python 3.6 changed _PyDict_Pop() first argument type to PyObject*. + // Python 3.13 removed _PyDict_Pop(). +#if (PY_VERSION_HEX >= _Py_PACK_VERSION(3, 13) \ + || defined(PYPY_VERSION) || defined(Py_LIMITED_API)) value = PyObject_CallMethod(dict, "pop", "O", key); #else value = _PyDict_Pop(dict, key, NULL); @@ -1195,11 +1225,11 @@ PyDict_PopString(PyObject *dict, const char *key, PyObject **result) #endif -// gh-111545 added Py_HashPointer() to Python 3.13.0a3 -#if PY_VERSION_HEX < 0x030D00A3 && !defined(Py_LIMITED_API) +// gh-111545 added Py_HashPointer() to Python 3.13 +#if PY_VERSION_HEX < _Py_PACK_VERSION(3, 13) && !defined(Py_LIMITED_API) static inline Py_hash_t Py_HashPointer(const void *ptr) { -#if PY_VERSION_HEX >= 0x030900A4 && !defined(PYPY_VERSION) +#if PY_VERSION_HEX >= _Py_PACK_VERSION(3, 9) && !defined(PYPY_VERSION) return _Py_HashPointer(ptr); #else return _Py_HashPointer(_Py_CAST(void*, ptr)); @@ -1208,9 +1238,9 @@ static inline Py_hash_t Py_HashPointer(const void *ptr) #endif -// Python 3.13a4 added a PyTime API. +// Python 3.13 added a PyTime API. // Use the private API added to Python 3.5. -#if PY_VERSION_HEX < 0x030D00A4 && !defined(Py_LIMITED_API) +#if PY_VERSION_HEX < _Py_PACK_VERSION(3, 13) && !defined(Py_LIMITED_API) typedef _PyTime_t PyTime_t; #define PyTime_MIN _PyTime_MIN #define PyTime_MAX _PyTime_MAX @@ -1226,9 +1256,9 @@ static inline int PyTime_Time(PyTime_t *result) static inline int PyTime_PerfCounter(PyTime_t *result) { -#if PY_VERSION_HEX >= 0x03070000 && !defined(PYPY_VERSION) +#if PY_VERSION_HEX >= _Py_PACK_VERSION(3, 7) && !defined(PYPY_VERSION) return _PyTime_GetPerfCounterWithInfo(result, NULL); -#elif PY_VERSION_HEX >= 0x03070000 +#elif PY_VERSION_HEX >= _Py_PACK_VERSION(3, 7) // Call time.perf_counter_ns() and convert Python int object to PyTime_t. // Cache time.perf_counter_ns() function for best performance. static PyObject *func = NULL; @@ -1295,11 +1325,11 @@ static inline int PyTime_PerfCounter(PyTime_t *result) #endif -// gh-111389 added hash constants to Python 3.13.0a5. These constants were -// added first as private macros to Python 3.4.0b1 and PyPy 7.3.8. +// gh-111389 added hash constants to Python 3.13. These constants were +// added first as private macros to Python 3.4 and PyPy 7.3.8. #if (!defined(PyHASH_BITS) \ - && ((!defined(PYPY_VERSION) && PY_VERSION_HEX >= 0x030400B1) \ - || (defined(PYPY_VERSION) && PY_VERSION_HEX >= 0x03070000 \ + && ((!defined(PYPY_VERSION) && PY_VERSION_HEX >= _Py_PACK_VERSION(3, 4)) \ + || (defined(PYPY_VERSION) && PY_VERSION_HEX >= _Py_PACK_VERSION(3, 7) \ && PYPY_VERSION_NUM >= 0x07030800))) # define PyHASH_BITS _PyHASH_BITS # define PyHASH_MODULUS _PyHASH_MODULUS @@ -1309,9 +1339,9 @@ static inline int PyTime_PerfCounter(PyTime_t *result) // gh-111545 added Py_GetConstant() and Py_GetConstantBorrowed() -// to Python 3.13.0a6 -#if (PY_VERSION_HEX < 0x030D00A6 \ - || (defined(Py_LIMITED_API) && Py_LIMITED_API+0 < 0x030D0000)) +// to Python 3.13 +#if (PY_VERSION_HEX < _Py_PACK_VERSION(3, 13) \ + || (defined(Py_LIMITED_API) && Py_LIMITED_API+0 < _Py_PACK_VERSION(3, 13))) #ifndef Py_CONSTANT_NONE # define Py_CONSTANT_NONE 0 @@ -1388,9 +1418,9 @@ static inline PyObject* Py_GetConstantBorrowed(unsigned int constant_id) #endif -// gh-114329 added PyList_GetItemRef() to Python 3.13.0a4 -#if (PY_VERSION_HEX < 0x030D00A4 \ - || (defined(Py_LIMITED_API) && Py_LIMITED_API+0 < 0x030d0000)) +// gh-114329 added PyList_GetItemRef() to Python 3.13 +#if (PY_VERSION_HEX < _Py_PACK_VERSION(3, 13) \ + || (defined(Py_LIMITED_API) && Py_LIMITED_API+0 < _Py_PACK_VERSION(3, 13))) static inline PyObject * PyList_GetItemRef(PyObject *op, Py_ssize_t index) { @@ -1401,9 +1431,9 @@ PyList_GetItemRef(PyObject *op, Py_ssize_t index) #endif -// gh-114329 added PyList_GetItemRef() to Python 3.13.0a4 -#if (PY_VERSION_HEX < 0x030D00A4 \ - || (defined(Py_LIMITED_API) && Py_LIMITED_API+0 < 0x030F0000)) +// gh-114329 added PyList_GetItemRef() to Python 3.13 +#if (PY_VERSION_HEX < _Py_PACK_VERSION(3, 13) \ + || (defined(Py_LIMITED_API) && Py_LIMITED_API+0 < _Py_PACK_VERSION(3, 15))) static inline int PyDict_SetDefaultRef(PyObject *d, PyObject *key, PyObject *default_value, PyObject **result) @@ -1442,14 +1472,15 @@ PyDict_SetDefaultRef(PyObject *d, PyObject *key, PyObject *default_value, } #endif -#if PY_VERSION_HEX < 0x030D00B3 +#if PY_VERSION_HEX < _Py_PACK_VERSION(3, 13) # define Py_BEGIN_CRITICAL_SECTION(op) { # define Py_END_CRITICAL_SECTION() } # define Py_BEGIN_CRITICAL_SECTION2(a, b) { # define Py_END_CRITICAL_SECTION2() } #endif -#if PY_VERSION_HEX < 0x030E0000 && !defined(PYPY_VERSION) && !defined(Py_LIMITED_API) +#if (PY_VERSION_HEX < _Py_PACK_VERSION(3, 14) \ + && !defined(PYPY_VERSION) && !defined(Py_LIMITED_API)) typedef struct PyUnicodeWriter PyUnicodeWriter; static inline void PyUnicodeWriter_Discard(PyUnicodeWriter *writer) @@ -1618,10 +1649,10 @@ PyUnicodeWriter_Format(PyUnicodeWriter *writer, const char *format, ...) Py_DECREF(str); return res; } -#endif // PY_VERSION_HEX < 0x030E0000 +#endif // PY_VERSION_HEX < _Py_PACK_VERSION(3, 14) -// gh-116560 added PyLong_GetSign() to Python 3.14.0a0 -#if PY_VERSION_HEX < 0x030E00A0 || defined(Py_LIMITED_API) +// gh-116560 added PyLong_GetSign() to Python 3.14 +#if PY_VERSION_HEX < _Py_PACK_VERSION(3, 14) || defined(Py_LIMITED_API) static inline int PyLong_GetSign(PyObject *obj, int *sign) { #ifndef Py_LIMITED_API @@ -1664,8 +1695,8 @@ static inline int PyLong_GetSign(PyObject *obj, int *sign) } #endif -// gh-126061 added PyLong_IsPositive/Negative/Zero() to Python in 3.14.0a2 -#if PY_VERSION_HEX < 0x030E00A2 || defined(Py_LIMITED_API) +// gh-126061 added PyLong_IsPositive/Negative/Zero() to Python in 3.14 +#if PY_VERSION_HEX < _Py_PACK_VERSION(3, 14) || defined(Py_LIMITED_API) static inline int PyLong_IsPositive(PyObject *obj) { #ifndef Py_LIMITED_API @@ -1736,11 +1767,12 @@ static inline int PyLong_IsZero(PyObject *obj) #endif -// gh-124502 added PyUnicode_Equal() to Python 3.14.0a0 -#if (PY_VERSION_HEX < 0x030E00A0 \ - || (defined(Py_LIMITED_API) && Py_LIMITED_API+0 < 0x030e0000)) +// gh-124502 added PyUnicode_Equal() to Python 3.14 +#if (PY_VERSION_HEX < _Py_PACK_VERSION(3, 14) \ + || (defined(Py_LIMITED_API) && Py_LIMITED_API+0 < _Py_PACK_VERSION(3, 14))) -#if PY_VERSION_HEX >= 0x030d0000 && !defined(PYPY_VERSION) && !defined(Py_LIMITED_API) +#if (PY_VERSION_HEX >= _Py_PACK_VERSION(3, 13) \ + && !defined(PYPY_VERSION) && !defined(Py_LIMITED_API)) PyAPI_FUNC(int) _PyUnicode_Equal(PyObject *str1, PyObject *str2); #endif @@ -1755,11 +1787,13 @@ static inline int PyUnicode_Equal(PyObject *str1, PyObject *str2) return -1; } -#if PY_VERSION_HEX >= 0x030d0000 && !defined(PYPY_VERSION) && !defined(Py_LIMITED_API) +#if (PY_VERSION_HEX >= _Py_PACK_VERSION(3, 13) \ + && !defined(PYPY_VERSION) && !defined(Py_LIMITED_API)) return _PyUnicode_Equal(str1, str2); #elif !defined(PYPY_VERSION) && !defined(Py_LIMITED_API) return _PyUnicode_EQ(str1, str2); -#elif PY_VERSION_HEX >= 0x03090000 && defined(PYPY_VERSION) && !defined(Py_LIMITED_API) +#elif (PY_VERSION_HEX >= _Py_PACK_VERSION(3, 9) \ + && defined(PYPY_VERSION) && !defined(Py_LIMITED_API)) return _PyUnicode_EQ(str1, str2); #else { @@ -1774,8 +1808,8 @@ static inline int PyUnicode_Equal(PyObject *str1, PyObject *str2) #endif -// gh-121645 added PyBytes_Join() to Python 3.14.0a0 -#if PY_VERSION_HEX < 0x030E00A0 || defined(Py_LIMITED_API) +// gh-121645 added PyBytes_Join() to Python 3.14 +#if PY_VERSION_HEX < _Py_PACK_VERSION(3, 14) || defined(Py_LIMITED_API) static inline PyObject* PyBytes_Join(PyObject *sep, PyObject *iterable) { #ifndef Py_LIMITED_API @@ -1797,8 +1831,8 @@ static inline PyObject* PyBytes_Join(PyObject *sep, PyObject *iterable) #endif -#if (PY_VERSION_HEX < 0x030E00A0 \ - || (defined(Py_LIMITED_API) && Py_LIMITED_API+0 < 0x03100000)) +#if (PY_VERSION_HEX < _Py_PACK_VERSION(3, 14) \ + || (defined(Py_LIMITED_API) && Py_LIMITED_API+0 < _Py_PACK_VERSION(3, 16))) #if !defined(PYPY_VERSION) && !defined(Py_LIMITED_API) PyAPI_FUNC(Py_hash_t) _Py_HashBytes(const void *src, Py_ssize_t len); @@ -1822,11 +1856,11 @@ static inline Py_hash_t Py_HashBuffer(const void *ptr, Py_ssize_t len) #endif -#if (PY_VERSION_HEX < 0x030E00A0 \ - || (defined(Py_LIMITED_API) && Py_LIMITED_API+0 < 0x030e0000)) +#if (PY_VERSION_HEX < _Py_PACK_VERSION(3, 14) \ + || (defined(Py_LIMITED_API) && Py_LIMITED_API+0 < _Py_PACK_VERSION(3, 14))) static inline int PyIter_NextItem(PyObject *iter, PyObject **item) { -#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03040000 +#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= _Py_PACK_VERSION(3, 4) iternextfunc tp_iternext; assert(iter != NULL); @@ -1878,8 +1912,8 @@ static inline int PyIter_NextItem(PyObject *iter, PyObject **item) #endif -#if (PY_VERSION_HEX < 0x030E00A0 \ - || (defined(Py_LIMITED_API) && Py_LIMITED_API+0 < 0x030e0000)) +#if (PY_VERSION_HEX < _Py_PACK_VERSION(3, 14) \ + || (defined(Py_LIMITED_API) && Py_LIMITED_API+0 < _Py_PACK_VERSION(3, 14))) static inline PyObject* PyLong_FromInt32(int32_t value) { Py_BUILD_ASSERT(sizeof(long) >= 4); @@ -1957,15 +1991,16 @@ static inline int PyLong_AsUInt64(PyObject *obj, uint64_t *pvalue) #endif -// gh-102471 added import and export API for integers to 3.14.0a2. -#if PY_VERSION_HEX < 0x030E00A2 && !defined(PYPY_VERSION) && !defined(Py_LIMITED_API) +// gh-102471 added import and export API for integers to 3.14. +#if (PY_VERSION_HEX < _Py_PACK_VERSION(3, 14) \ + && !defined(PYPY_VERSION) && !defined(Py_LIMITED_API)) // Helpers to access PyLongObject internals. static inline void _PyLong_SetSignAndDigitCount(PyLongObject *op, int sign, Py_ssize_t size) { -#if PY_VERSION_HEX >= 0x030C0000 +#if PY_VERSION_HEX >= _Py_PACK_VERSION(3, 12) op->long_value.lv_tag = (uintptr_t)(1 - sign) | ((uintptr_t)(size) << 3); -#elif PY_VERSION_HEX >= 0x030900A4 +#elif PY_VERSION_HEX >= _Py_PACK_VERSION(3, 9) Py_SET_SIZE(op, sign * size); #else Py_SIZE(op) = sign * size; @@ -1975,7 +2010,7 @@ _PyLong_SetSignAndDigitCount(PyLongObject *op, int sign, Py_ssize_t size) static inline Py_ssize_t _PyLong_DigitCount(const PyLongObject *op) { -#if PY_VERSION_HEX >= 0x030C0000 +#if PY_VERSION_HEX >= _Py_PACK_VERSION(3, 12) return (Py_ssize_t)(op->long_value.lv_tag >> 3); #else return _PyLong_Sign((PyObject*)op) < 0 ? -Py_SIZE(op) : Py_SIZE(op); @@ -1985,7 +2020,7 @@ _PyLong_DigitCount(const PyLongObject *op) static inline digit* _PyLong_GetDigits(const PyLongObject *op) { -#if PY_VERSION_HEX >= 0x030C0000 +#if PY_VERSION_HEX >= _Py_PACK_VERSION(3, 12) return (digit*)(op->long_value.ob_digit); #else return (digit*)(op->ob_digit); @@ -2135,7 +2170,7 @@ PyLongWriter_Finish(PyLongWriter *writer) #endif -#if PY_VERSION_HEX < 0x030C00A3 +#if PY_VERSION_HEX < _Py_PACK_VERSION(3, 12) # define Py_T_SHORT 0 # define Py_T_INT 1 # define Py_T_LONG 2 @@ -2166,8 +2201,8 @@ PyLongWriter_Finish(PyLongWriter *writer) #endif -// gh-127350 added Py_fopen() and Py_fclose() to Python 3.14a4 -#if PY_VERSION_HEX < 0x030E00A4 || defined(Py_LIMITED_API) +// gh-127350 added Py_fopen() and Py_fclose() to Python 3.14 +#if PY_VERSION_HEX < _Py_PACK_VERSION(3, 14) || defined(Py_LIMITED_API) #if !defined(PYPY_VERSION) && !defined(Py_LIMITED_API) PyAPI_FUNC(FILE*) _Py_fopen_obj(PyObject *path, const char *mode); @@ -2208,8 +2243,8 @@ static inline int Py_fclose(FILE *file) #endif -#if (0x03080000 <= PY_VERSION_HEX \ - && PY_VERSION_HEX < 0x030E0000 \ +#if (_Py_PACK_VERSION(3, 8) <= PY_VERSION_HEX \ + && PY_VERSION_HEX < _Py_PACK_VERSION(3, 14) \ && !defined(PYPY_VERSION) && !defined(Py_LIMITED_API)) PyAPI_FUNC(const PyConfig*) _Py_GetConfig(void); @@ -2246,20 +2281,20 @@ PyConfig_Get(const char *name) PYTHONCAPI_COMPAT_SPEC(exec_prefix, WSTR_OPT, "exec_prefix"), PYTHONCAPI_COMPAT_SPEC(executable, WSTR_OPT, "executable"), PYTHONCAPI_COMPAT_SPEC(inspect, BOOL, _Py_NULL), -#if 0x030C0000 <= PY_VERSION_HEX +#if _Py_PACK_VERSION(3, 12) <= PY_VERSION_HEX PYTHONCAPI_COMPAT_SPEC(int_max_str_digits, UINT, _Py_NULL), #endif PYTHONCAPI_COMPAT_SPEC(interactive, BOOL, _Py_NULL), PYTHONCAPI_COMPAT_SPEC(module_search_paths, WSTR_LIST, "path"), PYTHONCAPI_COMPAT_SPEC(optimization_level, UINT, _Py_NULL), PYTHONCAPI_COMPAT_SPEC(parser_debug, BOOL, _Py_NULL), -#if 0x03090000 <= PY_VERSION_HEX +#if _Py_PACK_VERSION(3, 9) <= PY_VERSION_HEX PYTHONCAPI_COMPAT_SPEC(platlibdir, WSTR, "platlibdir"), #endif PYTHONCAPI_COMPAT_SPEC(prefix, WSTR_OPT, "prefix"), PYTHONCAPI_COMPAT_SPEC(pycache_prefix, WSTR_OPT, "pycache_prefix"), PYTHONCAPI_COMPAT_SPEC(quiet, BOOL, _Py_NULL), -#if 0x030B0000 <= PY_VERSION_HEX +#if _Py_PACK_VERSION(3, 11) <= PY_VERSION_HEX PYTHONCAPI_COMPAT_SPEC(stdlib_dir, WSTR_OPT, "_stdlib_dir"), #endif PYTHONCAPI_COMPAT_SPEC(use_environment, BOOL, _Py_NULL), @@ -2269,16 +2304,16 @@ PyConfig_Get(const char *name) PYTHONCAPI_COMPAT_SPEC(xoptions, WSTR_LIST, "_xoptions"), PYTHONCAPI_COMPAT_SPEC(buffered_stdio, BOOL, _Py_NULL), PYTHONCAPI_COMPAT_SPEC(check_hash_pycs_mode, WSTR, _Py_NULL), -#if 0x030B0000 <= PY_VERSION_HEX +#if _Py_PACK_VERSION(3, 11) <= PY_VERSION_HEX PYTHONCAPI_COMPAT_SPEC(code_debug_ranges, BOOL, _Py_NULL), #endif PYTHONCAPI_COMPAT_SPEC(configure_c_stdio, BOOL, _Py_NULL), -#if 0x030D0000 <= PY_VERSION_HEX +#if _Py_PACK_VERSION(3, 13) <= PY_VERSION_HEX PYTHONCAPI_COMPAT_SPEC(cpu_count, INT, _Py_NULL), #endif PYTHONCAPI_COMPAT_SPEC(dev_mode, BOOL, _Py_NULL), PYTHONCAPI_COMPAT_SPEC(dump_refs, BOOL, _Py_NULL), -#if 0x030B0000 <= PY_VERSION_HEX +#if _Py_PACK_VERSION(3, 11) <= PY_VERSION_HEX PYTHONCAPI_COMPAT_SPEC(dump_refs_file, WSTR_OPT, _Py_NULL), #endif #ifdef Py_GIL_DISABLED @@ -2296,19 +2331,19 @@ PyConfig_Get(const char *name) PYTHONCAPI_COMPAT_SPEC(legacy_windows_stdio, BOOL, _Py_NULL), #endif PYTHONCAPI_COMPAT_SPEC(malloc_stats, BOOL, _Py_NULL), -#if 0x030A0000 <= PY_VERSION_HEX +#if _Py_PACK_VERSION(3, 10) <= PY_VERSION_HEX PYTHONCAPI_COMPAT_SPEC(orig_argv, WSTR_LIST, "orig_argv"), #endif PYTHONCAPI_COMPAT_SPEC(parse_argv, BOOL, _Py_NULL), PYTHONCAPI_COMPAT_SPEC(pathconfig_warnings, BOOL, _Py_NULL), -#if 0x030C0000 <= PY_VERSION_HEX +#if _Py_PACK_VERSION(3, 12) <= PY_VERSION_HEX PYTHONCAPI_COMPAT_SPEC(perf_profiling, UINT, _Py_NULL), #endif PYTHONCAPI_COMPAT_SPEC(program_name, WSTR, _Py_NULL), PYTHONCAPI_COMPAT_SPEC(run_command, WSTR_OPT, _Py_NULL), PYTHONCAPI_COMPAT_SPEC(run_filename, WSTR_OPT, _Py_NULL), PYTHONCAPI_COMPAT_SPEC(run_module, WSTR_OPT, _Py_NULL), -#if 0x030B0000 <= PY_VERSION_HEX +#if _Py_PACK_VERSION(3, 11) <= PY_VERSION_HEX PYTHONCAPI_COMPAT_SPEC(safe_path, BOOL, _Py_NULL), #endif PYTHONCAPI_COMPAT_SPEC(show_ref_count, BOOL, _Py_NULL), @@ -2317,12 +2352,12 @@ PyConfig_Get(const char *name) PYTHONCAPI_COMPAT_SPEC(stdio_encoding, WSTR, _Py_NULL), PYTHONCAPI_COMPAT_SPEC(stdio_errors, WSTR, _Py_NULL), PYTHONCAPI_COMPAT_SPEC(tracemalloc, UINT, _Py_NULL), -#if 0x030B0000 <= PY_VERSION_HEX +#if _Py_PACK_VERSION(3, 11) <= PY_VERSION_HEX PYTHONCAPI_COMPAT_SPEC(use_frozen_modules, BOOL, _Py_NULL), #endif PYTHONCAPI_COMPAT_SPEC(use_hash_seed, BOOL, _Py_NULL), PYTHONCAPI_COMPAT_SPEC(user_site_directory, BOOL, _Py_NULL), -#if 0x030A0000 <= PY_VERSION_HEX +#if _Py_PACK_VERSION(3, 10) <= PY_VERSION_HEX PYTHONCAPI_COMPAT_SPEC(warn_default_encoding, BOOL, _Py_NULL), #endif }; @@ -2430,12 +2465,13 @@ PyConfig_GetInt(const char *name, int *value) *value = as_int; return 0; } -#endif // PY_VERSION_HEX > 0x03090000 && !defined(PYPY_VERSION) +#endif // PY_VERSION_HEX > _Py_PACK_VERSION(3, 9) && !defined(PYPY_VERSION) -// gh-133144 added PyUnstable_Object_IsUniquelyReferenced() to Python 3.14.0b1. +// gh-133144 added PyUnstable_Object_IsUniquelyReferenced() to Python 3.14. // Adapted from _PyObject_IsUniquelyReferenced() implementation. // Not available on PyPy: Py_REFCNT() semantics is different on PyPy. -#if PY_VERSION_HEX < 0x030E00B0 && !defined(PYPY_VERSION) && !defined(Py_LIMITED_API) +#if (PY_VERSION_HEX < _Py_PACK_VERSION(3, 14) \ + && !defined(PYPY_VERSION) && !defined(Py_LIMITED_API)) static inline int PyUnstable_Object_IsUniquelyReferenced(PyObject *obj) { #if !defined(Py_GIL_DISABLED) @@ -2452,9 +2488,10 @@ static inline int PyUnstable_Object_IsUniquelyReferenced(PyObject *obj) #endif // gh-128926 added PyUnstable_TryIncRef() and PyUnstable_EnableTryIncRef() to -// Python 3.14.0a5. Adapted from _Py_TryIncref() and _PyObject_SetMaybeWeakref(). +// Python 3.14. Adapted from _Py_TryIncref() and _PyObject_SetMaybeWeakref(). // Not available on PyPy: Py_REFCNT() semantics is different on PyPy. -#if PY_VERSION_HEX < 0x030E00A5 && !defined(PYPY_VERSION) +#if (PY_VERSION_HEX < _Py_PACK_VERSION(3, 14) \ + && !defined(PYPY_VERSION)) static inline int PyUnstable_TryIncRef(PyObject *op) { #ifndef Py_GIL_DISABLED @@ -2525,11 +2562,11 @@ static inline void PyUnstable_EnableTryIncRef(PyObject *op) (void)op; // unused argument #endif } -#endif // PY_VERSION_HEX < 0x030E00A5 && !defined(PYPY_VERSION) +#endif // PY_VERSION_HEX < _Py_PACK_VERSION(3, 14) && !defined(PYPY_VERSION) -#if (PY_VERSION_HEX < 0x030F0000 \ - || (defined(Py_LIMITED_API) && Py_LIMITED_API+0 < 0x030f0000)) +#if (PY_VERSION_HEX < _Py_PACK_VERSION(3, 15) \ + || (defined(Py_LIMITED_API) && Py_LIMITED_API+0 < _Py_PACK_VERSION(3, 15))) static inline PyObject* PySys_GetAttrString(const char *name) { @@ -2546,7 +2583,7 @@ PySys_GetAttrString(const char *name) static inline PyObject* PySys_GetAttr(PyObject *name) { -#if defined(Py_LIMITED_API) && Py_LIMITED_API+0 < 0x030a0000 +#if defined(Py_LIMITED_API) && Py_LIMITED_API+0 < _Py_PACK_VERSION(3, 10) PyObject *bytes, *result; bytes = PyUnicode_AsUTF8String(name); if (bytes == NULL) { @@ -2582,7 +2619,7 @@ PySys_GetOptionalAttrString(const char *name, PyObject **value) static inline int PySys_GetOptionalAttr(PyObject *name, PyObject **value) { -#if defined(Py_LIMITED_API) && Py_LIMITED_API+0 < 0x030a0000 +#if defined(Py_LIMITED_API) && Py_LIMITED_API+0 < _Py_PACK_VERSION(3, 10) PyObject *bytes; int res; bytes = PyUnicode_AsUTF8String(name); @@ -2607,11 +2644,11 @@ PySys_GetOptionalAttr(PyObject *name, PyObject **value) return PySys_GetOptionalAttrString(name_str, value); #endif } -#endif // PY_VERSION_HEX < 0x030F00A1 +#endif // PY_VERSION_HEX < _Py_PACK_VERSION(3, 15) // _PyBytes_Resize() is not available in the limited C API. -#if PY_VERSION_HEX < 0x030F00A1 && !defined(Py_LIMITED_API) +#if PY_VERSION_HEX < _Py_PACK_VERSION(3, 15) && !defined(Py_LIMITED_API) typedef struct PyBytesWriter { char small_buffer[256]; PyObject *obj; @@ -2867,10 +2904,10 @@ PyBytesWriter_Format(PyBytesWriter *writer, const char *format, ...) Py_DECREF(str); return res; } -#endif // PY_VERSION_HEX < 0x030F00A1 +#endif // PY_VERSION_HEX < _Py_PACK_VERSION(3, 15) -#if PY_VERSION_HEX < 0x030F00A1 +#if PY_VERSION_HEX < _Py_PACK_VERSION(3, 15) static inline PyObject* PyTuple_FromArray(PyObject *const *array, Py_ssize_t size) { @@ -2894,7 +2931,7 @@ PyTuple_FromArray(PyObject *const *array, Py_ssize_t size) #endif -#if PY_VERSION_HEX < 0x030F00A1 && !defined(Py_LIMITED_API) +#if PY_VERSION_HEX < _Py_PACK_VERSION(3, 15) && !defined(Py_LIMITED_API) static inline Py_hash_t PyUnstable_Unicode_GET_CACHED_HASH(PyObject *op) { @@ -2907,14 +2944,14 @@ PyUnstable_Unicode_GET_CACHED_HASH(PyObject *op) } #endif -#if (0x030D0000 <= PY_VERSION_HEX \ - && PY_VERSION_HEX < 0x030F00A7 \ - && !defined(PYPY_VERSION) && !defined(Py_LIMITED_API)) +#if (_Py_PACK_VERSION(3, 13) <= PY_VERSION_HEX \ + && PY_VERSION_HEX < _Py_PACK_VERSION(3, 15) \ + && !defined(PYPY_VERSION) && !defined(Py_LIMITED_API)) // Immortal objects were implemented in Python 3.12, however there is no easy API // to make objects immortal until 3.14 which has _Py_SetImmortal(). Since // immortal objects are primarily needed for free-threading, this API is implemented // for 3.14 using _Py_SetImmortal() and uses private macros on 3.13. -#if 0x030E0000 <= PY_VERSION_HEX +#if _Py_PACK_VERSION(3, 14) <= PY_VERSION_HEX PyAPI_FUNC(void) _Py_SetImmortal(PyObject *op); #endif @@ -2925,7 +2962,7 @@ PyUnstable_SetImmortal(PyObject *op) if (!PyUnstable_Object_IsUniquelyReferenced(op) || PyUnicode_Check(op)) { return 0; } -#if 0x030E0000 <= PY_VERSION_HEX +#if _Py_PACK_VERSION(3, 14) <= PY_VERSION_HEX _Py_SetImmortal(op); #else // Python 3.13 doesn't export _Py_SetImmortal() function @@ -2947,7 +2984,7 @@ PyUnstable_SetImmortal(PyObject *op) // Python 3.14 added PyImport_ImportModuleAttr() // and PyImport_ImportModuleAttrString() -#if PY_VERSION_HEX < 0x030E0000 || defined(Py_LIMITED_API) +#if PY_VERSION_HEX < _Py_PACK_VERSION(3, 14) || defined(Py_LIMITED_API) static inline PyObject* PyImport_ImportModuleAttr(PyObject *mod_name, PyObject *attr_name) { @@ -2983,8 +3020,8 @@ PyImport_ImportModuleAttrString(const char *mod_name, const char *attr_name) // Python 3.11 added PyType_GetName() and PyType_GetQualName() -#if (PY_VERSION_HEX < 0x030B0000 \ - || (defined(Py_LIMITED_API) && Py_LIMITED_API+0 < 0x030B0000)) +#if (PY_VERSION_HEX < _Py_PACK_VERSION(3, 11) \ + || (defined(Py_LIMITED_API) && Py_LIMITED_API+0 < _Py_PACK_VERSION(3, 11))) static inline PyObject* PyType_GetName(PyTypeObject *type) { @@ -3000,8 +3037,8 @@ PyType_GetQualName(PyTypeObject *type) // Python 3.13 added PyType_GetModuleName() and PyType_GetFullyQualifiedName() -#if (PY_VERSION_HEX < 0x030D0000 \ - || (defined(Py_LIMITED_API) && Py_LIMITED_API+0 < 0x030D0000)) +#if (PY_VERSION_HEX < _Py_PACK_VERSION(3, 13) \ + || (defined(Py_LIMITED_API) && Py_LIMITED_API+0 < _Py_PACK_VERSION(3, 13))) static inline PyObject* PyType_GetModuleName(PyTypeObject *type) { diff --git a/tests/test_pythoncapi_compat_cext.c b/tests/test_pythoncapi_compat_cext.c index fd99a39..ac3cdc6 100644 --- a/tests/test_pythoncapi_compat_cext.c +++ b/tests/test_pythoncapi_compat_cext.c @@ -21,20 +21,20 @@ // Ignore reference count checks on PyPy #ifndef PYPY_VERSION -# define CHECK_REFCNT +# define CHECK_REFCNT #endif // CPython 3.12 beta 1 implements immortal objects (PEP 683) -#if 0x030C00B1 <= PY_VERSION_HEX && !defined(PYPY_VERSION) - // Don't check reference count of Python 3.12 immortal objects (ex: bool - // and str types) -# define IMMORTAL_OBJS +#if _Py_PACK_VERSION(3, 12) <= PY_VERSION_HEX && !defined(PYPY_VERSION) + // Don't check reference count of Python 3.12 immortal objects (ex: bool + // and str types) +# define IMMORTAL_OBJS #endif #ifdef CHECK_REFCNT -# define ASSERT_REFCNT(expr) assert(expr) +# define ASSERT_REFCNT(expr) assert(expr) #else -# define ASSERT_REFCNT(expr) +# define ASSERT_REFCNT(expr) #endif // Marker to check that pointer value was set @@ -75,7 +75,7 @@ test_object(PyObject *Py_UNUSED(module), PyObject* Py_UNUSED(ignored)) assert(Py_XNewRef(_Py_NULL) == _Py_NULL); -#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03100000 +#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= _Py_PACK_VERSION(3, 16) // Py_SETREF() PyObject *setref = Py_NewRef(obj); PyObject *none = Py_None; @@ -104,7 +104,7 @@ test_object(PyObject *Py_UNUSED(module), PyObject* Py_UNUSED(ignored)) // Py_SET_REFCNT Py_SET_REFCNT(obj, Py_REFCNT(obj)); -#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030a0000 +#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < _Py_PACK_VERSION(3, 10) // Py_SET_TYPE Py_SET_TYPE(obj, Py_TYPE(obj)); #endif @@ -192,8 +192,8 @@ test_frame_getvar(PyFrameObject *frame) // PyThreadState_GetFrame() needs limited C API 3.9 or newer -#if ((!defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03090000) \ - && !defined(PYPY_VERSION)) +#if ((!defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= _Py_PACK_VERSION(3, 9)) \ + && !defined(PYPY_VERSION)) static PyObject * test_frame(PyObject *Py_UNUSED(module), PyObject* Py_UNUSED(ignored)) { @@ -250,7 +250,7 @@ test_frame(PyObject *Py_UNUSED(module), PyObject* Py_UNUSED(ignored)) PyObject *locals = PyFrame_GetLocals(frame); assert(locals != _Py_NULL); // Python 3.13 creates a local proxy -#if PY_VERSION_HEX < 0x030D0000 +#if PY_VERSION_HEX < _Py_PACK_VERSION(3, 13) assert(PyDict_Check(locals)); #endif @@ -291,7 +291,7 @@ test_frame(PyObject *Py_UNUSED(module), PyObject* Py_UNUSED(ignored)) // PyThreadState_GetInterpreter() and PyThreadState_GetFrame() // need limited C API 3.9 -#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03090000 +#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= _Py_PACK_VERSION(3, 9) static PyObject * test_thread_state(PyObject *Py_UNUSED(module), PyObject* Py_UNUSED(ignored)) { @@ -312,7 +312,7 @@ test_thread_state(PyObject *Py_UNUSED(module), PyObject* Py_UNUSED(ignored)) Py_XDECREF(_PyObject_CAST(frame)); #endif -#if 0x030700A1 <= PY_VERSION_HEX && !defined(PYPY_VERSION) +#if _Py_PACK_VERSION(3, 7) <= PY_VERSION_HEX && !defined(PYPY_VERSION) uint64_t id = PyThreadState_GetID(tstate); assert(id > 0); #endif @@ -323,7 +323,7 @@ test_thread_state(PyObject *Py_UNUSED(module), PyObject* Py_UNUSED(ignored)) PyThreadState_LeaveTracing(tstate); #endif -#if PY_VERSION_HEX >= 0x03050200 && !defined(Py_LIMITED_API) +#if PY_VERSION_HEX >= _Py_PACK_VERSION(3, 5) && !defined(Py_LIMITED_API) // PyThreadState_GetUnchecked() assert(PyThreadState_GetUnchecked() == tstate); #endif @@ -339,7 +339,7 @@ test_interpreter(PyObject *Py_UNUSED(module), PyObject* Py_UNUSED(ignored)) // On Windows,PyInterpreterState_Get() is not available in stable ABI 3.9, // only in stable ABI 3.10. Don't test it in limited C API 3.9 on Unix to // make the test simpler. -#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030A0000 +#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= _Py_PACK_VERSION(3, 10) // test PyInterpreterState_Get() PyInterpreterState *interp = PyInterpreterState_Get(); assert(interp != _Py_NULL); @@ -350,9 +350,9 @@ test_interpreter(PyObject *Py_UNUSED(module), PyObject* Py_UNUSED(ignored)) assert(interp == interp2); #endif -#if (0x030300A1 <= PY_VERSION_HEX \ - && (!defined(PYPY_VERSION_NUM) || PYPY_VERSION_NUM >= 0x7030000) \ - && (!defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030D0000)) +#if (_Py_PACK_VERSION(3, 3) <= PY_VERSION_HEX \ + && (!defined(PYPY_VERSION_NUM) || PYPY_VERSION_NUM >= 0x7030000) \ + && (!defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= _Py_PACK_VERSION(3, 13))) // test Py_IsFinalizing() assert(Py_IsFinalizing() == 0); #endif @@ -393,7 +393,8 @@ test_calls(PyObject *Py_UNUSED(module), PyObject* Py_UNUSED(ignored)) } -#if !(defined(Py_LIMITED_API) && PY_VERSION_HEX < 0x030A0000) && !defined(PYPY_VERSION) +#if ((PY_VERSION_HEX >= _Py_PACK_VERSION(3, 10) || !defined(Py_LIMITED_API)) \ + && !defined(PYPY_VERSION)) static PyObject * test_gc(PyObject *Py_UNUSED(module), PyObject* Py_UNUSED(ignored)) { @@ -433,7 +434,6 @@ check_module_attr(PyObject *module, const char *name, PyObject *expected) } -#if !(defined(Py_LIMITED_API) && PY_VERSION_HEX < 0x030A0000) // test PyModule_AddType() static int test_module_add_type(PyObject *module) @@ -457,7 +457,6 @@ test_module_add_type(PyObject *module) ASSERT_REFCNT(Py_REFCNT(_PyObject_CAST(type)) == refcnt); return 0; } -#endif // !(defined(Py_LIMITED_API) && PY_VERSION_HEX < 0x030A0000) // test PyModule_AddObjectRef() @@ -541,11 +540,9 @@ test_module(PyObject *Py_UNUSED(module), PyObject* Py_UNUSED(ignored)) } assert(PyModule_Check(module)); -#if !(defined(Py_LIMITED_API) && PY_VERSION_HEX < 0x030A0000) if (test_module_add_type(module) < 0) { goto error; } -#endif if (test_module_addobjectref(module) < 0) { goto error; } @@ -562,8 +559,7 @@ test_module(PyObject *Py_UNUSED(module), PyObject* Py_UNUSED(ignored)) } -#if ((PY_VERSION_HEX <= 0x030B00A1 || 0x030B00A7 <= PY_VERSION_HEX) \ - && !defined(PYPY_VERSION) && !defined(Py_LIMITED_API)) +#if !defined(PYPY_VERSION) && !defined(Py_LIMITED_API) static PyObject * test_float_pack(PyObject *Py_UNUSED(module), PyObject* Py_UNUSED(ignored)) { @@ -572,7 +568,7 @@ test_float_pack(PyObject *Py_UNUSED(module), PyObject* Py_UNUSED(ignored)) char data[8]; const double d = 1.5; -#if PY_VERSION_HEX >= 0x030600B1 +#if PY_VERSION_HEX >= _Py_PACK_VERSION(3, 6) # define HAVE_FLOAT_PACK2 #endif @@ -793,7 +789,7 @@ test_import(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(args)) static void gc_collect(void) { -#if defined(PYPY_VERSION) && PY_VERSION_HEX < 0x030B0000 +#if defined(PYPY_VERSION) && PY_VERSION_HEX < _Py_PACK_VERSION(3, 11) PyObject *mod = PyImport_ImportModule("gc"); assert(mod != _Py_NULL); @@ -881,7 +877,6 @@ test_weakref(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(args)) } -#if !(defined(Py_LIMITED_API) && PY_VERSION_HEX < 0x030C0000) static void check_int(PyObject *obj, int value) { @@ -1040,7 +1035,7 @@ test_vectorcall(PyObject *module, PyObject *Py_UNUSED(args)) Py_DECREF(func_varargs); Py_RETURN_NONE; } -#endif // !(defined(Py_LIMITED_API) && PY_VERSION_HEX < 0x030C0000) + static PyObject * @@ -1523,8 +1518,9 @@ test_long_api(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(args)) // --- HeapCTypeWithManagedDict -------------------------------------------- -// Py_TPFLAGS_MANAGED_DICT was added to Python 3.11.0a3 but is not implemented on PyPy -#if (PY_VERSION_HEX >= 0x030B00A3 \ +// Py_TPFLAGS_MANAGED_DICT was added to Python 3.11, +// but is not implemented on PyPy +#if (PY_VERSION_HEX >= _Py_PACK_VERSION(3, 11) \ && !defined(PYPY_VERSION) && !defined(Py_LIMITED_API)) # define TEST_MANAGED_DICT @@ -1601,7 +1597,7 @@ test_managed_dict(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(args)) Py_RETURN_NONE; } -#endif // PY_VERSION_HEX >= 0x030B00A3 +#endif // PY_VERSION_HEX >= _Py_PACK_VERSION(3, 11) static PyObject * @@ -1718,8 +1714,8 @@ test_hash(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(args)) #endif -#if ((!defined(PYPY_VERSION) && PY_VERSION_HEX >= 0x030400B1) \ - || (defined(PYPY_VERSION) && PY_VERSION_HEX >= 0x03070000 \ +#if ((!defined(PYPY_VERSION) && PY_VERSION_HEX >= _Py_PACK_VERSION(3, 4)) \ + || (defined(PYPY_VERSION) && PY_VERSION_HEX >= _Py_PACK_VERSION(3, 7) \ && PYPY_VERSION_NUM >= 0x07030800)) && !defined(Py_LIMITED_API) // Just check that constants are available size_t bits = PyHASH_BITS; @@ -1834,7 +1830,7 @@ check_get_constant(PyObject* (*get_constant)(unsigned int), int borrowed) // Py_CONSTANT_EMPTY_STR obj = get_constant(Py_CONSTANT_EMPTY_STR); assert(Py_TYPE(obj) == &PyUnicode_Type); -#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000 +#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= _Py_PACK_VERSION(3, 3) assert(PyUnicode_GetLength(obj) == 0); #else { @@ -1871,7 +1867,7 @@ test_get_constant(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(args)) } -#if (PY_VERSION_HEX < 0x030E0000 && PY_VERSION_HEX >= 0x03060000 \ +#if (PY_VERSION_HEX < _Py_PACK_VERSION(3, 14) && PY_VERSION_HEX >= _Py_PACK_VERSION(3, 6) \ && !defined(PYPY_VERSION) && !defined(Py_LIMITED_API)) #define TEST_UNICODEWRITER 1 @@ -2074,7 +2070,7 @@ test_bytes(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(args)) } -#if !(defined(Py_LIMITED_API) && PY_VERSION_HEX < 0x030A0000) +#if !(defined(Py_LIMITED_API) && PY_VERSION_HEX < _Py_PACK_VERSION(3, 10)) static PyObject * test_iter(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(args)) { @@ -2107,7 +2103,7 @@ test_iter(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(args)) // Limited C API 3.2 and 3.3 implementation cannot check // if the first argument is an iterator -#if !(defined(Py_LIMITED_API) && PY_VERSION_HEX >= 0x03040000) +#if !(defined(Py_LIMITED_API) && PY_VERSION_HEX >= _Py_PACK_VERSION(3, 4)) // non-iterable object item = UNINITIALIZED_OBJ; assert(PyIter_NextItem(Py_None, &item) == -1); @@ -2119,7 +2115,7 @@ test_iter(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(args)) Py_DECREF(iter); Py_RETURN_NONE; } -#endif // !(defined(Py_LIMITED_API) && PY_VERSION_HEX < 0x030A0000) +#endif // !(defined(Py_LIMITED_API) && PY_VERSION_HEX < _Py_PACK_VERSION(3, 10)) static PyObject * @@ -2212,8 +2208,8 @@ test_file(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(args)) } -#if (0x03090000 <= PY_VERSION_HEX \ - && !defined(PYPY_VERSION) && !defined(Py_LIMITED_API)) +#if (_Py_PACK_VERSION(3, 9) <= PY_VERSION_HEX \ + && !defined(PYPY_VERSION) && !defined(Py_LIMITED_API)) static PyObject * test_config(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(args)) { @@ -2250,7 +2246,7 @@ test_config(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(args)) Py_DECREF(obj); // Get the last member -#if 0x030A0000 <= PY_VERSION_HEX +#if _Py_PACK_VERSION(3, 10) <= PY_VERSION_HEX obj = PyConfig_Get("warn_default_encoding"); #else obj = PyConfig_Get("user_site_directory"); @@ -2548,7 +2544,8 @@ test_try_incref(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(args)) } #endif // !PYPY_VERSION -#if 0x030D0000 <= PY_VERSION_HEX && !defined(PYPY_VERSION) && !defined(Py_LIMITED_API) +#if (_Py_PACK_VERSION(3, 13) <= PY_VERSION_HEX \ + && !defined(PYPY_VERSION) && !defined(Py_LIMITED_API)) static PyObject * test_set_immortal(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(args)) { @@ -2595,7 +2592,7 @@ test_type(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(args)) // Test PyType_GetModuleName() PyObject *modname = PyType_GetModuleName(type); assert(modname != NULL); -#if !defined(PYPY_VERSION) || PY_VERSION_HEX < 0x030C0000 +#if !defined(PYPY_VERSION) || PY_VERSION_HEX < _Py_PACK_VERSION(3, 12) assert(PyUnicode_EqualToUTF8(modname, "datetime") == 1); #else assert(PyUnicode_EqualToUTF8(modname, "_pydatetime") == 1); @@ -2617,7 +2614,7 @@ test_type(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(args)) // Test PyType_GetFullyQualifiedName() PyObject *fqn = PyType_GetFullyQualifiedName(type); assert(fqn != NULL); -#if !defined(PYPY_VERSION) || PY_VERSION_HEX < 0x030C0000 +#if !defined(PYPY_VERSION) || PY_VERSION_HEX < _Py_PACK_VERSION(3, 12) assert(PyUnicode_EqualToUTF8(fqn, "datetime.time") == 1); #else assert(PyUnicode_EqualToUTF8(fqn, "_pydatetime.time") == 1); @@ -2632,21 +2629,20 @@ test_type(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(args)) static struct PyMethodDef methods[] = { {"test_object", test_object, METH_NOARGS, _Py_NULL}, {"test_py_is", test_py_is, METH_NOARGS, _Py_NULL}, -#if ((!defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03090000) \ - && !defined(PYPY_VERSION)) +#if ((!defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= _Py_PACK_VERSION(3, 9)) \ + && !defined(PYPY_VERSION)) {"test_frame", test_frame, METH_NOARGS, _Py_NULL}, #endif -#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03090000 +#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= _Py_PACK_VERSION(3, 9) {"test_thread_state", test_thread_state, METH_NOARGS, _Py_NULL}, #endif {"test_interpreter", test_interpreter, METH_NOARGS, _Py_NULL}, {"test_calls", test_calls, METH_NOARGS, _Py_NULL}, -#if !(defined(Py_LIMITED_API) && PY_VERSION_HEX < 0x030A0000) && !defined(PYPY_VERSION) +#if !(defined(Py_LIMITED_API) && PY_VERSION_HEX < _Py_PACK_VERSION(3, 10)) && !defined(PYPY_VERSION) {"test_gc", test_gc, METH_NOARGS, _Py_NULL}, #endif {"test_module", test_module, METH_NOARGS, _Py_NULL}, -#if ((PY_VERSION_HEX <= 0x030B00A1 || 0x030B00A7 <= PY_VERSION_HEX) \ - && !defined(PYPY_VERSION) && !defined(Py_LIMITED_API)) +#if !defined(PYPY_VERSION) && !defined(Py_LIMITED_API) {"test_float_pack", test_float_pack, METH_NOARGS, _Py_NULL}, #endif #if !defined(PYPY_VERSION) && !defined(Py_LIMITED_API) @@ -2656,9 +2652,7 @@ static struct PyMethodDef methods[] = { {"test_import", test_import, METH_NOARGS, _Py_NULL}, {"test_weakref", test_weakref, METH_NOARGS, _Py_NULL}, {"func_varargs", (PyCFunction)(void*)func_varargs, METH_VARARGS | METH_KEYWORDS, _Py_NULL}, -#if !(defined(Py_LIMITED_API) && PY_VERSION_HEX < 0x030C0000) {"test_vectorcall", test_vectorcall, METH_NOARGS, _Py_NULL}, -#endif {"test_getattr", test_getattr, METH_NOARGS, _Py_NULL}, {"test_getitem", test_getitem, METH_NOARGS, _Py_NULL}, {"test_dict_api", test_dict_api, METH_NOARGS, _Py_NULL}, @@ -2681,13 +2675,13 @@ static struct PyMethodDef methods[] = { {"test_unicodewriter_format", test_unicodewriter_format, METH_NOARGS, _Py_NULL}, #endif {"test_bytes", test_bytes, METH_NOARGS, _Py_NULL}, -#if !(defined(Py_LIMITED_API) && PY_VERSION_HEX < 0x030A0000) +#if !(defined(Py_LIMITED_API) && PY_VERSION_HEX < _Py_PACK_VERSION(3, 10)) {"test_iter", test_iter, METH_NOARGS, _Py_NULL}, #endif {"test_long_stdint", test_long_stdint, METH_NOARGS, _Py_NULL}, {"test_structmember", test_structmember, METH_NOARGS, _Py_NULL}, {"test_file", test_file, METH_NOARGS, _Py_NULL}, -#if 0x03090000 <= PY_VERSION_HEX && !defined(PYPY_VERSION) && !defined(Py_LIMITED_API) +#if _Py_PACK_VERSION(3, 9) <= PY_VERSION_HEX && !defined(PYPY_VERSION) && !defined(Py_LIMITED_API) {"test_config", test_config, METH_NOARGS, _Py_NULL}, #endif {"test_sys", test_sys, METH_NOARGS, _Py_NULL}, @@ -2701,7 +2695,7 @@ static struct PyMethodDef methods[] = { #if !defined(PYPY_VERSION) && !defined(Py_LIMITED_API) {"test_try_incref", test_try_incref, METH_NOARGS, _Py_NULL}, #endif -#if 0x030D0000 <= PY_VERSION_HEX && !defined(PYPY_VERSION) && !defined(Py_LIMITED_API) +#if _Py_PACK_VERSION(3, 13) <= PY_VERSION_HEX && !defined(PYPY_VERSION) && !defined(Py_LIMITED_API) {"test_set_immortal", test_set_immortal, METH_NOARGS, _Py_NULL}, #endif {"test_type", test_type, METH_NOARGS, _Py_NULL}, @@ -2752,8 +2746,8 @@ module_exec(PyObject *module) // On Python 3.15 and newer, use PySlot API -#if (PY_VERSION_HEX >= 0x030F0000 \ - && (!defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030F0000)) +#if (PY_VERSION_HEX >= _Py_PACK_VERSION(3, 15) \ + && (!defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= _Py_PACK_VERSION(3, 15))) PyABIInfo_VAR(abi_info); @@ -2789,11 +2783,11 @@ INIT_FUNC(void) } #endif -#elif !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000 +#elif !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= _Py_PACK_VERSION(3, 5) static PyModuleDef_Slot module_slots[] = { {Py_mod_exec, _Py_CAST(void*, module_exec)}, -#if PY_VERSION_HEX >= 0x030D0000 +#if PY_VERSION_HEX >= _Py_PACK_VERSION(3, 13) {Py_mod_gil, Py_MOD_GIL_NOT_USED}, #endif {0, _Py_NULL} @@ -2853,4 +2847,4 @@ INIT_FUNC(void) return module; } -#endif // defined(Py_LIMITED_API) && Py_LIMITED_API+0 < 0x03050000 +#endif // defined(Py_LIMITED_API) && Py_LIMITED_API+0 < _Py_PACK_VERSION(3, 5)