summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2015-04-13 18:10:06 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2015-04-13 18:10:06 (GMT)
commita63cc212348e276c8ede32773313c60ff7fda651 (patch)
treec47fdcc44d220ed930f465a3fb4f7303ba461742 /Objects
parent56452eea39baa9d1864b2275b9e93cf37378af09 (diff)
downloadcpython-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.c7
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 */