Commit 1b63493e authored by Victor Stinner's avatar Victor Stinner

Issue #18408: Py_ReprLeave() now saves/restores the current exception,

and ignores exceptions raised during the call
parent ac2a4fe8
...@@ -1920,13 +1920,18 @@ Py_ReprLeave(PyObject *obj) ...@@ -1920,13 +1920,18 @@ Py_ReprLeave(PyObject *obj)
PyObject *dict; PyObject *dict;
PyObject *list; PyObject *list;
Py_ssize_t i; Py_ssize_t i;
PyObject *error_type, *error_value, *error_traceback;
PyErr_Fetch(&error_type, &error_value, &error_traceback);
dict = PyThreadState_GetDict(); dict = PyThreadState_GetDict();
if (dict == NULL) if (dict == NULL)
return; goto finally;
list = PyDict_GetItemString(dict, KEY); list = PyDict_GetItemString(dict, KEY);
if (list == NULL || !PyList_Check(list)) if (list == NULL || !PyList_Check(list))
return; goto finally;
i = PyList_GET_SIZE(list); i = PyList_GET_SIZE(list);
/* Count backwards because we always expect obj to be list[-1] */ /* Count backwards because we always expect obj to be list[-1] */
while (--i >= 0) { while (--i >= 0) {
...@@ -1935,6 +1940,10 @@ Py_ReprLeave(PyObject *obj) ...@@ -1935,6 +1940,10 @@ Py_ReprLeave(PyObject *obj)
break; break;
} }
} }
finally:
/* ignore exceptions because there is no way to report them. */
PyErr_Restore(error_type, error_value, error_traceback);
} }
/* Trashcan support. */ /* Trashcan support. */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment