summaryrefslogtreecommitdiffstats
path: root/Python/sysmodule.c
diff options
context:
space:
mode:
authorIrit Katriel <1055913+iritkatriel@users.noreply.github.com>2023-02-28 11:50:52 (GMT)
committerGitHub <noreply@github.com>2023-02-28 11:50:52 (GMT)
commit4c87537efb5fd28b4e4ee9631076ed5953720156 (patch)
tree8c8bf4b1c849bc47dc28561d0653c95b33e357db /Python/sysmodule.c
parent85b1fc1fc5a2e49d521382eaf5e7793175d00371 (diff)
downloadcpython-4c87537efb5fd28b4e4ee9631076ed5953720156.zip
cpython-4c87537efb5fd28b4e4ee9631076ed5953720156.tar.gz
cpython-4c87537efb5fd28b4e4ee9631076ed5953720156.tar.bz2
gh-102192: Replace PyErr_Fetch/Restore etc by more efficient alternatives (in Python/) (#102193)
Diffstat (limited to 'Python/sysmodule.c')
-rw-r--r--Python/sysmodule.c26
1 files changed, 11 insertions, 15 deletions
diff --git a/Python/sysmodule.c b/Python/sysmodule.c
index b69b803..207abb9 100644
--- a/Python/sysmodule.c
+++ b/Python/sysmodule.c
@@ -23,7 +23,7 @@ Data members:
#include "pycore_namespace.h" // _PyNamespace_New()
#include "pycore_object.h" // _PyObject_IS_GC()
#include "pycore_pathconfig.h" // _PyPathConfig_ComputeSysPath0()
-#include "pycore_pyerrors.h" // _PyErr_Fetch()
+#include "pycore_pyerrors.h" // _PyErr_GetRaisedException()
#include "pycore_pylifecycle.h" // _PyErr_WriteUnraisableDefaultHook()
#include "pycore_pymath.h" // _PY_SHORT_FLOAT_REPR
#include "pycore_pymem.h" // _PyMem_SetDefaultAllocator()
@@ -89,12 +89,11 @@ PySys_GetObject(const char *name)
{
PyThreadState *tstate = _PyThreadState_GET();
- PyObject *exc_type, *exc_value, *exc_tb;
- _PyErr_Fetch(tstate, &exc_type, &exc_value, &exc_tb);
+ PyObject *exc = _PyErr_GetRaisedException(tstate);
PyObject *value = _PySys_GetObject(tstate->interp, name);
/* XXX Suppress a new exception if it was raised and restore
* the old one. */
- _PyErr_Restore(tstate, exc_type, exc_value, exc_tb);
+ _PyErr_SetRaisedException(tstate, exc);
return value;
}
@@ -203,8 +202,8 @@ sys_audit_tstate(PyThreadState *ts, const char *event,
int dtrace = PyDTrace_AUDIT_ENABLED();
- PyObject *exc_type, *exc_value, *exc_tb;
- _PyErr_Fetch(ts, &exc_type, &exc_value, &exc_tb);
+
+ PyObject *exc = _PyErr_GetRaisedException(ts);
/* Initialize event args now */
if (argFormat && argFormat[0]) {
@@ -287,13 +286,11 @@ exit:
Py_XDECREF(eventArgs);
if (!res) {
- _PyErr_Restore(ts, exc_type, exc_value, exc_tb);
+ _PyErr_SetRaisedException(ts, exc);
}
else {
assert(_PyErr_Occurred(ts));
- Py_XDECREF(exc_type);
- Py_XDECREF(exc_value);
- Py_XDECREF(exc_tb);
+ Py_XDECREF(exc);
}
return res;
@@ -3661,12 +3658,11 @@ static void
sys_write(PyObject *key, FILE *fp, const char *format, va_list va)
{
PyObject *file;
- PyObject *error_type, *error_value, *error_traceback;
char buffer[1001];
int written;
PyThreadState *tstate = _PyThreadState_GET();
- _PyErr_Fetch(tstate, &error_type, &error_value, &error_traceback);
+ PyObject *exc = _PyErr_GetRaisedException(tstate);
file = _PySys_GetAttr(tstate, key);
written = PyOS_vsnprintf(buffer, sizeof(buffer), format, va);
if (sys_pyfile_write(buffer, file) != 0) {
@@ -3678,7 +3674,7 @@ sys_write(PyObject *key, FILE *fp, const char *format, va_list va)
if (sys_pyfile_write(truncated, file) != 0)
fputs(truncated, fp);
}
- _PyErr_Restore(tstate, error_type, error_value, error_traceback);
+ _PyErr_SetRaisedException(tstate, exc);
}
void
@@ -3708,7 +3704,7 @@ sys_format(PyObject *key, FILE *fp, const char *format, va_list va)
const char *utf8;
PyThreadState *tstate = _PyThreadState_GET();
- PyObject *error = _PyErr_GetRaisedException(tstate);
+ PyObject *exc = _PyErr_GetRaisedException(tstate);
file = _PySys_GetAttr(tstate, key);
message = PyUnicode_FromFormatV(format, va);
if (message != NULL) {
@@ -3720,7 +3716,7 @@ sys_format(PyObject *key, FILE *fp, const char *format, va_list va)
}
Py_DECREF(message);
}
- _PyErr_SetRaisedException(tstate, error);
+ _PyErr_SetRaisedException(tstate, exc);
}
void