summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1998-04-10 22:47:27 (GMT)
committerGuido van Rossum <guido@python.org>1998-04-10 22:47:27 (GMT)
commitfb376dee5576c57018c9032a21200ba7467cf324 (patch)
treef245382d16f63434d43645e689a11be7b391669d /Objects
parent255443b72058ba930ac6fe2f19a37be39e7fee49 (diff)
downloadcpython-fb376dee5576c57018c9032a21200ba7467cf324.zip
cpython-fb376dee5576c57018c9032a21200ba7467cf324.tar.gz
cpython-fb376dee5576c57018c9032a21200ba7467cf324.tar.bz2
Use Py_Repr{Enter,Leave} to display recursive lists in finite space.
(Jeremy will hardly recognize his patch :-)
Diffstat (limited to 'Objects')
-rw-r--r--Objects/listobject.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/Objects/listobject.c b/Objects/listobject.c
index 8bec8af..29c50f4 100644
--- a/Objects/listobject.c
+++ b/Objects/listobject.c
@@ -231,14 +231,25 @@ list_print(op, fp, flags)
int flags;
{
int i;
+
+ i = Py_ReprEnter((PyObject*)op);
+ if (i != 0) {
+ if (i < 0)
+ return i;
+ fprintf(fp, "[...]");
+ return 0;
+ }
fprintf(fp, "[");
for (i = 0; i < op->ob_size; i++) {
if (i > 0)
fprintf(fp, ", ");
- if (PyObject_Print(op->ob_item[i], fp, 0) != 0)
+ if (PyObject_Print(op->ob_item[i], fp, 0) != 0) {
+ Py_ReprLeave((PyObject *)op);
return -1;
+ }
}
fprintf(fp, "]");
+ Py_ReprLeave((PyObject *)op);
return 0;
}
@@ -248,6 +259,13 @@ list_repr(v)
{
PyObject *s, *comma;
int i;
+
+ i = Py_ReprEnter((PyObject*)v);
+ if (i != 0) {
+ if (i > 0)
+ return PyString_FromString("[...]");
+ return NULL;
+ }
s = PyString_FromString("[");
comma = PyString_FromString(", ");
for (i = 0; i < v->ob_size && s != NULL; i++) {
@@ -257,6 +275,7 @@ list_repr(v)
}
Py_XDECREF(comma);
PyString_ConcatAndDel(&s, PyString_FromString("]"));
+ Py_ReprLeave((PyObject *)v);
return s;
}