mirror of
https://github.com/python/cpython
synced 2026-09-29 12:10:30 +03:00
gh-108082: Use PyErr_FormatUnraisable() (GH-111580)
Replace most of calls of _PyErr_WriteUnraisableMsg() and some calls of PyErr_WriteUnraisable(NULL) with PyErr_FormatUnraisable(). Co-authored-by: Victor Stinner <vstinner@python.org>
This commit is contained in:
parent
a12f624a9d
commit
970e719a7a
18 changed files with 83 additions and 114 deletions
|
|
@ -8,8 +8,6 @@
|
|||
#include "pycore_pyerrors.h" // _PyErr_Occurred()
|
||||
|
||||
|
||||
static PyObject* func_repr(PyFunctionObject *op);
|
||||
|
||||
static const char *
|
||||
func_event_name(PyFunction_WatchEvent event) {
|
||||
switch (event) {
|
||||
|
|
@ -35,21 +33,9 @@ notify_func_watchers(PyInterpreterState *interp, PyFunction_WatchEvent event,
|
|||
// callback must be non-null if the watcher bit is set
|
||||
assert(cb != NULL);
|
||||
if (cb(event, func, new_value) < 0) {
|
||||
// Don't risk resurrecting the func if an unraisablehook keeps a
|
||||
// reference; pass a string as context.
|
||||
PyObject *context = NULL;
|
||||
PyObject *repr = func_repr(func);
|
||||
if (repr != NULL) {
|
||||
context = PyUnicode_FromFormat(
|
||||
"%s watcher callback for %U",
|
||||
func_event_name(event), repr);
|
||||
Py_DECREF(repr);
|
||||
}
|
||||
if (context == NULL) {
|
||||
context = Py_NewRef(Py_None);
|
||||
}
|
||||
PyErr_WriteUnraisable(context);
|
||||
Py_DECREF(context);
|
||||
PyErr_FormatUnraisable(
|
||||
"Exception ignored in %s watcher callback for function %U at %p",
|
||||
func_event_name(event), func->func_qualname, func);
|
||||
}
|
||||
}
|
||||
i++;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue