Skip to content

Commit 17c68b8

Browse files
authored
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.
1 parent ec3c99c commit 17c68b8

File tree

2 files changed

+5
-11
lines changed

2 files changed

+5
-11
lines changed

Doc/c-api/init.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1110,7 +1110,7 @@ All of the following functions must be called after :c:func:`Py_Initialize`.
11101110
.. c:function:: void PyEval_AcquireThread(PyThreadState *tstate)
11111111
11121112
Acquire the global interpreter lock and set the current thread state to
1113-
*tstate*, which should not be ``NULL``. The lock must have been created earlier.
1113+
*tstate*, which must not be ``NULL``. The lock must have been created earlier.
11141114
If this thread already has the lock, deadlock ensues.
11151115
11161116
.. note::

Python/ceval.c

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -302,9 +302,7 @@ PyEval_ReleaseLock(void)
302302
void
303303
PyEval_AcquireThread(PyThreadState *tstate)
304304
{
305-
if (tstate == NULL) {
306-
Py_FatalError("PyEval_AcquireThread: NULL new thread state");
307-
}
305+
assert(tstate != NULL);
308306

309307
_PyRuntimeState *runtime = tstate->interp->runtime;
310308
struct _ceval_runtime_state *ceval = &runtime->ceval;
@@ -321,9 +319,7 @@ PyEval_AcquireThread(PyThreadState *tstate)
321319
void
322320
PyEval_ReleaseThread(PyThreadState *tstate)
323321
{
324-
if (tstate == NULL) {
325-
Py_FatalError("PyEval_ReleaseThread: NULL thread state");
326-
}
322+
assert(tstate != NULL);
327323

328324
_PyRuntimeState *runtime = tstate->interp->runtime;
329325
PyThreadState *new_tstate = _PyThreadState_Swap(&runtime->gilstate, NULL);
@@ -385,12 +381,10 @@ PyEval_SaveThread(void)
385381
void
386382
PyEval_RestoreThread(PyThreadState *tstate)
387383
{
384+
assert(tstate != NULL);
385+
388386
_PyRuntimeState *runtime = tstate->interp->runtime;
389387
struct _ceval_runtime_state *ceval = &runtime->ceval;
390-
391-
if (tstate == NULL) {
392-
Py_FatalError("PyEval_RestoreThread: NULL tstate");
393-
}
394388
assert(gil_created(&ceval->gil));
395389

396390
int err = errno;

0 commit comments

Comments
 (0)