summaryrefslogtreecommitdiffstats
path: root/Objects/object.c
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@wyplay.com>2013-08-26 12:05:19 (GMT)
committerVictor Stinner <vstinner@wyplay.com>2013-08-26 12:05:19 (GMT)
commit33824f6fd70f89dd39fcb7ed1651e8097c57d340 (patch)
tree6047d333614cdebc7ead3b836abd9e1656f3c0f2 /Objects/object.c
parentc82bfd871f33b824974469071469ac4fb491d547 (diff)
downloadcpython-33824f6fd70f89dd39fcb7ed1651e8097c57d340.zip
cpython-33824f6fd70f89dd39fcb7ed1651e8097c57d340.tar.gz
cpython-33824f6fd70f89dd39fcb7ed1651e8097c57d340.tar.bz2
Restore changeset 5bd9db528aed (issue #18408)
"Issue #18408: PyObject_Str(), PyObject_Repr() and type_call() now fail with an assertion error if they are called with an exception set (PyErr_Occurred()). As PyEval_EvalFrameEx(), they may clear the current exception and so the caller looses its exception."
Diffstat (limited to 'Objects/object.c')
-rw-r--r--Objects/object.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/Objects/object.c b/Objects/object.c
index 006f0d4..693d8c7 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -449,6 +449,14 @@ PyObject_Repr(PyObject *v)
if (Py_TYPE(v)->tp_repr == NULL)
return PyUnicode_FromFormat("<%s object at %p>",
v->ob_type->tp_name, v);
+
+#ifdef Py_DEBUG
+ /* PyObject_Repr() must not be called with an exception set,
+ because it may clear it (directly or indirectly) and so the
+ caller looses its exception */
+ assert(!PyErr_Occurred());
+#endif
+
res = (*v->ob_type->tp_repr)(v);
if (res == NULL)
return NULL;
@@ -491,6 +499,13 @@ PyObject_Str(PyObject *v)
if (Py_TYPE(v)->tp_str == NULL)
return PyObject_Repr(v);
+#ifdef Py_DEBUG
+ /* PyObject_Str() must not be called with an exception set,
+ because it may clear it (directly or indirectly) and so the
+ caller looses its exception */
+ assert(!PyErr_Occurred());
+#endif
+
/* It is possible for a type to have a tp_str representation that loops
infinitely. */
if (Py_EnterRecursiveCall(" while getting the str of an object"))