From 5a42d44870ee3fb5f473c8294775aae107bb0824 Mon Sep 17 00:00:00 2001 From: Pablo Galindo Date: Mon, 21 Jun 2021 11:19:19 +0100 Subject: [PATCH] bpo-44472: Fix ltrace functionality when exceptions are raised --- .../Core and Builtins/2021-06-21-11-19-54.bpo-44472.Vvm1yn.rst | 1 + Python/ceval.c | 3 +++ 2 files changed, 4 insertions(+) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2021-06-21-11-19-54.bpo-44472.Vvm1yn.rst diff --git a/Misc/NEWS.d/next/Core and Builtins/2021-06-21-11-19-54.bpo-44472.Vvm1yn.rst b/Misc/NEWS.d/next/Core and Builtins/2021-06-21-11-19-54.bpo-44472.Vvm1yn.rst new file mode 100644 index 00000000000000..34fa2a9e8615fa --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2021-06-21-11-19-54.bpo-44472.Vvm1yn.rst @@ -0,0 +1 @@ +Fix ltrace functionality when exceptions are raised. Patch by Pablo Galindo diff --git a/Python/ceval.c b/Python/ceval.c index 699cd865faa1be..559da1334a234c 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -5323,11 +5323,14 @@ static int prtrace(PyThreadState *tstate, PyObject *v, const char *str) { printf("%s ", str); + PyObject *type, *value, *traceback; + PyErr_Fetch(&type, &value, &traceback); if (PyObject_Print(v, stdout, 0) != 0) { /* Don't know what else to do */ _PyErr_Clear(tstate); } printf("\n"); + PyErr_Restore(type, value, traceback); return 1; } #endif