gh-129354: Use PyErr_FormatUnraisable() function (#129656)

Replace PyErr_WriteUnraisable() with PyErr_FormatUnraisable().
This commit is contained in:
Victor Stinner 2025-02-04 16:21:10 +01:00 committed by GitHub
parent 979d766209
commit 14489c1bb4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 8 additions and 4 deletions

View file

@ -105,8 +105,10 @@ fileio_dealloc_warn(PyObject *op, PyObject *source)
PyObject *exc = PyErr_GetRaisedException();
if (PyErr_ResourceWarning(source, 1, "unclosed file %R", source)) {
/* Spurious errors can appear at shutdown */
if (PyErr_ExceptionMatches(PyExc_Warning))
PyErr_WriteUnraisable((PyObject *) self);
if (PyErr_ExceptionMatches(PyExc_Warning)) {
PyErr_FormatUnraisable("Exception ignored "
"while finalizing file %R", self);
}
}
PyErr_SetRaisedException(exc);
}

View file

@ -314,7 +314,8 @@ iobase_finalize(PyObject *self)
PyErr_Clear();
res = PyObject_CallMethodNoArgs((PyObject *)self, &_Py_ID(close));
if (res == NULL) {
PyErr_WriteUnraisable(self);
PyErr_FormatUnraisable("Exception ignored "
"while finalizing file %R", self);
}
else {
Py_DECREF(res);

View file

@ -5359,7 +5359,8 @@ sock_finalize(PyObject *self)
if (PyErr_ResourceWarning((PyObject *)s, 1, "unclosed %R", s)) {
/* Spurious errors can appear at shutdown */
if (PyErr_ExceptionMatches(PyExc_Warning)) {
PyErr_WriteUnraisable((PyObject *)s);
PyErr_FormatUnraisable("Exception ignored while "
"finalizing socket %R", s);
}
}