@@ -178,8 +178,7 @@ _PyErr_SetObject(PyThreadState *tstate, PyObject *exception, PyObject *value)
178
178
}
179
179
if (value != NULL && PyExceptionInstance_Check (value ))
180
180
tb = PyException_GetTraceback (value );
181
- Py_XINCREF (exception );
182
- _PyErr_Restore (tstate , exception , value , tb );
181
+ _PyErr_Restore (tstate , Py_XNewRef (exception ), value , tb );
183
182
}
184
183
185
184
void
@@ -489,13 +488,9 @@ _PyErr_GetExcInfo(PyThreadState *tstate,
489
488
{
490
489
_PyErr_StackItem * exc_info = _PyErr_GetTopmostException (tstate );
491
490
492
- * p_type = get_exc_type (exc_info -> exc_value );
493
- * p_value = exc_info -> exc_value ;
494
- * p_traceback = get_exc_traceback (exc_info -> exc_value );
495
-
496
- Py_XINCREF (* p_type );
497
- Py_XINCREF (* p_value );
498
- Py_XINCREF (* p_traceback );
491
+ * p_type = Py_XNewRef (get_exc_type (exc_info -> exc_value ));
492
+ * p_value = Py_XNewRef (exc_info -> exc_value );
493
+ * p_traceback = Py_XNewRef (get_exc_traceback (exc_info -> exc_value ));
499
494
}
500
495
501
496
PyObject *
@@ -674,9 +669,9 @@ _PyErr_FormatVFromCause(PyThreadState *tstate, PyObject *exception,
674
669
675
670
_PyErr_Fetch (tstate , & exc , & val2 , & tb );
676
671
_PyErr_NormalizeException (tstate , & exc , & val2 , & tb );
677
- Py_INCREF ( val );
678
- PyException_SetCause (val2 , val );
679
- PyException_SetContext ( val2 , val );
672
+ PyException_SetCause ( val2 , Py_NewRef ( val ) );
673
+ PyException_SetContext (val2 , Py_NewRef ( val ) );
674
+ Py_DECREF ( val );
680
675
_PyErr_Restore (tstate , exc , val2 , tb );
681
676
682
677
return NULL ;
@@ -1165,9 +1160,7 @@ PyErr_NewException(const char *name, PyObject *base, PyObject *dict)
1165
1160
goto failure ;
1166
1161
}
1167
1162
if (PyTuple_Check (base )) {
1168
- bases = base ;
1169
- /* INCREF as we create a new ref in the else branch */
1170
- Py_INCREF (bases );
1163
+ bases = Py_NewRef (base );
1171
1164
} else {
1172
1165
bases = PyTuple_Pack (1 , base );
1173
1166
if (bases == NULL )
0 commit comments