summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2002-07-08 22:11:52 (GMT)
committerTim Peters <tim.peters@gmail.com>2002-07-08 22:11:52 (GMT)
commitc6a3ff634a90cb8b028019e3c8c48a221739ee26 (patch)
tree45cded7528a7d0f7b2a8f4da1aa8016f5b84bec1 /Objects
parentd1b2045958306349b04da931a1a400d7e9a49fb9 (diff)
downloadcpython-c6a3ff634a90cb8b028019e3c8c48a221739ee26.zip
cpython-c6a3ff634a90cb8b028019e3c8c48a221739ee26.tar.gz
cpython-c6a3ff634a90cb8b028019e3c8c48a221739ee26.tar.bz2
SF bug 578752: COUNT_ALLOCS vs heap types
Repair segfaults and infinite loops in COUNT_ALLOCS builds in the presence of new-style (heap-allocated) classes/types. Bugfix candidate. I'll backport this to 2.2. It's irrelevant in 2.1.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/object.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/Objects/object.c b/Objects/object.c
index 5c53908..fd069f1 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -74,6 +74,15 @@ inc_count(PyTypeObject *tp)
if (tp->tp_next != NULL) /* sanity check */
Py_FatalError("XXX inc_count sanity check");
tp->tp_next = type_list;
+ /* Note that as of Python 2.2, heap-allocated type objects
+ * can go away, but this code requires that they stay alive
+ * until program exit. That's why we're careful with
+ * refcounts here. type_list gets a new reference to tp,
+ * while ownership of the reference type_list used to hold
+ * (if any) was transferred to tp->tp_next in the line above.
+ * tp is thus effectively immortal after this.
+ */
+ Py_INCREF(tp);
type_list = tp;
}
tp->tp_allocs++;