File tree Expand file tree Collapse file tree 3 files changed +12
-26
lines changed Expand file tree Collapse file tree 3 files changed +12
-26
lines changed Original file line number Diff line number Diff line change @@ -111,11 +111,7 @@ static inline int _PyWeakref_IS_DEAD(PyObject *ref_obj)
111
111
return ret ;
112
112
}
113
113
114
- // NB: In free-threaded builds the weakref list lock for the referenced object
115
- // must be held around calls to this function.
116
- extern Py_ssize_t _PyWeakref_GetWeakrefCount (PyWeakReference * head );
117
-
118
- extern Py_ssize_t _PyWeakref_GetWeakrefCountThreadsafe (PyObject * obj );
114
+ extern Py_ssize_t _PyWeakref_GetWeakrefCount (PyObject * obj );
119
115
120
116
// Clear all the weak references to obj but leave their callbacks uncalled and
121
117
// intact.
Original file line number Diff line number Diff line change @@ -26,10 +26,7 @@ static Py_ssize_t
26
26
_weakref_getweakrefcount_impl (PyObject * module , PyObject * object )
27
27
/*[clinic end generated code: output=301806d59558ff3e input=7d4d04fcaccf64d5]*/
28
28
{
29
- if (!_PyType_SUPPORTS_WEAKREFS (Py_TYPE (object ))) {
30
- return 0 ;
31
- }
32
- return _PyWeakref_GetWeakrefCountThreadsafe (object );
29
+ return _PyWeakref_GetWeakrefCount (object );
33
30
}
34
31
35
32
@@ -90,7 +87,7 @@ _weakref_getweakrefs(PyObject *module, PyObject *object)
90
87
}
91
88
92
89
PyWeakReference * * list = GET_WEAKREFS_LISTPTR (object );
93
- Py_ssize_t count = _PyWeakref_GetWeakrefCountThreadsafe (object );
90
+ Py_ssize_t count = _PyWeakref_GetWeakrefCount (object );
94
91
95
92
PyObject * result = PyList_New (count );
96
93
if (result == NULL ) {
Original file line number Diff line number Diff line change 39
39
40
40
41
41
Py_ssize_t
42
- _PyWeakref_GetWeakrefCount (PyWeakReference * head )
42
+ _PyWeakref_GetWeakrefCount (PyObject * obj )
43
43
{
44
- Py_ssize_t count = 0 ;
44
+ if (!_PyType_SUPPORTS_WEAKREFS (Py_TYPE (obj ))) {
45
+ return 0 ;
46
+ }
45
47
48
+ LOCK_WEAKREFS (obj );
49
+ Py_ssize_t count = 0 ;
50
+ PyWeakReference * head = * GET_WEAKREFS_LISTPTR (obj );
46
51
while (head != NULL ) {
47
52
++ count ;
48
53
head = head -> wr_next ;
49
54
}
50
- return count ;
51
- }
52
-
53
- Py_ssize_t
54
- _PyWeakref_GetWeakrefCountThreadsafe (PyObject * obj )
55
- {
56
- if (!_PyType_SUPPORTS_WEAKREFS (Py_TYPE (obj ))) {
57
- return 0 ;
58
- }
59
- Py_ssize_t count ;
60
- LOCK_WEAKREFS (obj );
61
- count = _PyWeakref_GetWeakrefCount (* GET_WEAKREFS_LISTPTR (obj ));
62
55
UNLOCK_WEAKREFS (obj );
63
56
return count ;
64
57
}
@@ -1114,7 +1107,7 @@ PyObject_ClearWeakRefs(PyObject *object)
1114
1107
}
1115
1108
1116
1109
/* Deal with non-canonical (subtypes or refs with callbacks) references. */
1117
- Py_ssize_t num_weakrefs = _PyWeakref_GetWeakrefCountThreadsafe (object );
1110
+ Py_ssize_t num_weakrefs = _PyWeakref_GetWeakrefCount (object );
1118
1111
if (num_weakrefs == 0 ) {
1119
1112
return ;
1120
1113
}
@@ -1168,7 +1161,7 @@ PyObject_ClearWeakRefs(PyObject *object)
1168
1161
}
1169
1162
if (* list != NULL ) {
1170
1163
PyWeakReference * current = * list ;
1171
- Py_ssize_t count = _PyWeakref_GetWeakrefCount (current );
1164
+ Py_ssize_t count = _PyWeakref_GetWeakrefCount (object );
1172
1165
PyObject * exc = PyErr_GetRaisedException ();
1173
1166
1174
1167
if (count == 1 ) {
You can’t perform that action at this time.
0 commit comments