gh-144748: Make PyErr_CheckSignals raise the exception scheduled by PyThreadState_SetAsyncExc (GH-145178)

Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
This commit is contained in:
Petr Viktorin 2026-03-02 11:47:32 +01:00 committed by GitHub
parent c9a5d9aae4
commit 3b276f3f59
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 138 additions and 18 deletions

View file

@ -1423,11 +1423,7 @@ _Py_HandlePending(PyThreadState *tstate)
/* Check for asynchronous exception. */
if ((breaker & _PY_ASYNC_EXCEPTION_BIT) != 0) {
_Py_unset_eval_breaker_bit(tstate, _PY_ASYNC_EXCEPTION_BIT);
PyObject *exc = _Py_atomic_exchange_ptr(&tstate->async_exc, NULL);
if (exc != NULL) {
_PyErr_SetNone(tstate, exc);
Py_DECREF(exc);
if (_PyEval_RaiseAsyncExc(tstate) < 0) {
return -1;
}
}
@ -1438,3 +1434,18 @@ _Py_HandlePending(PyThreadState *tstate)
return 0;
}
int
_PyEval_RaiseAsyncExc(PyThreadState *tstate)
{
assert(tstate != NULL);
assert(tstate == _PyThreadState_GET());
_Py_unset_eval_breaker_bit(tstate, _PY_ASYNC_EXCEPTION_BIT);
PyObject *exc = _Py_atomic_exchange_ptr(&tstate->async_exc, NULL);
if (exc != NULL) {
_PyErr_SetNone(tstate, exc);
Py_DECREF(exc);
return -1;
}
return 0;
}