summaryrefslogtreecommitdiff
path: root/Objects/object.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1992-09-03 20:32:55 +0000
committerGuido van Rossum <guido@python.org>1992-09-03 20:32:55 +0000
commit9c166fdbe44985c1f8536688a7ca91b9a829b9ca (patch)
treec6c95cd5c60b3f437238979ce8205881b1c2b7a2 /Objects/object.c
parentd984829385c3961b17ffc8116fe5c62bc5d558a1 (diff)
downloadcpython-9c166fdbe44985c1f8536688a7ca91b9a829b9ca.tar.gz
If a type has a repr function but no print function, printing it now
calls the repr function. When the refcount is bad, don't print the object at all (chances of crashes). Changes to checking and printing of references: the consistency check is somewhat faster; don't print strings referenced once (most occur in function's name lists).
Diffstat (limited to 'Objects/object.c')
-rw-r--r--Objects/object.c39
1 files changed, 34 insertions, 5 deletions
diff --git a/Objects/object.c b/Objects/object.c
index 5f54b364b8..16053a9780 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -77,10 +77,28 @@ printobject(op, fp, flags)
}
else {
if (op->ob_refcnt <= 0)
- fprintf(fp, "(refcnt %u):", op->ob_refcnt);
- if (op->ob_type->tp_print == NULL)
- fprintf(fp, "<%s object at %lx>",
- op->ob_type->tp_name, (long)op);
+ fprintf(fp, "<refcnt %u at %lx>",
+ op->ob_refcnt, (long)op);
+ else if (op->ob_type->tp_print == NULL) {
+ if (op->ob_type->tp_repr == NULL) {
+ fprintf(fp, "<%s object at %lx>",
+ op->ob_type->tp_name, (long)op);
+ }
+ else {
+ object *s = reprobject(op);
+ if (s == NULL)
+ ret = -1;
+ else if (!is_stringobject(s)) {
+ err_setstr(TypeError,
+ "repr not string");
+ ret = -1;
+ }
+ else {
+ fprintf(fp, "%s", getstringvalue(s));
+ }
+ XDECREF(s);
+ }
+ }
else
ret = (*op->ob_type->tp_print)(op, fp, flags);
}
@@ -252,6 +270,12 @@ UNREF(op)
fprintf(stderr, "UNREF negative refcnt\n");
abort();
}
+ if (op == &refchain ||
+ op->_ob_prev->_ob_next != op || op->_ob_next->_ob_prev != op) {
+ fprintf(stderr, "UNREF invalid object\n");
+ abort();
+ }
+#ifdef SLOW_UNREF_CHECK
for (p = refchain._ob_next; p != &refchain; p = p->_ob_next) {
if (p == op)
break;
@@ -260,8 +284,10 @@ UNREF(op)
fprintf(stderr, "UNREF unknown object\n");
abort();
}
+#endif
op->_ob_next->_ob_prev = op->_ob_prev;
op->_ob_prev->_ob_next = op->_ob_next;
+ op->_ob_next = op->_ob_prev = NULL;
}
DELREF(op)
@@ -269,14 +295,17 @@ DELREF(op)
{
UNREF(op);
(*(op)->ob_type->tp_dealloc)(op);
+ op->ob_type = NULL;
}
printrefs(fp)
FILE *fp;
{
object *op;
- fprintf(fp, "Remaining objects:\n");
+ fprintf(fp, "Remaining objects (except strings referenced once):\n");
for (op = refchain._ob_next; op != &refchain; op = op->_ob_next) {
+ if (op->ob_refcnt == 1 && is_stringobject(op))
+ continue; /* Will be printed elsewhere */
fprintf(fp, "[%d] ", op->ob_refcnt);
if (printobject(op, fp, 0) != 0)
err_clear();