Skip to content

Commit f78c780

Browse files
authored
Add PyThreadState_GetUnchecked() (python#77)
1 parent a594354 commit f78c780

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed

docs/api.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,12 @@ Python 3.13
107107
108108
See `PyObject_ClearManagedDict() documentation <https://docs.python.org/dev/c-api/object.html#c.PyObject_ClearManagedDict>`__.
109109
110+
.. c:function:: PyThreadState* PyThreadState_GetUnchecked(void)
111+
112+
See `PyThreadState_GetUnchecked() documentation <https://docs.python.org/dev/c-api/init.html#c.PyThreadState_GetUnchecked>`__.
113+
114+
Available on Python 3.5.2 and newer.
115+
110116
111117
Python 3.12
112118
-----------

docs/changelog.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
Changelog
22
=========
33

4-
* 2023-10-03: Add ``PyObject_VisitManagedDict()`` and
5-
``PyObject_ClearManagedDict()`` functions.
4+
* 2023-10-03: Add functions:
5+
6+
* ``PyObject_VisitManagedDict()``
7+
* ``PyObject_ClearManagedDict()``
8+
* ``PyThreadState_GetUnchecked()``
9+
610
* 2023-09-29: Add functions:
711

812
* ``PyMapping_HasKeyWithError()``

pythoncapi_compat.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -929,6 +929,16 @@ PyObject_ClearManagedDict(PyObject *obj)
929929
}
930930
#endif
931931

932+
// gh-108867 added PyThreadState_GetUnchecked() to Python 3.13.0a1
933+
// Python 3.5.2 added _PyThreadState_UncheckedGet().
934+
#if PY_VERSION_HEX >= 0x03050200 && PY_VERSION_HEX < 0x030D00A1
935+
static inline PyThreadState*
936+
PyThreadState_GetUnchecked(void)
937+
{
938+
return _PyThreadState_UncheckedGet();
939+
}
940+
#endif
941+
932942

933943
#ifdef __cplusplus
934944
}

tests/test_pythoncapi_compat_cext.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,11 @@ test_thread_state(PyObject *Py_UNUSED(module), PyObject* Py_UNUSED(ignored))
318318
PyThreadState_LeaveTracing(tstate);
319319
#endif
320320

321+
#if PY_VERSION_HEX >= 0x03050200
322+
// PyThreadState_GetUnchecked()
323+
assert(PyThreadState_GetUnchecked() == tstate);
324+
#endif
325+
321326
Py_RETURN_NONE;
322327
}
323328

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy