@@ -15,7 +15,7 @@ module _weakref
15
15
#include "clinic/_weakref.c.h"
16
16
17
17
/*[clinic input]
18
-
18
+ @critical_section object
19
19
_weakref.getweakrefcount -> Py_ssize_t
20
20
21
21
object: object
@@ -26,17 +26,13 @@ Return the number of weak references to 'object'.
26
26
27
27
static Py_ssize_t
28
28
_weakref_getweakrefcount_impl (PyObject * module , PyObject * object )
29
- /*[clinic end generated code: output=301806d59558ff3e input=cedb69711b6a2507 ]*/
29
+ /*[clinic end generated code: output=301806d59558ff3e input=6535a580f1d0ebdc ]*/
30
30
{
31
- PyWeakReference * * list ;
32
-
33
- if (!_PyType_SUPPORTS_WEAKREFS (Py_TYPE (object )))
31
+ if (!_PyType_SUPPORTS_WEAKREFS (Py_TYPE (object ))) {
34
32
return 0 ;
35
- Py_ssize_t count ;
36
- Py_BEGIN_CRITICAL_SECTION (object );
37
- list = GET_WEAKREFS_LISTPTR (object );
38
- count = _PyWeakref_GetWeakrefCount (* list );
39
- Py_END_CRITICAL_SECTION ();
33
+ }
34
+ PyWeakReference * * list = GET_WEAKREFS_LISTPTR (object );
35
+ Py_ssize_t count = _PyWeakref_GetWeakrefCount (* list );
40
36
return count ;
41
37
}
42
38
@@ -86,6 +82,7 @@ _weakref__remove_dead_weakref_impl(PyObject *module, PyObject *dct,
86
82
87
83
88
84
/*[clinic input]
85
+ @critical_section object
89
86
_weakref.getweakrefs
90
87
object: object
91
88
/
@@ -94,30 +91,26 @@ Return a list of all weak reference objects pointing to 'object'.
94
91
[clinic start generated code]*/
95
92
96
93
static PyObject *
97
- _weakref_getweakrefs (PyObject * module , PyObject * object )
98
- /*[clinic end generated code: output=25c7731d8e011824 input=00c6d0e5d3206693 ]*/
94
+ _weakref_getweakrefs_impl (PyObject * module , PyObject * object )
95
+ /*[clinic end generated code: output=5ec268989fb8f035 input=3dea95b8f5b31bbb ]*/
99
96
{
100
97
if (!_PyType_SUPPORTS_WEAKREFS (Py_TYPE (object ))) {
101
98
return PyList_New (0 );
102
99
}
103
100
104
- PyObject * result ;
105
- Py_BEGIN_CRITICAL_SECTION (object );
106
101
PyWeakReference * * list = GET_WEAKREFS_LISTPTR (object );
107
102
Py_ssize_t count = _PyWeakref_GetWeakrefCount (* list );
108
103
109
- result = PyList_New (count );
104
+ PyObject * result = PyList_New (count );
110
105
if (result == NULL ) {
111
- goto exit ;
106
+ return NULL ;
112
107
}
113
108
114
109
PyWeakReference * current = * list ;
115
110
for (Py_ssize_t i = 0 ; i < count ; ++ i ) {
116
111
PyList_SET_ITEM (result , i , Py_NewRef (current ));
117
112
current = current -> wr_next ;
118
113
}
119
- exit :
120
- Py_END_CRITICAL_SECTION ();
121
114
return result ;
122
115
}
123
116
0 commit comments