From fe40d99d7a07b588e96858be1d1bfac37e618690 Mon Sep 17 00:00:00 2001 From: Irit Katriel Date: Thu, 4 Nov 2021 13:18:57 +0000 Subject: [PATCH 1/2] bpo-45711: Use _PyErr_ClearExcState instead of setting only exc_value to NULL --- Modules/_asynciomodule.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Modules/_asynciomodule.c b/Modules/_asynciomodule.c index 8386a50d55826d..6e408b107a9137 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; } From 78c70ac72c7cc8a16301a64d946638d56e525686 Mon Sep 17 00:00:00 2001 From: Irit Katriel Date: Mon, 8 Nov 2021 10:16:41 +0000 Subject: [PATCH 2/2] fix whitespace --- Modules/_asynciomodule.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Modules/_asynciomodule.c b/Modules/_asynciomodule.c index 6e408b107a9137..df6644ba248ed7 100644 --- a/Modules/_asynciomodule.c +++ b/Modules/_asynciomodule.c @@ -1377,8 +1377,8 @@ _asyncio_Future__make_cancelled_error_impl(FutureObj *self) _PyErr_ClearExcState(exc_state); } else { - assert (exc_state->exc_type == NULL); - assert (exc_state->exc_traceback == NULL); + assert(exc_state->exc_type == NULL); + assert(exc_state->exc_traceback == NULL); } return exc;