Skip to content

Commit 4e47e05

Browse files
authored
pythongh-129354: Use PyErr_FormatUnraisable() function (python#129435)
Replace PyErr_WriteUnraisable() with PyErr_FormatUnraisable().
1 parent 5ab9604 commit 4e47e05

File tree

9 files changed

+21
-15
lines changed

9 files changed

+21
-15
lines changed

Modules/_datetimemodule.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ clear_current_module(PyInterpreterState *interp, PyObject *expected)
226226
goto finally;
227227

228228
error:
229-
PyErr_WriteUnraisable(NULL);
229+
PyErr_FormatUnraisable("Exception ignored when clearing _datetime module");
230230

231231
finally:
232232
PyErr_SetRaisedException(exc);

Modules/_testcapi/watchers.c

+6-3
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,8 @@ allocate_too_many_code_watchers(PyObject *self, PyObject *args)
428428
PyObject *exc = PyErr_GetRaisedException();
429429
for (int i = 0; i < num_watchers; i++) {
430430
if (PyCode_ClearWatcher(watcher_ids[i]) < 0) {
431-
PyErr_WriteUnraisable(Py_None);
431+
PyErr_FormatUnraisable("Exception ignored when "
432+
"clearing code watcher");
432433
break;
433434
}
434435
}
@@ -609,7 +610,8 @@ allocate_too_many_func_watchers(PyObject *self, PyObject *args)
609610
PyObject *exc = PyErr_GetRaisedException();
610611
for (int i = 0; i < num_watchers; i++) {
611612
if (PyFunction_ClearWatcher(watcher_ids[i]) < 0) {
612-
PyErr_WriteUnraisable(Py_None);
613+
PyErr_FormatUnraisable("Exception ignored when "
614+
"clearing function watcher");
613615
break;
614616
}
615617
}
@@ -755,7 +757,8 @@ allocate_too_many_context_watchers(PyObject *self, PyObject *args)
755757
PyObject *exc = PyErr_GetRaisedException();
756758
for (int i = 0; i < num_watchers; i++) {
757759
if (PyContext_ClearWatcher(watcher_ids[i]) < 0) {
758-
PyErr_WriteUnraisable(Py_None);
760+
PyErr_FormatUnraisable("Exception ignored when "
761+
"clearing context watcher");
759762
break;
760763
}
761764
}

Modules/_winapi.c

+4-5
Original file line numberDiff line numberDiff line change
@@ -171,17 +171,16 @@ overlapped_dealloc(OverlappedObject *self)
171171
{
172172
/* The operation is no longer pending -- nothing to do. */
173173
}
174-
else if (_Py_IsInterpreterFinalizing(_PyInterpreterState_GET()))
175-
{
174+
else if (_Py_IsInterpreterFinalizing(_PyInterpreterState_GET())) {
176175
/* The operation is still pending -- give a warning. This
177176
will probably only happen on Windows XP. */
178177
PyErr_SetString(PyExc_PythonFinalizationError,
179178
"I/O operations still in flight while destroying "
180179
"Overlapped object, the process may crash");
181-
PyErr_WriteUnraisable(NULL);
180+
PyErr_FormatUnraisable("Exception ignored when deallocating "
181+
"overlapped operation %R", self);
182182
}
183-
else
184-
{
183+
else {
185184
/* The operation is still pending, but the process is
186185
probably about to exit, so we need not worry too much
187186
about memory leaks. Leaking self prevents a potential

Modules/atexitmodule.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ atexit_callfuncs(struct atexit_state *state)
110110
PyObject *copy = PyList_GetSlice(state->callbacks, 0, PyList_GET_SIZE(state->callbacks));
111111
if (copy == NULL)
112112
{
113-
PyErr_WriteUnraisable(NULL);
113+
PyErr_FormatUnraisable("Exception ignored when "
114+
"copying atexit callbacks");
114115
return;
115116
}
116117

Modules/overlapped.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,8 @@ Overlapped_dealloc(OverlappedObject *self)
759759
PyExc_RuntimeError,
760760
"%R still has pending operation at "
761761
"deallocation, the process may crash", self);
762-
PyErr_WriteUnraisable(NULL);
762+
PyErr_FormatUnraisable("Exception ignored when deallocating "
763+
"overlapped operation %R", self);
763764
}
764765
}
765766

Modules/signalmodule.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -1837,7 +1837,8 @@ _PyErr_CheckSignalsTstate(PyThreadState *tstate)
18371837
PyErr_Format(PyExc_OSError,
18381838
"Signal %i ignored due to race condition",
18391839
i);
1840-
PyErr_WriteUnraisable(Py_None);
1840+
PyErr_FormatUnraisable("Exception ignored when "
1841+
"calling signal handler");
18411842
continue;
18421843
}
18431844
PyObject *arglist = NULL;

Objects/dictobject.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -7351,7 +7351,8 @@ PyObject_ClearManagedDict(PyObject *obj)
73517351
if (set_or_clear_managed_dict(obj, NULL, true) < 0) {
73527352
/* Must be out of memory */
73537353
assert(PyErr_Occurred() == PyExc_MemoryError);
7354-
PyErr_WriteUnraisable(NULL);
7354+
PyErr_FormatUnraisable("Exception ignored when "
7355+
"clearing an object managed dict");
73557356
/* Clear the dict */
73567357
PyDictObject *dict = _PyObject_GetManagedDict(obj);
73577358
Py_BEGIN_CRITICAL_SECTION2(dict, obj);

Objects/weakrefobject.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1042,7 +1042,7 @@ PyObject_ClearWeakRefs(PyObject *object)
10421042
PyObject *tuple = PyTuple_New(num_weakrefs * 2);
10431043
if (tuple == NULL) {
10441044
_PyWeakref_ClearWeakRefsNoCallbacks(object);
1045-
PyErr_WriteUnraisable(NULL);
1045+
PyErr_FormatUnraisable("Exception ignored when clearing object weakrefs");
10461046
PyErr_SetRaisedException(exc);
10471047
return;
10481048
}

Python/jit.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ _PyJIT_Free(_PyExecutorObject *executor)
563563
executor->jit_side_entry = NULL;
564564
executor->jit_size = 0;
565565
if (jit_free(memory, size)) {
566-
PyErr_WriteUnraisable(NULL);
566+
PyErr_FormatUnraisable("Exception ignored when freeing JIT memory");
567567
}
568568
}
569569
}

0 commit comments

Comments
 (0)