@@ -994,7 +994,8 @@ handle_weakrefs(PyGC_Head *unreachable, PyGC_Head *old)
994994 /* copy-paste of weakrefobject.c's handle_callback() */
995995 temp = PyObject_CallOneArg (callback , (PyObject * )wr );
996996 if (temp == NULL ) {
997- PyErr_WriteUnraisable (callback );
997+ PyErr_FormatUnraisable ("Exception ignored on "
998+ "calling weakref callback %R" , callback );
998999 }
9991000 else {
10001001 Py_DECREF (temp );
@@ -1797,7 +1798,8 @@ do_gc_callback(GCState *gcstate, const char *phase,
17971798 Py_INCREF (cb ); /* make sure cb doesn't go away */
17981799 r = PyObject_Vectorcall (cb , stack , 2 , NULL );
17991800 if (r == NULL ) {
1800- PyErr_WriteUnraisable (cb );
1801+ PyErr_FormatUnraisable ("Exception ignored while "
1802+ "calling GC callback %R" , cb );
18011803 }
18021804 else {
18031805 Py_DECREF (r );
@@ -2086,13 +2088,14 @@ _PyGC_DumpShutdownStats(PyInterpreterState *interp)
20862088 "gc" , NULL , message ,
20872089 PyList_GET_SIZE (gcstate -> garbage )))
20882090 {
2089- PyErr_WriteUnraisable ( NULL );
2091+ PyErr_FormatUnraisable ( "Exception ignored in GC shutdown" );
20902092 }
20912093 if (gcstate -> debug & _PyGC_DEBUG_UNCOLLECTABLE ) {
20922094 PyObject * repr = NULL , * bytes = NULL ;
20932095 repr = PyObject_Repr (gcstate -> garbage );
20942096 if (!repr || !(bytes = PyUnicode_EncodeFSDefault (repr ))) {
2095- PyErr_WriteUnraisable (gcstate -> garbage );
2097+ PyErr_FormatUnraisable ("Exception ignored in GC shutdown "
2098+ "while formatting garbage" );
20962099 }
20972100 else {
20982101 PySys_WriteStderr (
@@ -2344,9 +2347,12 @@ PyObject_GC_Del(void *op)
23442347#ifdef Py_DEBUG
23452348 PyObject * exc = PyErr_GetRaisedException ();
23462349 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" );
23502356 }
23512357 PyErr_SetRaisedException (exc );
23522358#endif
0 commit comments