File tree Expand file tree Collapse file tree 4 files changed +20
-22
lines changed
Expand file tree Collapse file tree 4 files changed +20
-22
lines changed Original file line number Diff line number Diff line change @@ -32,10 +32,6 @@ struct _PyWeakReference {
3232 vectorcallfunc vectorcall ;
3333};
3434
35- PyAPI_FUNC (Py_ssize_t ) _PyWeakref_GetWeakrefCount (PyWeakReference * head );
36-
37- PyAPI_FUNC (void ) _PyWeakref_ClearRef (PyWeakReference * self );
38-
3935static inline PyObject * PyWeakref_GET_OBJECT (PyObject * ref_obj ) {
4036 PyWeakReference * ref ;
4137 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) {
4646 return (Py_REFCNT (obj ) == 0 );
4747}
4848
49+ extern Py_ssize_t _PyWeakref_GetWeakrefCount (PyWeakReference * head );
50+
51+ extern void _PyWeakref_ClearRef (PyWeakReference * self );
52+
4953#ifdef __cplusplus
5054}
5155#endif
Original file line number Diff line number Diff line change @@ -89,25 +89,22 @@ static PyObject *
8989_weakref_getweakrefs (PyObject * module , PyObject * object )
9090/*[clinic end generated code: output=25c7731d8e011824 input=00c6d0e5d3206693]*/
9191{
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 );
10894 }
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 ;
111108 }
112109 return result ;
113110}
Original file line number Diff line number Diff line change 3030#include "pycore_object.h"
3131#include "pycore_pyerrors.h"
3232#include "pycore_pystate.h" // _PyThreadState_GET()
33+ #include "pycore_weakref.h" // _PyWeakref_ClearRef()
3334#include "pydtrace.h"
3435
3536typedef struct _gc_runtime_state GCState ;
You can’t perform that action at this time.
0 commit comments