diff options
author | Victor Stinner <vstinner@python.org> | 2020-06-01 16:02:40 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-01 16:02:40 +0200 |
commit | 3026cad59b87751a9215111776cac8e819458fce (patch) | |
tree | b994018d331ca9f01f58ebd1a3d05c4f3aa1cdc0 /Python/pystate.c | |
parent | db64f12e4deda2abbafb6d2bd5c06762fca991ff (diff) | |
download | cpython-3026cad59b87751a9215111776cac8e819458fce.tar.gz cpython-3026cad59b87751a9215111776cac8e819458fce.zip |
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/pystate.c')
-rw-r--r-- | Python/pystate.c | 18 |
1 files changed, 4 insertions, 14 deletions
diff --git a/Python/pystate.c b/Python/pystate.c index 119fe31a84b..f92c55e7471 100644 --- a/Python/pystate.c +++ b/Python/pystate.c @@ -39,16 +39,6 @@ extern "C" { _Py_atomic_store_relaxed(&(gilstate)->tstate_current, \ (uintptr_t)(value)) -static void -ensure_tstate_not_null(const char *func, PyThreadState *tstate) -{ - if (tstate == NULL) { - _Py_FatalErrorFunc(func, - "current thread state is NULL (released GIL?)"); - } -} - - /* Forward declarations */ static PyThreadState *_PyGILState_GetThisThreadState(struct _gilstate_runtime_state *gilstate); static void _PyThreadState_Delete(PyThreadState *tstate, int check_current); @@ -431,7 +421,7 @@ PyInterpreterState * PyInterpreterState_Get(void) { PyThreadState *tstate = _PyThreadState_GET(); - ensure_tstate_not_null(__func__, tstate); + _Py_EnsureTstateNotNULL(tstate); PyInterpreterState *interp = tstate->interp; if (interp == NULL) { Py_FatalError("no current interpreter"); @@ -846,7 +836,7 @@ static void tstate_delete_common(PyThreadState *tstate, struct _gilstate_runtime_state *gilstate) { - ensure_tstate_not_null(__func__, tstate); + _Py_EnsureTstateNotNULL(tstate); PyInterpreterState *interp = tstate->interp; if (interp == NULL) { Py_FatalError("NULL interpreter"); @@ -897,7 +887,7 @@ PyThreadState_Delete(PyThreadState *tstate) void _PyThreadState_DeleteCurrent(PyThreadState *tstate) { - ensure_tstate_not_null(__func__, tstate); + _Py_EnsureTstateNotNULL(tstate); struct _gilstate_runtime_state *gilstate = &tstate->interp->runtime->gilstate; tstate_delete_common(tstate, gilstate); _PyRuntimeGILState_SetThreadState(gilstate, NULL); @@ -975,7 +965,7 @@ PyThreadState * PyThreadState_Get(void) { PyThreadState *tstate = _PyThreadState_GET(); - ensure_tstate_not_null(__func__, tstate); + _Py_EnsureTstateNotNULL(tstate); return tstate; } |