diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 103c042..b2ffc34 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -13,7 +13,16 @@ jobs: matrix: os: [ubuntu-latest] # 2020-03-30: use "3.10.0-alpha - 3.10" to get Python 3.10 alpha - python: [2.7, 3.5, 3.6, 3.7, 3.8, 3.9, "3.10.0-alpha - 3.10", "pypy2", "pypy3"] + python: + - "2.7" + - "3.5" + - "3.6" + - "3.7" + - "3.8" + - "3.9" + - "3.10" + - "pypy2" + - "pypy3" include: - os: windows-latest python: 3.6 diff --git a/README.rst b/README.rst index 24992fe..e8bb1f2 100644 --- a/README.rst +++ b/README.rst @@ -156,7 +156,18 @@ Upgrade Operations pythoncapi_compat.h functions ============================= -Some functions related to frame objects are not available on PyPy. +Some functions related to frame objects and ``PyThreadState`` are not available +on PyPy. + +Python 3.11 +----------- + +:: + + // Not available on PyPy + void PyThreadState_EnterTracing(PyThreadState *tstate); + // Not available on PyPy + void PyThreadState_LeaveTracing(PyThreadState *tstate); Python 3.10 ----------- @@ -337,6 +348,8 @@ Links Changelog ========= +* 2021-10-15: Add PyThreadState_EnterTracing() and + PyThreadState_LeaveTracing(). * 2021-04-09: Add Py_Is(), Py_IsNone(), Py_IsTrue(), Py_IsFalse() functions. * 2021-04-01: diff --git a/pythoncapi_compat.h b/pythoncapi_compat.h index e1662b9..b4011d2 100644 --- a/pythoncapi_compat.h +++ b/pythoncapi_compat.h @@ -251,6 +251,34 @@ PyThreadState_GetID(PyThreadState *tstate) } #endif +// bpo-43760 added PyThreadState_EnterTracing() to Python 3.11.0a2 +#if PY_VERSION_HEX < 0x030B00A2 && !defined(PYPY_VERSION) +static inline void PyThreadState_EnterTracing(PyThreadState *tstate) +{ + tstate->tracing++; +#if PY_VERSION_HEX >= 0x030A00A1 + tstate->cframe->use_tracing = 0; +#else + tstate->use_tracing = 0; +#endif +} +#endif + +// bpo-43760 added PyThreadState_LeaveTracing() to Python 3.11.0a2 +#if PY_VERSION_HEX < 0x030B00A2 && !defined(PYPY_VERSION) +static inline void PyThreadState_LeaveTracing(PyThreadState *tstate) +{ + tstate->tracing--; + int use_tracing = (tstate->c_tracefunc != NULL + || tstate->c_profilefunc != NULL); +#if PY_VERSION_HEX >= 0x030A00A1 + tstate->cframe->use_tracing = use_tracing; +#else + tstate->use_tracing = use_tracing; +#endif +} +#endif + // bpo-37194 added PyObject_CallNoArgs() to Python 3.9.0a1 #if PY_VERSION_HEX < 0x030900A1 diff --git a/runtests.py b/runtests.py index d4cf57b..0b6186c 100755 --- a/runtests.py +++ b/runtests.py @@ -37,6 +37,7 @@ "python3.8", "python3.9", "python3.10", + "python3.11", "python3", "python3-debug", "pypy", diff --git a/tests/test_pythoncapi_compat_cext.c b/tests/test_pythoncapi_compat_cext.c index 147bf46..a5fabf1 100644 --- a/tests/test_pythoncapi_compat_cext.c +++ b/tests/test_pythoncapi_compat_cext.c @@ -228,6 +228,12 @@ test_thread_state(PyObject *Py_UNUSED(module), PyObject* Py_UNUSED(ignored)) assert(id > 0); #endif +#if !defined(PYPY_VERSION) + // PyThreadState_EnterTracing(), PyThreadState_LeaveTracing() + PyThreadState_EnterTracing(tstate); + PyThreadState_LeaveTracing(tstate); +#endif + Py_RETURN_NONE; }