Skip to content

Commit 1e4af96

Browse files
committed
Python/sysmodule.c
1 parent cd338f9 commit 1e4af96

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

Python/sysmodule.c

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Data members:
2323
#include "pycore_namespace.h" // _PyNamespace_New()
2424
#include "pycore_object.h" // _PyObject_IS_GC()
2525
#include "pycore_pathconfig.h" // _PyPathConfig_ComputeSysPath0()
26-
#include "pycore_pyerrors.h" // _PyErr_Fetch()
26+
#include "pycore_pyerrors.h" // _PyErr_GetRaisedException()
2727
#include "pycore_pylifecycle.h" // _PyErr_WriteUnraisableDefaultHook()
2828
#include "pycore_pymath.h" // _PY_SHORT_FLOAT_REPR
2929
#include "pycore_pymem.h" // _PyMem_SetDefaultAllocator()
@@ -89,12 +89,11 @@ PySys_GetObject(const char *name)
8989
{
9090
PyThreadState *tstate = _PyThreadState_GET();
9191

92-
PyObject *exc_type, *exc_value, *exc_tb;
93-
_PyErr_Fetch(tstate, &exc_type, &exc_value, &exc_tb);
92+
PyObject *exc = _PyErr_GetRaisedException(tstate);
9493
PyObject *value = _PySys_GetObject(tstate->interp, name);
9594
/* XXX Suppress a new exception if it was raised and restore
9695
* the old one. */
97-
_PyErr_Restore(tstate, exc_type, exc_value, exc_tb);
96+
_PyErr_SetRaisedException(tstate, exc);
9897
return value;
9998
}
10099

@@ -203,8 +202,8 @@ sys_audit_tstate(PyThreadState *ts, const char *event,
203202

204203
int dtrace = PyDTrace_AUDIT_ENABLED();
205204

206-
PyObject *exc_type, *exc_value, *exc_tb;
207-
_PyErr_Fetch(ts, &exc_type, &exc_value, &exc_tb);
205+
206+
PyObject *exc = _PyErr_GetRaisedException(ts);
208207

209208
/* Initialize event args now */
210209
if (argFormat && argFormat[0]) {
@@ -287,13 +286,11 @@ sys_audit_tstate(PyThreadState *ts, const char *event,
287286
Py_XDECREF(eventArgs);
288287

289288
if (!res) {
290-
_PyErr_Restore(ts, exc_type, exc_value, exc_tb);
289+
_PyErr_SetRaisedException(ts, exc);
291290
}
292291
else {
293292
assert(_PyErr_Occurred(ts));
294-
Py_XDECREF(exc_type);
295-
Py_XDECREF(exc_value);
296-
Py_XDECREF(exc_tb);
293+
Py_XDECREF(exc);
297294
}
298295

299296
return res;
@@ -3661,12 +3658,11 @@ static void
36613658
sys_write(PyObject *key, FILE *fp, const char *format, va_list va)
36623659
{
36633660
PyObject *file;
3664-
PyObject *error_type, *error_value, *error_traceback;
36653661
char buffer[1001];
36663662
int written;
36673663
PyThreadState *tstate = _PyThreadState_GET();
36683664

3669-
_PyErr_Fetch(tstate, &error_type, &error_value, &error_traceback);
3665+
PyObject *exc = _PyErr_GetRaisedException(tstate);
36703666
file = _PySys_GetAttr(tstate, key);
36713667
written = PyOS_vsnprintf(buffer, sizeof(buffer), format, va);
36723668
if (sys_pyfile_write(buffer, file) != 0) {
@@ -3678,7 +3674,7 @@ sys_write(PyObject *key, FILE *fp, const char *format, va_list va)
36783674
if (sys_pyfile_write(truncated, file) != 0)
36793675
fputs(truncated, fp);
36803676
}
3681-
_PyErr_Restore(tstate, error_type, error_value, error_traceback);
3677+
_PyErr_SetRaisedException(tstate, exc);
36823678
}
36833679

36843680
void
@@ -3708,7 +3704,7 @@ sys_format(PyObject *key, FILE *fp, const char *format, va_list va)
37083704
const char *utf8;
37093705
PyThreadState *tstate = _PyThreadState_GET();
37103706

3711-
PyObject *error = _PyErr_GetRaisedException(tstate);
3707+
PyObject *exc = _PyErr_GetRaisedException(tstate);
37123708
file = _PySys_GetAttr(tstate, key);
37133709
message = PyUnicode_FromFormatV(format, va);
37143710
if (message != NULL) {
@@ -3720,7 +3716,7 @@ sys_format(PyObject *key, FILE *fp, const char *format, va_list va)
37203716
}
37213717
Py_DECREF(message);
37223718
}
3723-
_PyErr_SetRaisedException(tstate, error);
3719+
_PyErr_SetRaisedException(tstate, exc);
37243720
}
37253721

37263722
void

0 commit comments

Comments
 (0)