Skip to content

gh-129354: Use PyErr_FormatUnraisable() function #129435

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Modules/_datetimemodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ clear_current_module(PyInterpreterState *interp, PyObject *expected)
goto finally;

error:
PyErr_WriteUnraisable(NULL);
PyErr_FormatUnraisable("Exception ignored on clearing _datetime module");

finally:
PyErr_SetRaisedException(exc);
Expand Down
9 changes: 6 additions & 3 deletions Modules/_testcapi/watchers.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 on "
"clearing code watcher");
break;
}
}
Expand Down Expand Up @@ -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 on "
"clearing function watcher");
break;
}
}
Expand Down Expand Up @@ -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 on "
"clearing context watcher");
break;
}
}
Expand Down
9 changes: 4 additions & 5 deletions Modules/_winapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 on 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
Expand Down
3 changes: 2 additions & 1 deletion Modules/atexitmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 on "
"copying atexit callbacks");
return;
}

Expand Down
3 changes: 2 additions & 1 deletion Modules/overlapped.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 on deallocating "
"overlapped operation %R", self);
}
}

Expand Down
3 changes: 2 additions & 1 deletion Modules/signalmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 on "
"calling signal handler");
continue;
}
PyObject *arglist = NULL;
Expand Down
3 changes: 2 additions & 1 deletion Objects/dictobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 on "
"clearing an object managed dict");
/* Clear the dict */
PyDictObject *dict = _PyObject_GetManagedDict(obj);
Py_BEGIN_CRITICAL_SECTION2(dict, obj);
Expand Down
2 changes: 1 addition & 1 deletion Objects/weakrefobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 on clearing object weakrefs");
PyErr_SetRaisedException(exc);
return;
}
Expand Down
2 changes: 1 addition & 1 deletion Python/jit.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 on freeing JIT memory");
}
}
}
Expand Down
Loading