summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@redhat.com>2019-05-27 06:57:14 (GMT)
committerGitHub <noreply@github.com>2019-05-27 06:57:14 (GMT)
commit71c52e3048dd07567f0c690eab4e5d57be66f534 (patch)
tree7f3a063d2d3edb324d7d00bf13a66ddad689d22e /Modules
parent2f0bfd27a5e3a9a7cbeb2ddd45ce50c3d4bdb4e9 (diff)
downloadcpython-71c52e3048dd07567f0c690eab4e5d57be66f534.zip
cpython-71c52e3048dd07567f0c690eab4e5d57be66f534.tar.gz
cpython-71c52e3048dd07567f0c690eab4e5d57be66f534.tar.bz2
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')
-rw-r--r--Modules/_ctypes/_ctypes.c6
-rw-r--r--Modules/_testcapimodule.c17
-rw-r--r--Modules/gcmodule.c5
3 files changed, 19 insertions, 9 deletions
diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c
index f4eb536..21b08f8 100644
--- a/Modules/_ctypes/_ctypes.c
+++ b/Modules/_ctypes/_ctypes.c
@@ -150,9 +150,9 @@ _DictRemover_call(PyObject *myself, PyObject *args, PyObject *kw)
{
DictRemoverObject *self = (DictRemoverObject *)myself;
if (self->key && self->dict) {
- if (-1 == PyDict_DelItem(self->dict, self->key))
- /* XXX Error context */
- PyErr_WriteUnraisable(Py_None);
+ if (-1 == PyDict_DelItem(self->dict, self->key)) {
+ _PyErr_WriteUnraisableMsg("on calling _ctypes.DictRemover", NULL);
+ }
Py_CLEAR(self->key);
Py_CLEAR(self->dict);
}
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c
index 7945f49..51e5d80 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;
}
diff --git a/Modules/gcmodule.c b/Modules/gcmodule.c
index be9b73a..3b15c7b 100644
--- a/Modules/gcmodule.c
+++ b/Modules/gcmodule.c
@@ -929,9 +929,8 @@ delete_garbage(struct _gc_runtime_state *state,
Py_INCREF(op);
(void) clear(op);
if (PyErr_Occurred()) {
- PySys_WriteStderr("Exception ignored in tp_clear of "
- "%.50s\n", Py_TYPE(op)->tp_name);
- PyErr_WriteUnraisable(NULL);
+ _PyErr_WriteUnraisableMsg("in tp_clear of",
+ (PyObject*)Py_TYPE(op));
}
Py_DECREF(op);
}