@@ -104,9 +104,11 @@ clear_weakref_lock_held(PyWeakReference *self, PyObject **callback)
104
104
105
105
// Clear the weakref and its callback
106
106
static void
107
- clear_weakref (PyWeakReference * self )
107
+ clear_weakref (PyObject * op )
108
108
{
109
+ PyWeakReference * self = _PyWeakref_CAST (op );
109
110
PyObject * callback = NULL ;
111
+
110
112
// self->wr_object may be Py_None if the GC cleared the weakref, so lock
111
113
// using the pointer in the weakref.
112
114
LOCK_WEAKREFS_FOR_WR (self );
@@ -139,22 +141,24 @@ static void
139
141
weakref_dealloc (PyObject * self )
140
142
{
141
143
PyObject_GC_UnTrack (self );
142
- clear_weakref (( PyWeakReference * ) self );
144
+ clear_weakref (self );
143
145
Py_TYPE (self )-> tp_free (self );
144
146
}
145
147
146
148
147
149
static int
148
- gc_traverse (PyWeakReference * self , visitproc visit , void * arg )
150
+ gc_traverse (PyObject * op , visitproc visit , void * arg )
149
151
{
152
+ PyWeakReference * self = _PyWeakref_CAST (op );
150
153
Py_VISIT (self -> wr_callback );
151
154
return 0 ;
152
155
}
153
156
154
157
155
158
static int
156
- gc_clear (PyWeakReference * self )
159
+ gc_clear (PyObject * op )
157
160
{
161
+ PyWeakReference * self = _PyWeakref_CAST (op );
158
162
PyObject * callback ;
159
163
// The world is stopped during GC in free-threaded builds. It's safe to
160
164
// call this without holding the lock.
@@ -198,8 +202,9 @@ weakref_hash_lock_held(PyWeakReference *self)
198
202
}
199
203
200
204
static Py_hash_t
201
- weakref_hash (PyWeakReference * self )
205
+ weakref_hash (PyObject * op )
202
206
{
207
+ PyWeakReference * self = _PyWeakref_CAST (op );
203
208
Py_hash_t hash ;
204
209
Py_BEGIN_CRITICAL_SECTION (self );
205
210
hash = weakref_hash_lock_held (self );
@@ -499,11 +504,11 @@ _PyWeakref_RefType = {
499
504
.tp_vectorcall_offset = offsetof(PyWeakReference , vectorcall ),
500
505
.tp_call = PyVectorcall_Call ,
501
506
.tp_repr = weakref_repr ,
502
- .tp_hash = ( hashfunc ) weakref_hash ,
507
+ .tp_hash = weakref_hash ,
503
508
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
504
509
Py_TPFLAGS_HAVE_VECTORCALL | Py_TPFLAGS_BASETYPE ,
505
- .tp_traverse = ( traverseproc ) gc_traverse ,
506
- .tp_clear = ( inquiry ) gc_clear ,
510
+ .tp_traverse = gc_traverse ,
511
+ .tp_clear = gc_clear ,
507
512
.tp_richcompare = weakref_richcompare ,
508
513
.tp_methods = weakref_methods ,
509
514
.tp_members = weakref_members ,
@@ -687,7 +692,7 @@ proxy_bool(PyObject *proxy)
687
692
}
688
693
689
694
static void
690
- proxy_dealloc (PyWeakReference * self )
695
+ proxy_dealloc (PyObject * self )
691
696
{
692
697
PyObject_GC_UnTrack (self );
693
698
clear_weakref (self );
@@ -850,7 +855,7 @@ _PyWeakref_ProxyType = {
850
855
sizeof (PyWeakReference ),
851
856
0 ,
852
857
/* methods */
853
- ( destructor ) proxy_dealloc , /* tp_dealloc */
858
+ proxy_dealloc , /* tp_dealloc */
854
859
0 , /* tp_vectorcall_offset */
855
860
0 , /* tp_getattr */
856
861
0 , /* tp_setattr */
@@ -868,8 +873,8 @@ _PyWeakref_ProxyType = {
868
873
0 , /* tp_as_buffer */
869
874
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC , /* tp_flags */
870
875
0 , /* tp_doc */
871
- ( traverseproc ) gc_traverse , /* tp_traverse */
872
- ( inquiry ) gc_clear , /* tp_clear */
876
+ gc_traverse , /* tp_traverse */
877
+ gc_clear , /* tp_clear */
873
878
proxy_richcompare , /* tp_richcompare */
874
879
0 , /* tp_weaklistoffset */
875
880
proxy_iter , /* tp_iter */
@@ -885,7 +890,7 @@ _PyWeakref_CallableProxyType = {
885
890
sizeof (PyWeakReference ),
886
891
0 ,
887
892
/* methods */
888
- ( destructor ) proxy_dealloc , /* tp_dealloc */
893
+ proxy_dealloc , /* tp_dealloc */
889
894
0 , /* tp_vectorcall_offset */
890
895
0 , /* tp_getattr */
891
896
0 , /* tp_setattr */
@@ -902,8 +907,8 @@ _PyWeakref_CallableProxyType = {
902
907
0 , /* tp_as_buffer */
903
908
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC , /* tp_flags */
904
909
0 , /* tp_doc */
905
- ( traverseproc ) gc_traverse , /* tp_traverse */
906
- ( inquiry ) gc_clear , /* tp_clear */
910
+ gc_traverse , /* tp_traverse */
911
+ gc_clear , /* tp_clear */
907
912
proxy_richcompare , /* tp_richcompare */
908
913
0 , /* tp_weaklistoffset */
909
914
proxy_iter , /* tp_iter */
0 commit comments