diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2015-04-13 18:10:06 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2015-04-13 18:10:06 (GMT) |
commit | a63cc212348e276c8ede32773313c60ff7fda651 (patch) | |
tree | c47fdcc44d220ed930f465a3fb4f7303ba461742 /Objects | |
parent | 56452eea39baa9d1864b2275b9e93cf37378af09 (diff) | |
download | cpython-a63cc212348e276c8ede32773313c60ff7fda651.zip cpython-a63cc212348e276c8ede32773313c60ff7fda651.tar.gz cpython-a63cc212348e276c8ede32773313c60ff7fda651.tar.bz2 |
Issue #23726: Don't enable GC for user subclasses of non-GC types that don't add any new fields.
Patch by Eugene Toder.
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/typeobject.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 030dc1f..0e54fe6 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -2645,9 +2645,10 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds) } type->tp_dealloc = subtype_dealloc; - /* Enable GC unless there are really no instance variables possible */ - if (!(type->tp_basicsize == sizeof(PyObject) && - type->tp_itemsize == 0)) + /* Enable GC unless this class is not adding new instance variables and + the base class did not use GC. */ + if ((base->tp_flags & Py_TPFLAGS_HAVE_GC) || + type->tp_basicsize > base->tp_basicsize) type->tp_flags |= Py_TPFLAGS_HAVE_GC; /* Always override allocation strategy to use regular heap */ |