Skip to content

Commit

Permalink
Add PyThreadState_GetUnchecked() (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
vstinner committed Oct 3, 2023
1 parent a594354 commit f78c780
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
6 changes: 6 additions & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ Python 3.13
See `PyObject_ClearManagedDict() documentation <https://docs.python.org/dev/c-api/object.html#c.PyObject_ClearManagedDict>`__.
.. c:function:: PyThreadState* PyThreadState_GetUnchecked(void)
See `PyThreadState_GetUnchecked() documentation <https://docs.python.org/dev/c-api/init.html#c.PyThreadState_GetUnchecked>`__.
Available on Python 3.5.2 and newer.
Python 3.12
-----------
Expand Down
8 changes: 6 additions & 2 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
Changelog
=========

* 2023-10-03: Add ``PyObject_VisitManagedDict()`` and
``PyObject_ClearManagedDict()`` functions.
* 2023-10-03: Add functions:

* ``PyObject_VisitManagedDict()``
* ``PyObject_ClearManagedDict()``
* ``PyThreadState_GetUnchecked()``

* 2023-09-29: Add functions:

* ``PyMapping_HasKeyWithError()``
Expand Down
10 changes: 10 additions & 0 deletions pythoncapi_compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,16 @@ PyObject_ClearManagedDict(PyObject *obj)
}
#endif

// gh-108867 added PyThreadState_GetUnchecked() to Python 3.13.0a1
// Python 3.5.2 added _PyThreadState_UncheckedGet().
#if PY_VERSION_HEX >= 0x03050200 && PY_VERSION_HEX < 0x030D00A1
static inline PyThreadState*
PyThreadState_GetUnchecked(void)
{
return _PyThreadState_UncheckedGet();
}
#endif


#ifdef __cplusplus
}
Expand Down
5 changes: 5 additions & 0 deletions tests/test_pythoncapi_compat_cext.c
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,11 @@ test_thread_state(PyObject *Py_UNUSED(module), PyObject* Py_UNUSED(ignored))
PyThreadState_LeaveTracing(tstate);
#endif

#if PY_VERSION_HEX >= 0x03050200
// PyThreadState_GetUnchecked()
assert(PyThreadState_GetUnchecked() == tstate);
#endif

Py_RETURN_NONE;
}

Expand Down

0 comments on commit f78c780

Please sign in to comment.