]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-38631: Replace Py_FatalError() with assert() in ceval.c (GH-18279)
authorVictor Stinner <vstinner@python.org>
Thu, 30 Jan 2020 11:20:48 +0000 (12:20 +0100)
committerGitHub <noreply@github.com>
Thu, 30 Jan 2020 11:20:48 +0000 (12:20 +0100)
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.

Doc/c-api/init.rst
Python/ceval.c

index 8913dbfe249dcde76fe4e83e8ba7f13d024388c9..7ea48aec009c927f1ddba09c9edc43d891635014 100644 (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)
 
    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.
 
    .. note::
index 2770dc6d08dd230bab719ceaf1102b1293f02d32..2bf64eda4224af8fb0e47b9edc7228d0daecbe78 100644 (file)
@@ -302,9 +302,7 @@ PyEval_ReleaseLock(void)
 void
 PyEval_AcquireThread(PyThreadState *tstate)
 {
-    if (tstate == NULL) {
-        Py_FatalError("PyEval_AcquireThread: NULL new thread state");
-    }
+    assert(tstate != NULL);
 
     _PyRuntimeState *runtime = tstate->interp->runtime;
     struct _ceval_runtime_state *ceval = &runtime->ceval;
@@ -321,9 +319,7 @@ PyEval_AcquireThread(PyThreadState *tstate)
 void
 PyEval_ReleaseThread(PyThreadState *tstate)
 {
-    if (tstate == NULL) {
-        Py_FatalError("PyEval_ReleaseThread: NULL thread state");
-    }
+    assert(tstate != NULL);
 
     _PyRuntimeState *runtime = tstate->interp->runtime;
     PyThreadState *new_tstate = _PyThreadState_Swap(&runtime->gilstate, NULL);
@@ -385,12 +381,10 @@ PyEval_SaveThread(void)
 void
 PyEval_RestoreThread(PyThreadState *tstate)
 {
+    assert(tstate != NULL);
+
     _PyRuntimeState *runtime = tstate->interp->runtime;
     struct _ceval_runtime_state *ceval = &runtime->ceval;
-
-    if (tstate == NULL) {
-        Py_FatalError("PyEval_RestoreThread: NULL tstate");
-    }
     assert(gil_created(&ceval->gil));
 
     int err = errno;