8000 bpo-46417: Fix _PyStaticType_Dealloc() (GH-30810) · python/cpython@a1444f4 · GitHub
[go: up one dir, main page]

Skip to content

Commit a1444f4

Browse files
authored
bpo-46417: Fix _PyStaticType_Dealloc() (GH-30810)
_PyStaticType_Dealloc() now only calls PyObject_ClearWeakRefs() if the call is not going to fail.
1 parent 12f4ac3 commit a1444f4

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

Objects/typeobject.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4071,8 +4071,6 @@ type_dealloc_common(PyTypeObject *type)
40714071
remove_all_subclasses(type, type->tp_bases);
40724072
PyErr_Restore(tp, val, tb);
40734073
}
4074-
4075-
PyObject_ClearWeakRefs((PyObject *)type);
40764074
}
40774075

40784076

@@ -4094,19 +4092,29 @@ _PyStaticType_Dealloc(PyTypeObject *type)
40944092
Py_CLEAR(type->tp_cache);
40954093
// type->tp_subclasses is NULL
40964094

4095+
// PyObject_ClearWeakRefs() raises an exception if Py_REFCNT() != 0
4096+
if (Py_REFCNT(type) == 0) {
4097+
PyObject_ClearWeakRefs((PyObject *)type);
4098+
}
4099+
40974100
type->tp_flags &= ~Py_TPFLAGS_READY;
40984101
}
40994102

41004103

41014104
static void
41024105
type_dealloc(PyTypeObject *type)
41034106
{
4104-
/* Assert this is a heap-allocated type object */
4107+
// Assert this is a heap-allocated type object
41054108
_PyObject_ASSERT((PyObject *)type, type->tp_flags & Py_TPFLAGS_HEAPTYPE);
4109+
41064110
_PyObject_GC_UNTRACK(type);
41074111

41084112
type_dealloc_common(type);
41094113

4114+
// PyObject_ClearWeakRefs() raises an exception if Py_REFCNT() != 0
4115+
assert(Py_REFCNT(type) == 0);
4116+
PyObject_ClearWeakRefs((PyObject *)type);
4117+
41104118
Py_XDECREF(type->tp_base);
41114119
Py_XDECREF(type->tp_dict);
41124120
Py_XDECREF(type->tp_bases);

0 commit comments

Comments
 (0)
0