diff options
author | Victor Stinner <vstinner@redhat.com> | 2019-05-27 08:57:14 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-27 08:57:14 +0200 |
commit | 71c52e3048dd07567f0c690eab4e5d57be66f534 (patch) | |
tree | 7f3a063d2d3edb324d7d00bf13a66ddad689d22e /Modules/_testcapimodule.c | |
parent | 2f0bfd27a5e3a9a7cbeb2ddd45ce50c3d4bdb4e9 (diff) | |
download | cpython-git-71c52e3048dd07567f0c690eab4e5d57be66f534.tar.gz |
bpo-36829: Add _PyErr_WriteUnraisableMsg() (GH-13488)
* sys.unraisablehook: add 'err_msg' field to UnraisableHookArgs.
* Use _PyErr_WriteUnraisableMsg() in _ctypes _DictRemover_call()
and gc delete_garbage().
Diffstat (limited to 'Modules/_testcapimodule.c')
-rw-r--r-- | Modules/_testcapimodule.c | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index 7945f498f9..51e5d80d1f 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -4985,13 +4985,24 @@ negative_refcount(PyObject *self, PyObject *Py_UNUSED(args)) static PyObject* test_write_unraisable_exc(PyObject *self, PyObject *args) { - PyObject *exc, *obj; - if (!PyArg_ParseTuple(args, "OO", &exc, &obj)) { + PyObject *exc, *err_msg, *obj; + if (!PyArg_ParseTuple(args, "OOO", &exc, &err_msg, &obj)) { return NULL; } + const char *err_msg_utf8; + if (err_msg != Py_None) { + err_msg_utf8 = PyUnicode_AsUTF8(err_msg); + if (err_msg_utf8 == NULL) { + return NULL; + } + } + else { + err_msg_utf8 = NULL; + } + PyErr_SetObject((PyObject *)Py_TYPE(exc), exc); - PyErr_WriteUnraisable(obj); + _PyErr_WriteUnraisableMsg(err_msg_utf8, obj); Py_RETURN_NONE; } |