Skip to content

Commit 1799453

Browse files
Fix clearing the fields.
1 parent 05d4c12 commit 1799453

File tree

1 file changed

+20
-23
lines changed

1 file changed

+20
-23
lines changed

Objects/typeobject.c

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ static inline PyObject * lookup_tp_dict(PyTypeObject *type);
211211
static inline void init_tp_dict(PyTypeObject *type, PyObject *dict);
212212
static inline void clear_tp_dict(PyTypeObject *type);
213213
static inline PyObject * lookup_tp_bases(PyTypeObject *type);
214+
static inline void clear_tp_bases(PyTypeObject *type);
214215

215216
int
216217
_PyType_CheckConsistency(PyTypeObject *type)
@@ -862,6 +863,18 @@ init_tp_bases(PyTypeObject *type, PyObject *bases)
862863
type->tp_bases = bases;
863864
}
864865

866+
static inline void
867+
clear_tp_bases(PyTypeObject *type)
868+
{
869+
if (type->tp_flags & _Py_TPFLAGS_STATIC_BUILTIN) {
870+
static_builtin_state *state = _PyStaticType_GetState(type);
871+
assert(state != NULL);
872+
Py_CLEAR(state->tp_bases);
873+
return;
874+
}
875+
Py_CLEAR(type->tp_bases);
876+
}
877+
865878
static PyObject *
866879
type_get_bases(PyTypeObject *type, void *context)
867880
{
@@ -4586,34 +4599,18 @@ clear_static_tp_subclasses(PyTypeObject *type)
45864599
clear_tp_subclasses(type);
45874600
}
45884601

4589-
static void
4590-
clear_static_type_interp_data(PyTypeObject *type)
4591-
{
4592-
if (type->tp_flags & _Py_TPFLAGS_STATIC_BUILTIN) {
4593-
static_builtin_state *state = _PyStaticType_GetState(type);
4594-
assert(state != NULL);
4595-
4596-
Py_CLEAR(state->tp_dict);
4597-
Py_CLEAR(state->tp_bases);
4598-
Py_CLEAR(state->tp_mro);
4599-
}
4600-
else {
4601-
Py_CLEAR(type->tp_dict);
4602-
Py_CLEAR(type->tp_bases);
4603-
Py_CLEAR(type->tp_mro);
4604-
}
4605-
clear_static_tp_subclasses(type);
4606-
}
4607-
46084602
void
46094603
_PyStaticType_Dealloc(PyTypeObject *type)
46104604
{
46114605
assert(!(type->tp_flags & Py_TPFLAGS_HEAPTYPE));
46124606

46134607
type_dealloc_common(type);
46144608

4609+
clear_tp_dict(type);
4610+
clear_tp_bases(type);
4611+
clear_tp_mro(type);
46154612
Py_CLEAR(type->tp_cache);
4616-
clear_static_type_interp_data(type);
4613+
clear_static_tp_subclasses(type);
46174614

46184615
// PyObject_ClearWeakRefs() raises an exception if Py_REFCNT() != 0
46194616
if (Py_REFCNT(type) == 0) {
@@ -4647,9 +4644,9 @@ type_dealloc(PyTypeObject *type)
46474644
PyObject_ClearWeakRefs((PyObject *)type);
46484645

46494646
Py_XDECREF(type->tp_base);
4650-
Py_XDECREF(type->tp_dict);
4651-
Py_XDECREF(type->tp_bases);
4652-
Py_XDECREF(type->tp_mro);
4647+
clear_tp_dict(type);
4648+
clear_tp_bases(type);
4649+
clear_tp_mro(type);
46534650
Py_XDECREF(type->tp_cache);
46544651
clear_tp_subclasses(type);
46554652

0 commit comments

Comments
 (0)