@@ -848,11 +848,9 @@ PyWeakref_NewProxy(PyObject *ob, PyObject *callback)
848
848
if (result != NULL )
849
849
Py_INCREF (result );
850
850
else {
851
- /* Note: new_weakref() can trigger cyclic GC, so the weakref
852
- list on ob can be mutated. This means that the ref and
853
- proxy pointers we got back earlier may have been collected,
854
- so we need to compute these values again before we use
855
- them. */
851
+ /* We do not need to recompute ref/proxy; new_weakref cannot
852
+ trigger GC.
853
+ */
856
854
result = new_weakref (ob , callback );
857
855
if (result != NULL ) {
858
856
PyWeakReference * prev ;
@@ -863,16 +861,7 @@ PyWeakref_NewProxy(PyObject *ob, PyObject *callback)
863
861
else {
864
862
Py_SET_TYPE (result , & _PyWeakref_ProxyType );
865
863
}
866
- get_basic_refs (* list , & ref , & proxy );
867
864
if (callback == NULL ) {
868
- if (proxy != NULL ) {
869
- /* Someone else added a proxy without a callback
870
- during GC. Return that one instead of this one
871
- to avoid violating the invariants of the list
872
- of weakrefs for ob. */
873
- Py_SETREF (result , (PyWeakReference * )Py_NewRef (proxy ));
874
- goto skip_insert ;
875
- }
876
865
prev = ref ;
877
866
}
878
867
else
@@ -882,8 +871,6 @@ PyWeakref_NewProxy(PyObject *ob, PyObject *callback)
882
871
insert_head (result , list );
883
872
else
884
873
insert_after (result , prev );
885
- skip_insert :
886
- ;
887
874
}
888
875
}
889
876
return (PyObject * ) result ;
0 commit comments