File tree Expand file tree Collapse file tree
Misc/NEWS.d/next/Core_and_Builtins Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -29,8 +29,11 @@ extern "C" {
2929 PyMutex_LockFlags(wr->weakrefs_lock, _Py_LOCK_DONT_DETACH)
3030#define UNLOCK_WEAKREFS_FOR_WR (wr ) PyMutex_Unlock(wr->weakrefs_lock)
3131
32- #define FT_CLEAR_WEAKREFS (obj , weakref_list ) \
33- PyObject_ClearWeakRefs(obj)
32+ #define FT_CLEAR_WEAKREFS (obj , weakref_list ) \
33+ do { \
34+ assert(Py_REFCNT(obj) == 0); \
35+ PyObject_ClearWeakRefs(obj); \
36+ } while (0)
3437
3538#else
3639
Original file line number Diff line number Diff line change 1- Fix potential :mod: `weakref ` races on objects dealloc on the :term: `free threaded <free
1+ Fix potential :mod: `weakref ` races in an object's destructor on the :term: `free threaded <free
22threading> ` build.
Original file line number Diff line number Diff line change @@ -737,8 +737,7 @@ pattern_dealloc(PyObject *self)
737737{
738738 PyTypeObject * tp = Py_TYPE (self );
739739 PyObject_GC_UnTrack (self );
740- PatternObject * obj = _PatternObject_CAST (self );
741- FT_CLEAR_WEAKREFS (self , obj -> weakreflist );
740+ FT_CLEAR_WEAKREFS (self , _PatternObject_CAST (self )-> weakreflist );
742741 (void )pattern_clear (self );
743742 tp -> tp_free (self );
744743 Py_DECREF (tp );
Original file line number Diff line number Diff line change @@ -1365,7 +1365,7 @@ static void
13651365localdummy_dealloc (PyObject * op )
13661366{
13671367 localdummyobject * self = localdummyobject_CAST (op );
1368- PyObject_ClearWeakRefs (op );
1368+ FT_CLEAR_WEAKREFS (op , self -> weakreflist );
13691369 PyTypeObject * tp = Py_TYPE (self );
13701370 tp -> tp_free (self );
13711371 Py_DECREF (tp );
You can’t perform that action at this time.
0 commit comments