File tree 4 files changed +20
-22
lines changed 4 files changed +20
-22
lines changed Original file line number Diff line number Diff line change @@ -32,10 +32,6 @@ struct _PyWeakReference {
32
32
vectorcallfunc vectorcall ;
33
33
};
34
34
35
- PyAPI_FUNC (Py_ssize_t ) _PyWeakref_GetWeakrefCount (PyWeakReference * head );
36
-
37
- PyAPI_FUNC (void ) _PyWeakref_ClearRef (PyWeakReference * self );
38
-
39
35
static inline PyObject * PyWeakref_GET_OBJECT (PyObject * ref_obj ) {
40
36
PyWeakReference * ref ;
41
37
PyObject * obj ;
Original file line number Diff line number Diff line change @@ -46,6 +46,10 @@ static inline int _PyWeakref_IS_DEAD(PyObject *ref_obj) {
46
46
return (Py_REFCNT (obj ) == 0 );
47
47
}
48
48
49
+ extern Py_ssize_t _PyWeakref_GetWeakrefCount (PyWeakReference * head );
50
+
51
+ extern void _PyWeakref_ClearRef (PyWeakReference * self );
52
+
49
53
#ifdef __cplusplus
50
54
}
51
55
#endif
Original file line number Diff line number Diff line change @@ -89,25 +89,22 @@ static PyObject *
89
89
_weakref_getweakrefs (PyObject * module , PyObject * object )
90
90
/*[clinic end generated code: output=25c7731d8e011824 input=00c6d0e5d3206693]*/
91
91
{
92
- PyObject * result = NULL ;
93
-
94
- if (_PyType_SUPPORTS_WEAKREFS (Py_TYPE (object ))) {
95
- PyWeakReference * * list = GET_WEAKREFS_LISTPTR (object );
96
- Py_ssize_t count = _PyWeakref_GetWeakrefCount (* list );
97
-
98
- result = PyList_New (count );
99
- if (result != NULL ) {
100
- PyWeakReference * current = * list ;
101
- Py_ssize_t i ;
102
- for (i = 0 ; i < count ; ++ i ) {
103
- PyList_SET_ITEM (result , i , (PyObject * ) current );
104
- Py_INCREF (current );
105
- current = current -> wr_next ;
106
- }
107
- }
92
+ if (!_PyType_SUPPORTS_WEAKREFS (Py_TYPE (object ))) {
93
+ return PyList_New (0 );
108
94
}
109
- else {
110
- result = PyList_New (0 );
95
+
96
+ PyWeakReference * * list = GET_WEAKREFS_LISTPTR (object );
97
+ Py_ssize_t count = _PyWeakref_GetWeakrefCount (* list );
98
+
99
+ PyObject * result = PyList_New (count );
100
+ if (result == NULL ) {
101
+ return NULL ;
102
+ }
103
+
104
+ PyWeakReference * current = * list ;
105
+ for (Py_ssize_t i = 0 ; i < count ; ++ i ) {
106
+ PyList_SET_ITEM (result , i , Py_NewRef (current ));
107
+ current = current -> wr_next ;
111
108
}
112
109
return result ;
113
110
}
Original file line number Diff line number Diff line change 30
30
#include "pycore_object.h"
31
31
#include "pycore_pyerrors.h"
32
32
#include "pycore_pystate.h" // _PyThreadState_GET()
33
+ #include "pycore_weakref.h" // _PyWeakref_ClearRef()
33
34
#include "pydtrace.h"
34
35
35
36
typedef struct _gc_runtime_state GCState ;
You can’t perform that action at this time.
0 commit comments