cpython: 5bd9db528aed (original) (raw)

Mercurial > cpython

changeset 84706:5bd9db528aed

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. [#18408]

Victor Stinner victor.stinner@gmail.com
date Thu, 18 Jul 2013 01:49:30 +0200
parents 9bae7696951f
children ddff866d820d
files Objects/object.c Objects/typeobject.c
diffstat 2 files changed, 23 insertions(+), 0 deletions(-)[+] [-] Objects/object.c 16 Objects/typeobject.c 7

line wrap: on

line diff

--- a/Objects/object.c +++ b/Objects/object.c @@ -377,6 +377,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

+#endif + res = (*v->ob_type->tp_repr)(v); if (res == NULL) return NULL; @@ -408,6 +416,7 @@ PyObject_Str(PyObject *v) #endif if (v == NULL) return PyUnicode_FromString(""); + if (PyUnicode_CheckExact(v)) { #ifndef Py_DEBUG if (PyUnicode_READY(v) < 0) @@ -419,6 +428,13 @@ PyObject_Str(PyObject *v) if (Py_TYPE(v)->tp_str == NULL) return PyObject_Repr(v); +#ifdef Py_DEBUG

+#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"))

--- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -736,6 +736,13 @@ type_call(PyTypeObject *type, PyObject * return NULL; } +#ifdef Py_DEBUG

+#endif + obj = type->tp_new(type, args, kwds); if (obj != NULL) { /* Ugly exception: when the call was type(something),