From 4bb5ee4b17ef9cd1cf32aec3ae3d58a5a8bcd5e8 Mon Sep 17 00:00:00 2001 From: Dave Abrahams Date: Fri, 5 Apr 2002 04:11:04 +0000 Subject: [PATCH] Fixes for GC interoperability [SVN r13373] --- src/object/class.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/object/class.cpp b/src/object/class.cpp index 9341da7d..487dc01c 100644 --- a/src/object/class.cpp +++ b/src/object/class.cpp @@ -23,6 +23,18 @@ instance_holder::~instance_holder() { } +// This is copied from typeobject.c in the Python sources. Even though +// class_metatype_object doesn't set Py_TPFLAGS_HAVE_GC, that bit gets +// filled in by the base class initialization process in +// PyType_Ready(). However, tp_is_gc is *not* copied from the base +// type, making it assume that classes are GC-able even if (like +// class_type_object) they're statically allocated. +static int +type_is_gc(PyTypeObject *python_type) +{ + return python_type->tp_flags & Py_TPFLAGS_HEAPTYPE; +} + PyTypeObject class_metatype_object = { PyObject_HEAD_INIT(0)//&PyType_Type) 0, @@ -63,8 +75,9 @@ PyTypeObject class_metatype_object = { 0, /* tp_dictoffset */ 0, /* tp_init */ 0, /* tp_alloc */ - 0, - // PyType_GenericNew /* tp_new */ + 0, // filled in with type_new /* tp_new */ + 0, // filled in with __PyObject_GC_Del /* tp_free */ + (inquiry)type_is_gc, /* tp_is_gc */ }; // Get the metatype object for all extension classes.