summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2007-08-09 20:47:59 (GMT)
committerGuido van Rossum <guido@python.org>2007-08-09 20:47:59 (GMT)
commit6ca130d0dba71dd494ae284a76e45e7050132468 (patch)
tree6ca9d52e87fc0ebf9da0497573d5e8ce660b6f9d /Objects
parent66aaf74e52d36e455af0b771c2c02f02ab05b387 (diff)
downloadcpython-6ca130d0dba71dd494ae284a76e45e7050132468.zip
cpython-6ca130d0dba71dd494ae284a76e45e7050132468.tar.gz
cpython-6ca130d0dba71dd494ae284a76e45e7050132468.tar.bz2
Oops. The PyObject_Print() function was totally broken; the original code
was relying on PyString.tp_print but that no longer works. Fortunately it's rarely called; only the gdb 'pyo' command seems affected.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/object.c22
1 files changed, 19 insertions, 3 deletions
diff --git a/Objects/object.c b/Objects/object.c
index 3eaf6fa..04d5f48 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -284,12 +284,28 @@ internal_print(PyObject *op, FILE *fp, int flags, int nesting)
if (flags & Py_PRINT_RAW)
s = PyObject_Str(op);
else
- s = PyObject_ReprStr8(op);
+ s = PyObject_Repr(op);
if (s == NULL)
ret = -1;
+ else if (PyString_Check(s)) {
+ fwrite(PyString_AS_STRING(s), 1,
+ PyString_GET_SIZE(s), fp);
+ }
+ else if (PyUnicode_Check(s)) {
+ PyObject *t;
+ t = _PyUnicode_AsDefaultEncodedString(s, NULL);
+ if (t == NULL)
+ ret = 0;
+ else {
+ fwrite(PyString_AS_STRING(t), 1,
+ PyString_GET_SIZE(t), fp);
+ }
+ }
else {
- ret = internal_print(s, fp, Py_PRINT_RAW,
- nesting+1);
+ PyErr_Format(PyExc_TypeError,
+ "str() or repr() returned '%.100s'",
+ s->ob_type->tp_name);
+ ret = -1;
}
Py_XDECREF(s);
}