@@ -994,7 +994,8 @@ handle_weakrefs(PyGC_Head *unreachable, PyGC_Head *old)
994
994
/* copy-paste of weakrefobject.c's handle_callback() */
995
995
temp = PyObject_CallOneArg (callback , (PyObject * )wr );
996
996
if (temp == NULL ) {
997
- PyErr_WriteUnraisable (callback );
997
+ PyErr_FormatUnraisable ("Exception ignored on "
998
+ "calling weakref callback %R" , callback );
998
999
}
999
1000
else {
1000
1001
Py_DECREF (temp );
@@ -1797,7 +1798,8 @@ do_gc_callback(GCState *gcstate, const char *phase,
1797
1798
Py_INCREF (cb ); /* make sure cb doesn't go away */
1798
1799
r = PyObject_Vectorcall (cb , stack , 2 , NULL );
1799
1800
if (r == NULL ) {
1800
- PyErr_WriteUnraisable (cb );
1801
+ PyErr_FormatUnraisable ("Exception ignored while "
1802
+ "calling GC callback %R" , cb );
1801
1803
}
1802
1804
else {
1803
1805
Py_DECREF (r );
@@ -2086,13 +2088,14 @@ _PyGC_DumpShutdownStats(PyInterpreterState *interp)
2086
2088
"gc" , NULL , message ,
2087
2089
PyList_GET_SIZE (gcstate -> garbage )))
2088
2090
{
2089
- PyErr_WriteUnraisable ( NULL );
2091
+ PyErr_FormatUnraisable ( "Exception ignored in GC shutdown" );
2090
2092
}
2091
2093
if (gcstate -> debug & _PyGC_DEBUG_UNCOLLECTABLE ) {
2092
2094
PyObject * repr = NULL , * bytes = NULL ;
2093
2095
repr = PyObject_Repr (gcstate -> garbage );
2094
2096
if (!repr || !(bytes = PyUnicode_EncodeFSDefault (repr ))) {
2095
- PyErr_WriteUnraisable (gcstate -> garbage );
2097
+ PyErr_FormatUnraisable ("Exception ignored in GC shutdown "
2098
+ "while formatting garbage" );
2096
2099
}
2097
2100
else {
2098
2101
PySys_WriteStderr (
@@ -2344,9 +2347,12 @@ PyObject_GC_Del(void *op)
2344
2347
#ifdef Py_DEBUG
2345
2348
PyObject * exc = PyErr_GetRaisedException ();
2346
2349
if (PyErr_WarnExplicitFormat (PyExc_ResourceWarning , "gc" , 0 ,
2347
- "gc" , NULL , "Object of type %s is not untracked before destruction" ,
2348
- Py_TYPE (op )-> tp_name )) {
2349
- PyErr_WriteUnraisable (NULL );
2350
+ "gc" , NULL ,
2351
+ "Object of type %s is not untracked "
2352
+ "before destruction" ,
2353
+ Py_TYPE (op )-> tp_name ))
2354
+ {
2355
+ PyErr_FormatUnraisable ("Exception ignored on object deallocation" );
2350
2356
}
2351
2357
PyErr_SetRaisedException (exc );
2352
2358
#endif
0 commit comments