mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
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:
parent
56452eea39
commit
a63cc21234
4 changed files with 27 additions and 5 deletions
|
@ -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 */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue