@@ -1371,10 +1371,15 @@ _asyncio_Future__make_cancelled_error_impl(FutureObj *self) |
|
|
1371 |
1371 |
{ |
1372 |
1372 |
PyObject *exc = create_cancelled_error(self->fut_cancel_msg); |
1373 |
1373 |
_PyErr_StackItem *exc_state = &self->fut_cancelled_exc_state; |
1374 |
|
-/* Transfer ownership of exc_value from exc_state to exc since we are |
1375 |
|
- done with it. */ |
1376 |
|
-PyException_SetContext(exc, exc_state->exc_value); |
1377 |
|
-exc_state->exc_value = NULL; |
|
1374 |
+ |
|
1375 |
+if (exc_state->exc_value) { |
|
1376 |
+PyException_SetContext(exc, Py_NewRef(exc_state->exc_value)); |
|
1377 |
+_PyErr_ClearExcState(exc_state); |
|
1378 |
+ } |
|
1379 |
+else { |
|
1380 |
+assert(exc_state->exc_type == NULL); |
|
1381 |
+assert(exc_state->exc_traceback == NULL); |
|
1382 |
+ } |
1378 |
1383 |
|
1379 |
1384 |
return exc; |
1380 |
1385 |
} |