Skip to content

Commit e28f16e

Browse files
committed
Add PyThreadState_EnterTracing()
* runtests.py: add Python 3.11 * GitHub Action: add "nightly" version
1 parent 764b856 commit e28f16e

File tree

5 files changed

+76
-2
lines changed

5 files changed

+76
-2
lines changed

.github/workflows/build.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,17 @@ 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+
- "nightly"
25+
- "pypy2"
26+
- "pypy3"
1727
include:
1828
- os: windows-latest
1929
python: 3.6

README.rst

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,20 @@ 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+
int PyThreadState_IsTracing(PyThreadState *tstate);
169+
// Not available on PyPy
170+
void PyThreadState_EnterTracing(PyThreadState *tstate);
171+
// Not available on PyPy
172+
void PyThreadState_LeaveTracing(PyThreadState *tstate);
160173

161174
Python 3.10
162175
-----------
@@ -337,6 +350,8 @@ Links
337350
Changelog
338351
=========
339352

353+
* 2021-10-15: Add PyThreadState_EnterTracing(), PyThreadState_LeaveTracing()
354+
and PyThreadState_IsTracing().
340355
* 2021-04-09: Add Py_Is(), Py_IsNone(), Py_IsTrue(), Py_IsFalse() functions.
341356
* 2021-04-01:
342357

pythoncapi_compat.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,46 @@ PyThreadState_GetID(PyThreadState *tstate)
251251
}
252252
#endif
253253

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

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

runtests.py

Lines changed: 1 addition & 0 deletions
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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,14 @@ 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_IsTracing(), PyThreadState_EnterTracing(),
233+
// PyThreadState_LeaveTracing()
234+
PyThreadState_EnterTracing(tstate);
235+
assert(PyThreadState_IsTracing(tstate) == 0);
236+
PyThreadState_LeaveTracing(tstate);
237+
#endif
238+
231239
Py_RETURN_NONE;
232240
}
233241

0 commit comments

Comments
 (0)