Skip to content

Commit 13cb48c

Browse files
committed
Objects/object.c
1 parent c40fc27 commit 13cb48c

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

Objects/object.c

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -370,13 +370,12 @@ _PyObject_Dump(PyObject* op)
370370
fflush(stderr);
371371

372372
PyGILState_STATE gil = PyGILState_Ensure();
373-
PyObject *error_type, *error_value, *error_traceback;
374-
PyErr_Fetch(&error_type, &error_value, &error_traceback);
373+
PyObject *exc = PyErr_GetRaisedException();
375374

376375
(void)PyObject_Print(op, stderr, 0);
377376
fflush(stderr);
378377

379-
PyErr_Restore(error_type, error_value, error_traceback);
378+
PyErr_SetRaisedException(exc);
380379
PyGILState_Release(gil);
381380

382381
fprintf(stderr, "\n");
@@ -860,25 +859,23 @@ set_attribute_error_context(PyObject* v, PyObject* name)
860859
return 0;
861860
}
862861
// Intercept AttributeError exceptions and augment them to offer suggestions later.
863-
PyObject *type, *value, *traceback;
864-
PyErr_Fetch(&type, &value, &traceback);
865-
PyErr_NormalizeException(&type, &value, &traceback);
866-
// Check if the normalized exception is indeed an AttributeError
867-
if (!PyErr_GivenExceptionMatches(value, PyExc_AttributeError)) {
862+
PyObject *exc = PyErr_GetRaisedException();
863+
// Check if the exception is indeed an AttributeError
864+
if (!PyErr_GivenExceptionMatches(exc, PyExc_AttributeError)) {
868865
goto restore;
869866
}
870-
PyAttributeErrorObject* the_exc = (PyAttributeErrorObject*) value;
867+
PyAttributeErrorObject* the_exc = (PyAttributeErrorObject*) exc;
871868
// Check if this exception was already augmented
872869
if (the_exc->name || the_exc->obj) {
873870
goto restore;
874871
}
875872
// Augment the exception with the name and object
876-
if (PyObject_SetAttr(value, &_Py_ID(name), name) ||
877-
PyObject_SetAttr(value, &_Py_ID(obj), v)) {
873+
if (PyObject_SetAttr(exc, &_Py_ID(name), name) ||
874+
PyObject_SetAttr(exc, &_Py_ID(obj), v)) {
878875
return 1;
879876
}
880877
restore:
881-
PyErr_Restore(type, value, traceback);
878+
PyErr_SetRaisedException(exc);
882879
return 0;
883880
}
884881

@@ -2190,9 +2187,8 @@ Py_ReprLeave(PyObject *obj)
21902187
PyObject *dict;
21912188
PyObject *list;
21922189
Py_ssize_t i;
2193-
PyObject *error_type, *error_value, *error_traceback;
21942190

2195-
PyErr_Fetch(&error_type, &error_value, &error_traceback);
2191+
PyObject *exc = PyErr_GetRaisedException();
21962192

21972193
dict = PyThreadState_GetDict();
21982194
if (dict == NULL)
@@ -2213,7 +2209,7 @@ Py_ReprLeave(PyObject *obj)
22132209

22142210
finally:
22152211
/* ignore exceptions because there is no way to report them. */
2216-
PyErr_Restore(error_type, error_value, error_traceback);
2212+
PyErr_SetRaisedException(exc);
22172213
}
22182214

22192215
/* Trashcan support. */

0 commit comments

Comments
 (0)