diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2023-11-02 09:16:34 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-02 09:16:34 (GMT) |
commit | 970e719a7a829bddc647bbaa668dd8603abdddef (patch) | |
tree | 92eeeba01687f6e02482315db653ce57f3b10e4b /Objects/codeobject.c | |
parent | a12f624a9dc1c44bb20a20b13fd164c14b987892 (diff) | |
download | cpython-970e719a7a829bddc647bbaa668dd8603abdddef.zip cpython-970e719a7a829bddc647bbaa668dd8603abdddef.tar.gz cpython-970e719a7a829bddc647bbaa668dd8603abdddef.tar.bz2 |
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>
Diffstat (limited to 'Objects/codeobject.c')
-rw-r--r-- | Objects/codeobject.c | 20 |
1 files changed, 3 insertions, 17 deletions
diff --git a/Objects/codeobject.c b/Objects/codeobject.c index f662b8e..48ff5b8 100644 --- a/Objects/codeobject.c +++ b/Objects/codeobject.c @@ -12,8 +12,6 @@ #include "pycore_tuple.h" // _PyTuple_ITEMS() #include "clinic/codeobject.c.h" -static PyObject* code_repr(PyCodeObject *co); - static const char * code_event_name(PyCodeEvent event) { switch (event) { @@ -41,21 +39,9 @@ notify_code_watchers(PyCodeEvent event, PyCodeObject *co) // callback must be non-null if the watcher bit is set assert(cb != NULL); if (cb(event, co) < 0) { - // Don't risk resurrecting the object if an unraisablehook keeps - // a reference; pass a string as context. - PyObject *context = NULL; - PyObject *repr = code_repr(co); - if (repr) { - context = PyUnicode_FromFormat( - "%s watcher callback for %U", - code_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 %R", + code_event_name(event), co); } } i++; |