diff options
author | Irit Katriel <1055913+iritkatriel@users.noreply.github.com> | 2021-11-10 16:57:14 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-10 16:57:14 (GMT) |
commit | 05fbd60147456d77a7aecf29dddd86c5bde5872f (patch) | |
tree | 648c25c5f6fb8fff88ef685824e962c63768f34d /Modules/_asynciomodule.c | |
parent | 76d14fac72479e0f5f5b144d6968ecd9e594db34 (diff) | |
download | cpython-05fbd60147456d77a7aecf29dddd86c5bde5872f.zip cpython-05fbd60147456d77a7aecf29dddd86c5bde5872f.tar.gz cpython-05fbd60147456d77a7aecf29dddd86c5bde5872f.tar.bz2 |
bpo-45711: Use _PyErr_ClearExcState instead of setting only exc_value to NULL (GH-29404)
Diffstat (limited to 'Modules/_asynciomodule.c')
-rw-r--r-- | Modules/_asynciomodule.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/Modules/_asynciomodule.c b/Modules/_asynciomodule.c index 8386a50..df6644b 100644 --- a/Modules/_asynciomodule.c +++ b/Modules/_asynciomodule.c @@ -1371,10 +1371,15 @@ _asyncio_Future__make_cancelled_error_impl(FutureObj *self) { PyObject *exc = create_cancelled_error(self->fut_cancel_msg); _PyErr_StackItem *exc_state = &self->fut_cancelled_exc_state; - /* Transfer ownership of exc_value from exc_state to exc since we are - done with it. */ - PyException_SetContext(exc, exc_state->exc_value); - exc_state->exc_value = NULL; + + if (exc_state->exc_value) { + PyException_SetContext(exc, Py_NewRef(exc_state->exc_value)); + _PyErr_ClearExcState(exc_state); + } + else { + assert(exc_state->exc_type == NULL); + assert(exc_state->exc_traceback == NULL); + } return exc; } |