diff options
author | Victor Stinner <vstinner@python.org> | 2022-01-22 23:32:05 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-22 23:32:05 (GMT) |
commit | a1444f43584af0f7a0af72aa06ba0a86ae5a87a2 (patch) | |
tree | 467ee01b8a6dcb346c90d83f8319f4453d532aff /Objects/typeobject.c | |
parent | 12f4ac3bc848244242d6b8a7ee158b985fd64744 (diff) | |
download | cpython-a1444f43584af0f7a0af72aa06ba0a86ae5a87a2.zip cpython-a1444f43584af0f7a0af72aa06ba0a86ae5a87a2.tar.gz cpython-a1444f43584af0f7a0af72aa06ba0a86ae5a87a2.tar.bz2 |
bpo-46417: Fix _PyStaticType_Dealloc() (GH-30810)
_PyStaticType_Dealloc() now only calls PyObject_ClearWeakRefs()
if the call is not going to fail.
Diffstat (limited to 'Objects/typeobject.c')
-rw-r--r-- | Objects/typeobject.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/Objects/typeobject.c b/Objects/typeobject.c index cc4612f..4527593 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -4071,8 +4071,6 @@ type_dealloc_common(PyTypeObject *type) remove_all_subclasses(type, type->tp_bases); PyErr_Restore(tp, val, tb); } - - PyObject_ClearWeakRefs((PyObject *)type); } @@ -4094,6 +4092,11 @@ _PyStaticType_Dealloc(PyTypeObject *type) Py_CLEAR(type->tp_cache); // type->tp_subclasses is NULL + // PyObject_ClearWeakRefs() raises an exception if Py_REFCNT() != 0 + if (Py_REFCNT(type) == 0) { + PyObject_ClearWeakRefs((PyObject *)type); + } + type->tp_flags &= ~Py_TPFLAGS_READY; } @@ -4101,12 +4104,17 @@ _PyStaticType_Dealloc(PyTypeObject *type) static void type_dealloc(PyTypeObject *type) { - /* Assert this is a heap-allocated type object */ + // Assert this is a heap-allocated type object _PyObject_ASSERT((PyObject *)type, type->tp_flags & Py_TPFLAGS_HEAPTYPE); + _PyObject_GC_UNTRACK(type); type_dealloc_common(type); + // PyObject_ClearWeakRefs() raises an exception if Py_REFCNT() != 0 + assert(Py_REFCNT(type) == 0); + PyObject_ClearWeakRefs((PyObject *)type); + Py_XDECREF(type->tp_base); Py_XDECREF(type->tp_dict); Py_XDECREF(type->tp_bases); |