:c:func:`PyThreadState_Clear`.
- .. c:function:: void PyThreadState_DeleteCurrent()
+.. c:function:: void PyThreadState_DeleteCurrent(void)
- Destroy the current thread state and release the global interpreter lock.
- Like :c:func:`PyThreadState_Delete`, the global interpreter lock need not
- be held. The thread state must have been reset with a previous call
- to :c:func:`PyThreadState_Clear`.
+ Destroy the current thread state and release the global interpreter lock.
+ Like :c:func:`PyThreadState_Delete`, the global interpreter lock need not
+ be held. The thread state must have been reset with a previous call
+ to :c:func:`PyThreadState_Clear`.
+
+
+.. c:function:: PyInterpreterState* PyThreadState_GetInterpreter(PyThreadState *tstate)
+
+ Get the interpreter of the Python thread state *tstate*.
+
+ *tstate* must not be ``NULL``.
+
+ .. versionadded:: 3.9
.. c:function:: PyInterpreterState* PyInterpreterState_Get(void)
Build and C API Changes
=======================
-* New :c:func:`PyInterpreterState_Get` function.
+* New :c:func:`PyThreadState_GetInterpreter` and
+ :c:func:`PyInterpreterState_Get` functions to get the interpreter.
* Add ``--with-platlibdir`` option to the ``configure`` script: name of the
platform-specific library directory, stored in the new :attr:`sys.platlibdir`
PyAPI_FUNC(PyObject *) PyThreadState_GetDict(void);
PyAPI_FUNC(int) PyThreadState_SetAsyncExc(unsigned long, PyObject *);
+#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03090000
+/* New in 3.9 */
+PyAPI_FUNC(PyInterpreterState *) PyThreadState_GetInterpreter(PyThreadState *tstate);
+#endif
+
typedef
enum {PyGILState_LOCKED, PyGILState_UNLOCKED}
PyGILState_STATE;
--- /dev/null
+Add :c:func:`PyThreadState_GetInterpreter`: get the interpreter of a Python
+thread state.
Py_XSETREF(fatal_error.file, file);
fatal_error.fd = fd;
fatal_error.all_threads = all_threads;
- fatal_error.interp = tstate->interp;
+ fatal_error.interp = PyThreadState_GetInterpreter(tstate);
if (faulthandler_enable() < 0) {
return NULL;
/* the downcast is safe: we check that 0 < timeout_us < PY_TIMEOUT_MAX */
thread.timeout_us = (PY_TIMEOUT_T)timeout_us;
thread.repeat = repeat;
- thread.interp = tstate->interp;
+ thread.interp = PyThreadState_GetInterpreter(tstate);
thread.exit = exit;
thread.header = header;
thread.header_len = header_len;
user->fd = fd;
user->all_threads = all_threads;
user->chain = chain;
- user->interp = tstate->interp;
+ user->interp = PyThreadState_GetInterpreter(tstate);
user->enabled = 1;
Py_RETURN_NONE;
}
+PyInterpreterState *
+PyThreadState_GetInterpreter(PyThreadState *tstate)
+{
+ assert(tstate != NULL);
+ if (tstate == NULL) {
+ return NULL;
+ }
+ return tstate->interp;
+}
+
+
/* Asynchronously raise an exception in a thread.
Requested by Just van Rossum and Alex Martelli.
To prevent naive misuse, you must write your own extension