Skip to content

Commit

Permalink
Fix Python 3.11a2-3.11a6
Browse files Browse the repository at this point in the history
  • Loading branch information
vstinner committed Mar 11, 2022
1 parent c7d3657 commit 5b669e9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
11 changes: 8 additions & 3 deletions pythoncapi_compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -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); }
Expand All @@ -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); }
Expand Down
17 changes: 3 additions & 14 deletions tests/test_pythoncapi_compat_cext.c
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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))
{
Expand Down Expand Up @@ -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[] = {
Expand All @@ -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}
Expand Down

0 comments on commit 5b669e9

Please sign in to comment.