mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
[3.9] bpo-40826: PyOS_InterruptOccurred() requires GIL (GH-20578) (GH-20618)
* bpo-40826: Add _Py_EnsureTstateNotNULL() macro (GH-20571) Add _Py_EnsureTstateNotNULL(tstate) macro: call Py_FatalError() if tstate is NULL, the error message contains the current function name. (cherry picked from commit3026cad59b
) * bpo-40826: PyOS_InterruptOccurred() requires GIL (GH-20578) PyOS_InterruptOccurred() now fails with a fatal error if it is called with the GIL released. (cherry picked from commitcbe1296922
)
This commit is contained in:
parent
5d2396c8cf
commit
6d62dc1ea4
8 changed files with 43 additions and 31 deletions
|
@ -240,13 +240,13 @@ UNSIGNAL_ASYNC_EXC(PyInterpreterState *interp)
|
|||
#endif
|
||||
#include "ceval_gil.h"
|
||||
|
||||
static void
|
||||
ensure_tstate_not_null(const char *func, PyThreadState *tstate)
|
||||
void _Py_NO_RETURN
|
||||
_Py_FatalError_TstateNULL(const char *func)
|
||||
{
|
||||
if (tstate == NULL) {
|
||||
_Py_FatalErrorFunc(func,
|
||||
"current thread state is NULL (released GIL?)");
|
||||
}
|
||||
_Py_FatalErrorFunc(func,
|
||||
"the function must be called with the GIL held, "
|
||||
"but the GIL is released "
|
||||
"(the current Python thread state is NULL)");
|
||||
}
|
||||
|
||||
|
||||
|
@ -346,7 +346,7 @@ PyEval_AcquireLock(void)
|
|||
{
|
||||
_PyRuntimeState *runtime = &_PyRuntime;
|
||||
PyThreadState *tstate = _PyRuntimeState_GetThreadState(runtime);
|
||||
ensure_tstate_not_null(__func__, tstate);
|
||||
_Py_EnsureTstateNotNULL(tstate);
|
||||
|
||||
take_gil(tstate);
|
||||
}
|
||||
|
@ -375,7 +375,7 @@ _PyEval_ReleaseLock(PyThreadState *tstate)
|
|||
void
|
||||
PyEval_AcquireThread(PyThreadState *tstate)
|
||||
{
|
||||
ensure_tstate_not_null(__func__, tstate);
|
||||
_Py_EnsureTstateNotNULL(tstate);
|
||||
|
||||
take_gil(tstate);
|
||||
|
||||
|
@ -410,7 +410,7 @@ void
|
|||
_PyEval_ReInitThreads(_PyRuntimeState *runtime)
|
||||
{
|
||||
PyThreadState *tstate = _PyRuntimeState_GetThreadState(runtime);
|
||||
ensure_tstate_not_null(__func__, tstate);
|
||||
_Py_EnsureTstateNotNULL(tstate);
|
||||
|
||||
struct _gil_runtime_state *gil = &runtime->ceval.gil;
|
||||
if (!gil_created(gil)) {
|
||||
|
@ -445,7 +445,7 @@ PyEval_SaveThread(void)
|
|||
{
|
||||
_PyRuntimeState *runtime = &_PyRuntime;
|
||||
PyThreadState *tstate = _PyThreadState_Swap(&runtime->gilstate, NULL);
|
||||
ensure_tstate_not_null(__func__, tstate);
|
||||
_Py_EnsureTstateNotNULL(tstate);
|
||||
|
||||
struct _ceval_runtime_state *ceval = &runtime->ceval;
|
||||
struct _ceval_state *ceval2 = &tstate->interp->ceval;
|
||||
|
@ -457,7 +457,7 @@ PyEval_SaveThread(void)
|
|||
void
|
||||
PyEval_RestoreThread(PyThreadState *tstate)
|
||||
{
|
||||
ensure_tstate_not_null(__func__, tstate);
|
||||
_Py_EnsureTstateNotNULL(tstate);
|
||||
|
||||
take_gil(tstate);
|
||||
|
||||
|
@ -889,7 +889,7 @@ eval_frame_handle_pending(PyThreadState *tstate)
|
|||
PyObject* _Py_HOT_FUNCTION
|
||||
_PyEval_EvalFrameDefault(PyThreadState *tstate, PyFrameObject *f, int throwflag)
|
||||
{
|
||||
ensure_tstate_not_null(__func__, tstate);
|
||||
_Py_EnsureTstateNotNULL(tstate);
|
||||
|
||||
#ifdef DXPAIRS
|
||||
int lastopcode = 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue