diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2017-10-17 22:14:19 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2017-10-17 22:14:19 (GMT) |
commit | 2712247ec94dcc12cf9abeec78f18f54fcc3357a (patch) | |
tree | 75e8771fb391d7f199ed20cc464cb93724b72f39 /Python/pythonrun.c | |
parent | 858ea4354fafa36e57859d2dfd70f8a057984075 (diff) | |
download | cpython-2712247ec94dcc12cf9abeec78f18f54fcc3357a.zip cpython-2712247ec94dcc12cf9abeec78f18f54fcc3357a.tar.gz cpython-2712247ec94dcc12cf9abeec78f18f54fcc3357a.tar.bz2 |
[3.6] bpo-28603: Fix formatting tracebacks for unhashable exceptions (GH-4014) (#4024)
(cherry picked from commit de86073a761cd3539aaca6f886a1f55effc0d9da)
Diffstat (limited to 'Python/pythonrun.c')
-rw-r--r-- | Python/pythonrun.c | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/Python/pythonrun.c b/Python/pythonrun.c index 8befa54..bf651d0 100644 --- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -811,13 +811,21 @@ print_exception_recursive(PyObject *f, PyObject *value, PyObject *seen) if (seen != NULL) { /* Exception chaining */ - if (PySet_Add(seen, value) == -1) + PyObject *value_id = PyLong_FromVoidPtr(value); + if (value_id == NULL || PySet_Add(seen, value_id) == -1) PyErr_Clear(); else if (PyExceptionInstance_Check(value)) { + PyObject *check_id = NULL; cause = PyException_GetCause(value); context = PyException_GetContext(value); if (cause) { - res = PySet_Contains(seen, cause); + check_id = PyLong_FromVoidPtr(cause); + if (check_id == NULL) { + res = -1; + } else { + res = PySet_Contains(seen, check_id); + Py_DECREF(check_id); + } if (res == -1) PyErr_Clear(); if (res == 0) { @@ -829,7 +837,13 @@ print_exception_recursive(PyObject *f, PyObject *value, PyObject *seen) } else if (context && !((PyBaseExceptionObject *)value)->suppress_context) { - res = PySet_Contains(seen, context); + check_id = PyLong_FromVoidPtr(context); + if (check_id == NULL) { + res = -1; + } else { + res = PySet_Contains(seen, check_id); + Py_DECREF(check_id); + } if (res == -1) PyErr_Clear(); if (res == 0) { @@ -842,6 +856,7 @@ print_exception_recursive(PyObject *f, PyObject *value, PyObject *seen) Py_XDECREF(context); Py_XDECREF(cause); } + Py_XDECREF(value_id); } print_exception(f, value); if (err != 0) |