diff options
author | Mark Shannon <mark@hotpy.org> | 2023-02-08 09:31:12 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-08 09:31:12 +0000 |
commit | feec49c40736fc05626a183a8d14c4ebbea5ae28 (patch) | |
tree | 5af6110eca8c2a21a9f699b40a87e7567c603e98 /Python/sysmodule.c | |
parent | 027adf42cd85db41fee05b0a40d89ef822876c97 (diff) | |
download | cpython-feec49c40736fc05626a183a8d14c4ebbea5ae28.tar.gz cpython-feec49c40736fc05626a183a8d14c4ebbea5ae28.zip |
GH-101578: Normalize the current exception (GH-101607)
* Make sure that the current exception is always normalized.
* Remove redundant type and traceback fields for the current exception.
* Add new API functions: PyErr_GetRaisedException, PyErr_SetRaisedException
* Add new API functions: PyException_GetArgs, PyException_SetArgs
Diffstat (limited to 'Python/sysmodule.c')
-rw-r--r-- | Python/sysmodule.c | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/Python/sysmodule.c b/Python/sysmodule.c index f9f766a94d1..6e81ef92b67 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -66,12 +66,11 @@ _PySys_GetAttr(PyThreadState *tstate, PyObject *name) if (sd == NULL) { return NULL; } - PyObject *exc_type, *exc_value, *exc_tb; - _PyErr_Fetch(tstate, &exc_type, &exc_value, &exc_tb); + PyObject *exc = _PyErr_GetRaisedException(tstate); /* XXX Suppress a new exception if it was raised and restore * the old one. */ PyObject *value = _PyDict_GetItemWithError(sd, name); - _PyErr_Restore(tstate, exc_type, exc_value, exc_tb); + _PyErr_SetRaisedException(tstate, exc); return value; } @@ -3704,11 +3703,10 @@ static void sys_format(PyObject *key, FILE *fp, const char *format, va_list va) { PyObject *file, *message; - PyObject *error_type, *error_value, *error_traceback; const char *utf8; PyThreadState *tstate = _PyThreadState_GET(); - _PyErr_Fetch(tstate, &error_type, &error_value, &error_traceback); + PyObject *error = _PyErr_GetRaisedException(tstate); file = _PySys_GetAttr(tstate, key); message = PyUnicode_FromFormatV(format, va); if (message != NULL) { @@ -3720,7 +3718,7 @@ sys_format(PyObject *key, FILE *fp, const char *format, va_list va) } Py_DECREF(message); } - _PyErr_Restore(tstate, error_type, error_value, error_traceback); + _PyErr_SetRaisedException(tstate, error); } void |