Skip to content

Add PyThreadState_EnterTracing() #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
15 changes: 14 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
-----------
Expand Down Expand Up @@ -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:

Expand Down
28 changes: 28 additions & 0 deletions pythoncapi_compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
6 changes: 6 additions & 0 deletions tests/test_pythoncapi_compat_cext.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down