File tree Expand file tree Collapse file tree 2 files changed +7
-2
lines changed Expand file tree Collapse file tree 2 files changed +7
-2
lines changed Original file line number Diff line number Diff line change @@ -71,6 +71,8 @@ static inline int _PyWeakref_IS_DEAD(PyObject *ref_obj)
71
71
return ret ;
72
72
}
73
73
74
+ // NB: In free-threaded builds the referenced object must be live for the
75
+ // duration of the call.
74
76
extern Py_ssize_t _PyWeakref_GetWeakrefCount (PyWeakReference * head );
75
77
76
78
extern void _PyWeakref_ClearRef (PyWeakReference * self );
@@ -79,4 +81,3 @@ extern void _PyWeakref_ClearRef(PyWeakReference *self);
79
81
}
80
82
#endif
81
83
#endif /* !Py_INTERNAL_WEAKREF_H */
82
-
Original file line number Diff line number Diff line change @@ -108,11 +108,15 @@ Py_ssize_t
108
108
_PyWeakref_GetWeakrefCount (PyWeakReference * head )
109
109
{
110
110
Py_ssize_t count = 0 ;
111
-
111
+ if (head == NULL ) {
112
+ return 0 ;
113
+ }
114
+ Py_BEGIN_CRITICAL_SECTION (head -> wr_object );
112
115
while (head != NULL ) {
113
116
++ count ;
114
117
head = head -> wr_next ;
115
118
}
119
+ Py_END_CRITICAL_SECTION ();
116
120
return count ;
117
121
}
118
122
You can’t perform that action at this time.
0 commit comments