From 5b669e9524e6c7fa0cbcacd9662fa2adde9b520a Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Sat, 12 Mar 2022 00:33:53 +0100 Subject: [PATCH] Fix Python 3.11a2-3.11a6 --- pythoncapi_compat.h | 11 ++++++++--- tests/test_pythoncapi_compat_cext.c | 17 +++-------------- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/pythoncapi_compat.h b/pythoncapi_compat.h index 1d08b20..2837467 100644 --- a/pythoncapi_compat.h +++ b/pythoncapi_compat.h @@ -391,9 +391,11 @@ _Py_IS_TYPE(const PyObject *ob, const PyTypeObject *type) { #endif -// bpo-11734 added _PyFloat_Pack2() and _PyFloat_Unpack2() to Python 3.6.0b1. // bpo-46906 added PyFloat_Pack2() and PyFloat_Unpack2() to Python 3.11a7. -#if 0x030600B1 <= PY_VERSION_HEX && PY_VERSION_HEX < 0x030B00A7 && !defined(PYPY_VERSION) +// 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 0x030600B1 <= PY_VERSION_HEX && PY_VERSION_HEX <= 0x030B00A1 && !defined(PYPY_VERSION) PYCAPI_COMPAT_STATIC_INLINE(int) PyFloat_Pack2(double x, char *p, int le) { return _PyFloat_Pack2(x, (unsigned char*)p, le); } @@ -406,7 +408,10 @@ PyFloat_Unpack2(const char *p, int le) // bpo-46906 added PyFloat_Pack4(), PyFloat_Pack8(), PyFloat_Unpack4() and // PyFloat_Unpack8() to Python 3.11a7. -#if PY_VERSION_HEX < 0x030B00A7 && !defined(PYPY_VERSION) +// 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) PYCAPI_COMPAT_STATIC_INLINE(int) PyFloat_Pack4(double x, char *p, int le) { return _PyFloat_Pack4(x, (unsigned char*)p, le); } diff --git a/tests/test_pythoncapi_compat_cext.c b/tests/test_pythoncapi_compat_cext.c index ecbb8a1..fa1483c 100644 --- a/tests/test_pythoncapi_compat_cext.c +++ b/tests/test_pythoncapi_compat_cext.c @@ -1,17 +1,6 @@ // Always enable assertions #undef NDEBUG -// In Python 3.11a2-3.11a6, _PyFloat_Pack8() is part of the internal C API: -// pythoncapi_compat.h doesn't support these early alpha versions. Workaround -// the issue to be able to test pythoncapi_compat.h on these unsupported Python -// versions anyway. -#include "Python.h" -#if (0x030B00A2 <= PY_VERSION_HEX && PY_VERSION_HEX <= 0x030B00A6) && !defined(PYPY_VERSION) -# define Py_BUILD_CORE 1 -# include "internal/pycore_floatobject.h" -# undef Py_BUILD_CORE -#endif - #include "pythoncapi_compat.h" #ifdef Py_LIMITED_API @@ -417,7 +406,7 @@ test_module(PyObject *Py_UNUSED(module), PyObject* Py_UNUSED(ignored)) } -#ifndef PYPY_VERSION +#if (PY_VERSION_HEX <= 0x030B00A1 || 0x030B00A7 <= PY_VERSION_HEX) && !defined(PYPY_VERSION) static PyObject * test_float_pack(PyObject *Py_UNUSED(module), PyObject* Py_UNUSED(ignored)) { @@ -470,7 +459,7 @@ test_float_pack(PyObject *Py_UNUSED(module), PyObject* Py_UNUSED(ignored)) Py_RETURN_NONE; } -#endif // !PYPY_VERSION +#endif static struct PyMethodDef methods[] = { @@ -485,7 +474,7 @@ static struct PyMethodDef methods[] = { {"test_calls", test_calls, METH_NOARGS, NULL}, {"test_gc", test_gc, METH_NOARGS, NULL}, {"test_module", test_module, METH_NOARGS, NULL}, -#ifndef PYPY_VERSION +#if (PY_VERSION_HEX <= 0x030B00A1 || 0x030B00A7 <= PY_VERSION_HEX) && !defined(PYPY_VERSION) {"test_float_pack", test_float_pack, METH_NOARGS, NULL}, #endif {NULL, NULL, 0, NULL}