File tree 3 files changed +19
-1
lines changed
3 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -70,6 +70,7 @@ extern PyStatus _PyTypes_InitSlotDefs(void);
70
70
71
71
extern int _PyStaticType_InitBuiltin (PyTypeObject * type );
72
72
extern static_builtin_state * _PyStaticType_GetState (PyTypeObject * );
73
+ extern void _PyStaticType_ClearWeakRefs (PyTypeObject * type );
73
74
extern void _PyStaticType_Dealloc (PyTypeObject * type );
74
75
75
76
Original file line number Diff line number Diff line change @@ -140,7 +140,7 @@ static_builtin_state_clear(PyTypeObject *self)
140
140
141
141
static_builtin_state * state = static_builtin_state_get (interp , self );
142
142
state -> type = NULL ;
143
- /* state->tp_weaklist should already have been cleared out. */
143
+ assert ( state -> tp_weaklist == NULL ); // It was already cleared out.
144
144
static_builtin_index_clear (self );
145
145
146
146
assert (interp -> types .num_builtins_initialized > 0 );
@@ -4358,6 +4358,7 @@ _PyStaticType_Dealloc(PyTypeObject *type)
4358
4358
type -> tp_flags &= ~Py_TPFLAGS_READY ;
4359
4359
4360
4360
if (type -> tp_flags & _Py_TPFLAGS_STATIC_BUILTIN ) {
4361
+ _PyStaticType_ClearWeakRefs (type );
4361
4362
static_builtin_state_clear (type );
4362
4363
/* We leave _Py_TPFLAGS_STATIC_BUILTIN set on tp_flags. */
4363
4364
}
Original file line number Diff line number Diff line change @@ -1018,3 +1018,19 @@ PyObject_ClearWeakRefs(PyObject *object)
1018
1018
PyErr_Restore (err_type , err_value , err_tb );
1019
1019
}
1020
1020
}
1021
+
1022
+ /* This function is called by _PyStaticType_Dealloc() to clear weak references.
1023
+ *
1024
+ * This is called at the end of runtime finalization, so we can just
1025
+ * wipe out the type's weaklist. We don't bother with callbacks
1026
+ * or anything else.
1027
+ */
1028
+ void
1029
+ _PyStaticType_ClearWeakRefs (PyTypeObject * type )
1030
+ {
1031
+ static_builtin_state * state = _PyStaticType_GetState (type );
1032
+ PyObject * * list = _PyStaticType_GET_WEAKREFS_LISTPTR (state );
1033
+ while (* list != NULL ) {
1034
+ clear_weakref ((PyWeakReference * )* list );
1035
+ }
1036
+ }
You can’t perform that action at this time.
0 commit comments