bpo-38631: Replace Py_FatalError() with assert() in ceval.c (GH-18279)

Replace a few Py_FatalError() calls if tstate is NULL with
assert(tstate != NULL) in ceval.c.

PyEval_AcquireThread(), PyEval_ReleaseThread() and
PyEval_RestoreThread() must never be called with a NULL tstate.
This commit is contained in:
Victor Stinner 2020-01-30 12:20:48 +01:00 committed by GitHub
parent ec3c99c8a7
commit 17c68b8107
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 11 deletions

View File

@ -1110,7 +1110,7 @@ All of the following functions must be called after :c:func:`Py_Initialize`.
.. c:function:: void PyEval_AcquireThread(PyThreadState *tstate) .. c:function:: void PyEval_AcquireThread(PyThreadState *tstate)
Acquire the global interpreter lock and set the current thread state to Acquire the global interpreter lock and set the current thread state to
*tstate*, which should not be ``NULL``. The lock must have been created earlier. *tstate*, which must not be ``NULL``. The lock must have been created earlier.
If this thread already has the lock, deadlock ensues. If this thread already has the lock, deadlock ensues.
.. note:: .. note::

View File

@ -302,9 +302,7 @@ PyEval_ReleaseLock(void)
void void
PyEval_AcquireThread(PyThreadState *tstate) PyEval_AcquireThread(PyThreadState *tstate)
{ {
if (tstate == NULL) { assert(tstate != NULL);
Py_FatalError("PyEval_AcquireThread: NULL new thread state");
}
_PyRuntimeState *runtime = tstate->interp->runtime; _PyRuntimeState *runtime = tstate->interp->runtime;
struct _ceval_runtime_state *ceval = &runtime->ceval; struct _ceval_runtime_state *ceval = &runtime->ceval;
@ -321,9 +319,7 @@ PyEval_AcquireThread(PyThreadState *tstate)
void void
PyEval_ReleaseThread(PyThreadState *tstate) PyEval_ReleaseThread(PyThreadState *tstate)
{ {
if (tstate == NULL) { assert(tstate != NULL);
Py_FatalError("PyEval_ReleaseThread: NULL thread state");
}
_PyRuntimeState *runtime = tstate->interp->runtime; _PyRuntimeState *runtime = tstate->interp->runtime;
PyThreadState *new_tstate = _PyThreadState_Swap(&runtime->gilstate, NULL); PyThreadState *new_tstate = _PyThreadState_Swap(&runtime->gilstate, NULL);
@ -385,12 +381,10 @@ PyEval_SaveThread(void)
void void
PyEval_RestoreThread(PyThreadState *tstate) PyEval_RestoreThread(PyThreadState *tstate)
{ {
assert(tstate != NULL);
_PyRuntimeState *runtime = tstate->interp->runtime; _PyRuntimeState *runtime = tstate->interp->runtime;
struct _ceval_runtime_state *ceval = &runtime->ceval; struct _ceval_runtime_state *ceval = &runtime->ceval;
if (tstate == NULL) {
Py_FatalError("PyEval_RestoreThread: NULL tstate");
}
assert(gil_created(&ceval->gil)); assert(gil_created(&ceval->gil));
int err = errno; int err = errno;