Issue #23726: Don't enable GC for user subclasses of non-GC types that don't add any new fields.

Patch by Eugene Toder.
This commit is contained in:
Antoine Pitrou 2015-04-13 20:10:06 +02:00
parent 56452eea39
commit a63cc21234
4 changed files with 27 additions and 5 deletions

View file

@ -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 */