@@ -370,13 +370,12 @@ _PyObject_Dump(PyObject* op)
370
370
fflush (stderr );
371
371
372
372
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 ();
375
374
376
375
(void )PyObject_Print (op , stderr , 0 );
377
376
fflush (stderr );
378
377
379
- PyErr_Restore ( error_type , error_value , error_traceback );
378
+ PyErr_SetRaisedException ( exc );
380
379
PyGILState_Release (gil );
381
380
382
381
fprintf (stderr , "\n" );
@@ -860,25 +859,23 @@ set_attribute_error_context(PyObject* v, PyObject* name)
860
859
return 0 ;
861
860
}
862
861
// 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 )) {
868
865
goto restore ;
869
866
}
870
- PyAttributeErrorObject * the_exc = (PyAttributeErrorObject * ) value ;
867
+ PyAttributeErrorObject * the_exc = (PyAttributeErrorObject * ) exc ;
871
868
// Check if this exception was already augmented
872
869
if (the_exc -> name || the_exc -> obj ) {
873
870
goto restore ;
874
871
}
875
872
// 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 )) {
878
875
return 1 ;
879
876
}
880
877
restore :
881
- PyErr_Restore ( type , value , traceback );
878
+ PyErr_SetRaisedException ( exc );
882
879
return 0 ;
883
880
}
884
881
@@ -2190,9 +2187,8 @@ Py_ReprLeave(PyObject *obj)
2190
2187
PyObject * dict ;
2191
2188
PyObject * list ;
2192
2189
Py_ssize_t i ;
2193
- PyObject * error_type , * error_value , * error_traceback ;
2194
2190
2195
- PyErr_Fetch ( & error_type , & error_value , & error_traceback );
2191
+ PyObject * exc = PyErr_GetRaisedException ( );
2196
2192
2197
2193
dict = PyThreadState_GetDict ();
2198
2194
if (dict == NULL )
@@ -2213,7 +2209,7 @@ Py_ReprLeave(PyObject *obj)
2213
2209
2214
2210
finally :
2215
2211
/* ignore exceptions because there is no way to report them. */
2216
- PyErr_Restore ( error_type , error_value , error_traceback );
2212
+ PyErr_SetRaisedException ( exc );
2217
2213
}
2218
2214
2219
2215
/* Trashcan support. */
0 commit comments