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.
diff --git a/Python/errors.c b/Python/errors.c
index 70365aa..5d17256 100644
--- a/Python/errors.c
+++ b/Python/errors.c
@@ -1426,7 +1426,7 @@
_PyErr_WriteUnraisableMsg(const char *err_msg_str, PyObject *obj)
{
PyThreadState *tstate = _PyThreadState_GET();
- assert(tstate != NULL);
+ _Py_EnsureTstateNotNULL(tstate);
PyObject *err_msg = NULL;
PyObject *exc_type, *exc_value, *exc_tb;