diff options
author | Miss Skeleton (bot) <31488909+miss-islington@users.noreply.github.com> | 2020-10-15 03:38:25 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-15 03:38:25 (GMT) |
commit | d197b2bb3e401bed53987b65a7ceb6c712c4f5bd (patch) | |
tree | eb6a228d93fb633b7fd2719b1ad37e8c4c0bf593 /Objects/typeobject.c | |
parent | f07448bef48d645c8cee862b1f25a99003a6140e (diff) | |
download | cpython-d197b2bb3e401bed53987b65a7ceb6c712c4f5bd.zip cpython-d197b2bb3e401bed53987b65a7ceb6c712c4f5bd.tar.gz cpython-d197b2bb3e401bed53987b65a7ceb6c712c4f5bd.tar.bz2 |
bpo-41984: GC track all user classes (GH-22701/GH-22702)
(cherry picked from commit c13b847a6f913b72eeb71651ff626390b738d973)
Diffstat (limited to 'Objects/typeobject.c')
-rw-r--r-- | Objects/typeobject.c | 22 |
1 files changed, 6 insertions, 16 deletions
diff --git a/Objects/typeobject.c b/Objects/typeobject.c index f65434f..1a12b0c 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -2605,10 +2605,10 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds) slots = NULL; /* Initialize tp_flags */ + // All heap types need GC, since we can create a reference cycle by storing + // an instance on one of its parents: type->tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE | - Py_TPFLAGS_BASETYPE; - if (base->tp_flags & Py_TPFLAGS_HAVE_GC) - type->tp_flags |= Py_TPFLAGS_HAVE_GC; + Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC; /* Initialize essential fields */ type->tp_as_async = &et->as_async; @@ -2808,21 +2808,11 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds) } type->tp_dealloc = subtype_dealloc; - /* 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 */ type->tp_alloc = PyType_GenericAlloc; - if (type->tp_flags & Py_TPFLAGS_HAVE_GC) { - type->tp_free = PyObject_GC_Del; - type->tp_traverse = subtype_traverse; - type->tp_clear = subtype_clear; - } - else - type->tp_free = PyObject_Del; + type->tp_free = PyObject_GC_Del; + type->tp_traverse = subtype_traverse; + type->tp_clear = subtype_clear; /* store type in class' cell if one is supplied */ cell = _PyDict_GetItemIdWithError(dict, &PyId___classcell__); |