diff options
author | Victor Stinner <vstinner@python.org> | 2020-06-01 14:02:40 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-01 14:02:40 (GMT) |
commit | 3026cad59b87751a9215111776cac8e819458fce (patch) | |
tree | b994018d331ca9f01f58ebd1a3d05c4f3aa1cdc0 /Python/ceval.c | |
parent | db64f12e4deda2abbafb6d2bd5c06762fca991ff (diff) | |
download | cpython-3026cad59b87751a9215111776cac8e819458fce.zip cpython-3026cad59b87751a9215111776cac8e819458fce.tar.gz cpython-3026cad59b87751a9215111776cac8e819458fce.tar.bz2 |
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.
Diffstat (limited to 'Python/ceval.c')
-rw-r--r-- | Python/ceval.c | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/Python/ceval.c b/Python/ceval.c index a79773f..01dd361 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -240,16 +240,15 @@ 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)"); } - #ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS int _PyEval_ThreadsInitialized(PyInterpreterState *interp) @@ -374,7 +373,7 @@ PyEval_AcquireLock(void) { _PyRuntimeState *runtime = &_PyRuntime; PyThreadState *tstate = _PyRuntimeState_GetThreadState(runtime); - ensure_tstate_not_null(__func__, tstate); + _Py_EnsureTstateNotNULL(tstate); take_gil(tstate); } @@ -403,7 +402,7 @@ _PyEval_ReleaseLock(PyThreadState *tstate) void PyEval_AcquireThread(PyThreadState *tstate) { - ensure_tstate_not_null(__func__, tstate); + _Py_EnsureTstateNotNULL(tstate); take_gil(tstate); @@ -442,7 +441,7 @@ void _PyEval_ReInitThreads(_PyRuntimeState *runtime) { PyThreadState *tstate = _PyRuntimeState_GetThreadState(runtime); - ensure_tstate_not_null(__func__, tstate); + _Py_EnsureTstateNotNULL(tstate); #ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS struct _gil_runtime_state *gil = &tstate->interp->ceval.gil; @@ -486,7 +485,7 @@ PyEval_SaveThread(void) #else PyThreadState *tstate = _PyThreadState_Swap(&runtime->gilstate, NULL); #endif - ensure_tstate_not_null(__func__, tstate); + _Py_EnsureTstateNotNULL(tstate); struct _ceval_runtime_state *ceval = &runtime->ceval; struct _ceval_state *ceval2 = &tstate->interp->ceval; @@ -502,7 +501,7 @@ PyEval_SaveThread(void) void PyEval_RestoreThread(PyThreadState *tstate) { - ensure_tstate_not_null(__func__, tstate); + _Py_EnsureTstateNotNULL(tstate); take_gil(tstate); @@ -944,7 +943,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; |