Skip to content

Commit

Permalink
Add PyThreadState_EnterTracing()
Browse files Browse the repository at this point in the history
runtests.py: add Python 3.11
  • Loading branch information
vstinner committed Oct 15, 2021
1 parent 764b856 commit 48d283e
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 2 deletions.
11 changes: 10 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 16 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,20 @@ 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
int PyThreadState_IsTracing(PyThreadState *tstate);
// Not available on PyPy
void PyThreadState_EnterTracing(PyThreadState *tstate);
// Not available on PyPy
void PyThreadState_LeaveTracing(PyThreadState *tstate);

Python 3.10
-----------
Expand Down Expand Up @@ -337,6 +350,8 @@ Links
Changelog
=========

* 2021-10-15: Add PyThreadState_EnterTracing(), PyThreadState_LeaveTracing()
and PyThreadState_IsTracing().
* 2021-04-09: Add Py_Is(), Py_IsNone(), Py_IsTrue(), Py_IsFalse() functions.
* 2021-04-01:

Expand Down
40 changes: 40 additions & 0 deletions pythoncapi_compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,46 @@ PyThreadState_GetID(PyThreadState *tstate)
}
#endif

// bpo-43760 added PyThreadState_IsTracing() to Python 3.11.0a2
#if PY_VERSION_HEX < 0x030B00A2 && !defined(PYPY_VERSION)
static inline int PyThreadState_IsTracing(PyThreadState *tstate)
{
#if PY_VERSION_HEX >= 0x030A00A1
return (tstate->cframe->use_tracing != 0);
#else
return (tstate->use_tracing != 0);
#endif
}
#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
Expand Down
1 change: 1 addition & 0 deletions runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"python3.8",
"python3.9",
"python3.10",
"python3.11",
"python3",
"python3-debug",
"pypy",
Expand Down
8 changes: 8 additions & 0 deletions tests/test_pythoncapi_compat_cext.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,14 @@ test_thread_state(PyObject *Py_UNUSED(module), PyObject* Py_UNUSED(ignored))
assert(id > 0);
#endif

#if !defined(PYPY_VERSION)
// PyThreadState_IsTracing(), PyThreadState_EnterTracing(),
// PyThreadState_LeaveTracing()
PyThreadState_EnterTracing(tstate);
assert(PyThreadState_IsTracing(tstate) == 0);
PyThreadState_LeaveTracing(tstate);
#endif

Py_RETURN_NONE;
}

Expand Down

0 comments on commit 48d283e

Please sign in to comment.