gh-135607: remove null checking of weakref list in dealloc of extension modules and objects (#135614)

Co-authored-by: Kumar Aditya <kumaraditya@python.org>
Co-authored-by: Victor Stinner <vstinner@python.org>
This commit is contained in:
Xuanteng Huang 2025-06-30 19:14:31 +08:00 committed by GitHub
parent 0533c1faf2
commit b1056c2a44
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
32 changed files with 77 additions and 83 deletions

View file

@ -29,6 +29,12 @@ extern "C" {
PyMutex_LockFlags(wr->weakrefs_lock, _Py_LOCK_DONT_DETACH)
#define UNLOCK_WEAKREFS_FOR_WR(wr) PyMutex_Unlock(wr->weakrefs_lock)
#define FT_CLEAR_WEAKREFS(obj, weakref_list) \
do { \
assert(Py_REFCNT(obj) == 0); \
PyObject_ClearWeakRefs(obj); \
} while (0)
#else
#define LOCK_WEAKREFS(obj)
@ -37,6 +43,14 @@ extern "C" {
#define LOCK_WEAKREFS_FOR_WR(wr)
#define UNLOCK_WEAKREFS_FOR_WR(wr)
#define FT_CLEAR_WEAKREFS(obj, weakref_list) \
do { \
assert(Py_REFCNT(obj) == 0); \
if (weakref_list != NULL) { \
PyObject_ClearWeakRefs(obj); \
} \
} while (0)
#endif
static inline int _is_dead(PyObject *obj)