Skip to content

Commit 10fde24

Browse files
committed
Add PyThreadState_EnterTracing() and PyThreadState_LeaveTracing()
Add PyThreadState_EnterTracing() and PyThreadState_LeaveTracing() functions. runtests.py: add Python 3.11
1 parent 764b856 commit 10fde24

File tree

5 files changed

+59
-2
lines changed

5 files changed

+59
-2
lines changed

.github/workflows/build.yml

+10-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,16 @@ jobs:
1313
matrix:
1414
os: [ubuntu-latest]
1515
# 2020-03-30: use "3.10.0-alpha - 3.10" to get Python 3.10 alpha
16-
python: [2.7, 3.5, 3.6, 3.7, 3.8, 3.9, "3.10.0-alpha - 3.10", "pypy2", "pypy3"]
16+
python:
17+
- "2.7"
18+
- "3.5"
19+
- "3.6"
20+
- "3.7"
21+
- "3.8"
22+
- "3.9"
23+
- "3.10"
24+
- "pypy2"
25+
- "pypy3"
1726
include:
1827
- os: windows-latest
1928
python: 3.6

README.rst

+14-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,18 @@ Upgrade Operations
156156
pythoncapi_compat.h functions
157157
=============================
158158

159-
Some functions related to frame objects are not available on PyPy.
159+
Some functions related to frame objects and ``PyThreadState`` are not available
160+
on PyPy.
161+
162+
Python 3.11
163+
-----------
164+
165+
::
166+
167+
// Not available on PyPy
168+
void PyThreadState_EnterTracing(PyThreadState *tstate);
169+
// Not available on PyPy
170+
void PyThreadState_LeaveTracing(PyThreadState *tstate);
160171

161172
Python 3.10
162173
-----------
@@ -337,6 +348,8 @@ Links
337348
Changelog
338349
=========
339350

351+
* 2021-10-15: Add PyThreadState_EnterTracing() and
352+
PyThreadState_LeaveTracing().
340353
* 2021-04-09: Add Py_Is(), Py_IsNone(), Py_IsTrue(), Py_IsFalse() functions.
341354
* 2021-04-01:
342355

pythoncapi_compat.h

+28
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,34 @@ PyThreadState_GetID(PyThreadState *tstate)
251251
}
252252
#endif
253253

254+
// bpo-43760 added PyThreadState_EnterTracing() to Python 3.11.0a2
255+
#if PY_VERSION_HEX < 0x030B00A2 && !defined(PYPY_VERSION)
256+
static inline void PyThreadState_EnterTracing(PyThreadState *tstate)
257+
{
258+
tstate->tracing++;
259+
#if PY_VERSION_HEX >= 0x030A00A1
260+
tstate->cframe->use_tracing = 0;
261+
#else
262+
tstate->use_tracing = 0;
263+
#endif
264+
}
265+
#endif
266+
267+
// bpo-43760 added PyThreadState_LeaveTracing() to Python 3.11.0a2
268+
#if PY_VERSION_HEX < 0x030B00A2 && !defined(PYPY_VERSION)
269+
static inline void PyThreadState_LeaveTracing(PyThreadState *tstate)
270+
{
271+
tstate->tracing--;
272+
int use_tracing = (tstate->c_tracefunc != NULL
273+
|| tstate->c_profilefunc != NULL);
274+
#if PY_VERSION_HEX >= 0x030A00A1
275+
tstate->cframe->use_tracing = use_tracing;
276+
#else
277+
tstate->use_tracing = use_tracing;
278+
#endif
279+
}
280+
#endif
281+
254282

255283
// bpo-37194 added PyObject_CallNoArgs() to Python 3.9.0a1
256284
#if PY_VERSION_HEX < 0x030900A1

runtests.py

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"python3.8",
3838
"python3.9",
3939
"python3.10",
40+
"python3.11",
4041
"python3",
4142
"python3-debug",
4243
"pypy",

tests/test_pythoncapi_compat_cext.c

+6
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,12 @@ test_thread_state(PyObject *Py_UNUSED(module), PyObject* Py_UNUSED(ignored))
228228
assert(id > 0);
229229
#endif
230230

231+
#if !defined(PYPY_VERSION)
232+
// PyThreadState_EnterTracing(), PyThreadState_LeaveTracing()
233+
PyThreadState_EnterTracing(tstate);
234+
PyThreadState_LeaveTracing(tstate);
235+
#endif
236+
231237
Py_RETURN_NONE;
232238
}
233239

0 commit comments

Comments
 (0)