[Python-checkins] bpo-45711: Use _PyErr_ClearExcState instead of setting only exc_value to NULL (GH-29404)

iritkatriel webhook-mailer at python.org
Wed Nov 10 11:57:24 EST 2021


https://github.com/python/cpython/commit/05fbd60147456d77a7aecf29dddd86c5bde5872f
commit: 05fbd60147456d77a7aecf29dddd86c5bde5872f
branch: main
author: Irit Katriel <1055913+iritkatriel at users.noreply.github.com>
committer: iritkatriel <1055913+iritkatriel at users.noreply.github.com>
date: 2021-11-10T16:57:14Z
summary:

bpo-45711: Use _PyErr_ClearExcState instead of setting only exc_value to NULL (GH-29404)

files:
M Modules/_asynciomodule.c

diff --git a/Modules/_asynciomodule.c b/Modules/_asynciomodule.c
index 8386a50d55826..df6644ba248ed 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;
 }



More information about the Python-checkins mailing list