summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2001-04-27 21:35:01 (GMT)
committerGuido van Rossum <guido@python.org>2001-04-27 21:35:01 (GMT)
commit3a80c4a29c9eca9699b5bfe80541bc413a83bcef (patch)
tree5c94eeeb2548888e32f0bb68f0a9b85b95b17fc2
parente9bcb5c766635575ac33376fd4da6a38a86ddff1 (diff)
downloadcpython-3a80c4a29c9eca9699b5bfe80541bc413a83bcef.zip
cpython-3a80c4a29c9eca9699b5bfe80541bc413a83bcef.tar.gz
cpython-3a80c4a29c9eca9699b5bfe80541bc413a83bcef.tar.bz2
(Adding this to the trunk as well.)
Fix a very old flaw in PyObject_Print(). Amazing! When an object type defines tp_str but not tp_repr, 'print x' to a real file object would not call the tp_str slot but rather print a default style representation: <foo object at 0x....>. This even though 'print x' to a file-like-object would correctly call the tp_str slot.
-rw-r--r--Objects/object.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/Objects/object.c b/Objects/object.c
index 47907bc..1ace8f5 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -196,7 +196,10 @@ PyObject_Print(PyObject *op, FILE *fp, int flags)
fprintf(fp, "<refcnt %u at %p>",
op->ob_refcnt, op);
else if (op->ob_type->tp_print == NULL) {
- if (op->ob_type->tp_repr == NULL) {
+ if ((flags & Py_PRINT_RAW)
+ ? (op->ob_type->tp_str == NULL)
+ : (op->ob_type->tp_repr == NULL))
+ {
fprintf(fp, "<%s object at %p>",
op->ob_type->tp_name, op);
}