]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-129354: Use PyErr_FormatUnraisable() function (#129435)
authorVictor Stinner <vstinner@python.org>
Thu, 30 Jan 2025 15:09:38 +0000 (16:09 +0100)
committerGitHub <noreply@github.com>
Thu, 30 Jan 2025 15:09:38 +0000 (16:09 +0100)
Replace PyErr_WriteUnraisable() with PyErr_FormatUnraisable().

Modules/_datetimemodule.c
Modules/_testcapi/watchers.c
Modules/_winapi.c
Modules/atexitmodule.c
Modules/overlapped.c
Modules/signalmodule.c
Objects/dictobject.c
Objects/weakrefobject.c
Python/jit.c

index a486af7833c2c66ec1caca06a3e8f2c296df9255..9d2abce203be7deeb74b50797d2fc34fc162a99a 100644 (file)
@@ -226,7 +226,7 @@ clear_current_module(PyInterpreterState *interp, PyObject *expected)
     goto finally;
 
 error:
-    PyErr_WriteUnraisable(NULL);
+    PyErr_FormatUnraisable("Exception ignored when clearing _datetime module");
 
 finally:
     PyErr_SetRaisedException(exc);
index 321d3aeffb6ad18f364aaeb9dc6336508c6b1084..17a30355a266f06e2be834aec9a99581d00130c8 100644 (file)
@@ -428,7 +428,8 @@ allocate_too_many_code_watchers(PyObject *self, PyObject *args)
     PyObject *exc = PyErr_GetRaisedException();
     for (int i = 0; i < num_watchers; i++) {
         if (PyCode_ClearWatcher(watcher_ids[i]) < 0) {
-            PyErr_WriteUnraisable(Py_None);
+            PyErr_FormatUnraisable("Exception ignored when "
+                                   "clearing code watcher");
             break;
         }
     }
@@ -609,7 +610,8 @@ allocate_too_many_func_watchers(PyObject *self, PyObject *args)
     PyObject *exc = PyErr_GetRaisedException();
     for (int i = 0; i < num_watchers; i++) {
         if (PyFunction_ClearWatcher(watcher_ids[i]) < 0) {
-            PyErr_WriteUnraisable(Py_None);
+            PyErr_FormatUnraisable("Exception ignored when "
+                                   "clearing function watcher");
             break;
         }
     }
@@ -755,7 +757,8 @@ allocate_too_many_context_watchers(PyObject *self, PyObject *args)
     PyObject *exc = PyErr_GetRaisedException();
     for (int i = 0; i < num_watchers; i++) {
         if (PyContext_ClearWatcher(watcher_ids[i]) < 0) {
-            PyErr_WriteUnraisable(Py_None);
+            PyErr_FormatUnraisable("Exception ignored when "
+                                   "clearing context watcher");
             break;
         }
     }
index 260cab48091c16e342ce606d850f6a94fd9e5300..56dd38401cb273f772704be3614ea029ae25a180 100644 (file)
@@ -171,17 +171,16 @@ overlapped_dealloc(OverlappedObject *self)
         {
             /* The operation is no longer pending -- nothing to do. */
         }
-        else if (_Py_IsInterpreterFinalizing(_PyInterpreterState_GET()))
-        {
+        else if (_Py_IsInterpreterFinalizing(_PyInterpreterState_GET())) {
             /* The operation is still pending -- give a warning.  This
                will probably only happen on Windows XP. */
             PyErr_SetString(PyExc_PythonFinalizationError,
                             "I/O operations still in flight while destroying "
                             "Overlapped object, the process may crash");
-            PyErr_WriteUnraisable(NULL);
+            PyErr_FormatUnraisable("Exception ignored when deallocating "
+                                   "overlapped operation %R", self);
         }
-        else
-        {
+        else {
             /* The operation is still pending, but the process is
                probably about to exit, so we need not worry too much
                about memory leaks.  Leaking self prevents a potential
index 1b89b32ba907d7d926dd5b95b4d13ee7c0663c62..1dbcc1089c32ab43ad50c64d8316ba1b9efdab6e 100644 (file)
@@ -110,7 +110,8 @@ atexit_callfuncs(struct atexit_state *state)
     PyObject *copy = PyList_GetSlice(state->callbacks, 0, PyList_GET_SIZE(state->callbacks));
     if (copy == NULL)
     {
-        PyErr_WriteUnraisable(NULL);
+        PyErr_FormatUnraisable("Exception ignored when "
+                               "copying atexit callbacks");
         return;
     }
 
index 308a0dab7fab1aea1c43c22521f36f4afcabbff0..525b288f3ff54dd1d26e202f1baadf85e3471d17 100644 (file)
@@ -759,7 +759,8 @@ Overlapped_dealloc(OverlappedObject *self)
                     PyExc_RuntimeError,
                     "%R still has pending operation at "
                     "deallocation, the process may crash", self);
-                PyErr_WriteUnraisable(NULL);
+                PyErr_FormatUnraisable("Exception ignored when deallocating "
+                                       "overlapped operation %R", self);
         }
     }
 
index 0e53a36bca55f0326ed29bfd22af55e4aa7397ed..0cc9b35300dccaad0d3057cd5ef84630fa697d02 100644 (file)
@@ -1837,7 +1837,8 @@ _PyErr_CheckSignalsTstate(PyThreadState *tstate)
             PyErr_Format(PyExc_OSError,
                          "Signal %i ignored due to race condition",
                          i);
-            PyErr_WriteUnraisable(Py_None);
+            PyErr_FormatUnraisable("Exception ignored when "
+                                   "calling signal handler");
             continue;
         }
         PyObject *arglist = NULL;
index 733a10a2e80b18591e1f4a9402aab4a6d5f75936..a05359ca0b16efb0a2e2dbcb8941ac656d3cbc76 100644 (file)
@@ -7351,7 +7351,8 @@ PyObject_ClearManagedDict(PyObject *obj)
     if (set_or_clear_managed_dict(obj, NULL, true) < 0) {
         /* Must be out of memory */
         assert(PyErr_Occurred() == PyExc_MemoryError);
-        PyErr_WriteUnraisable(NULL);
+        PyErr_FormatUnraisable("Exception ignored when "
+                               "clearing an object managed dict");
         /* Clear the dict */
         PyDictObject *dict = _PyObject_GetManagedDict(obj);
         Py_BEGIN_CRITICAL_SECTION2(dict, obj);
index 0ee64ed70a63cdd1ad43a77607d7e33025f27c8b..8ced82ef36e30dadd9662c06c34d6d91acab3953 100644 (file)
@@ -1042,7 +1042,7 @@ PyObject_ClearWeakRefs(PyObject *object)
     PyObject *tuple = PyTuple_New(num_weakrefs * 2);
     if (tuple == NULL) {
         _PyWeakref_ClearWeakRefsNoCallbacks(object);
-        PyErr_WriteUnraisable(NULL);
+        PyErr_FormatUnraisable("Exception ignored when clearing object weakrefs");
         PyErr_SetRaisedException(exc);
         return;
     }
index 7dd0da7a45055a966a43853edf0d8c2afc98b7e4..4b01112f9b0a5a58d3a1e96dd12e5466c38c09f2 100644 (file)
@@ -563,7 +563,7 @@ _PyJIT_Free(_PyExecutorObject *executor)
         executor->jit_side_entry = NULL;
         executor->jit_size = 0;
         if (jit_free(memory, size)) {
-            PyErr_WriteUnraisable(NULL);
+            PyErr_FormatUnraisable("Exception ignored when freeing JIT memory");
         }
     }
 }