@@ -801,24 +801,14 @@ PyWeakref_NewRef(PyObject *ob, PyObject *callback)
801
801
if (result != NULL )
802
802
Py_INCREF (result );
803
803
else {
804
- /* Note: new_weakref() can trigger cyclic GC, so the weakref
805
- list on ob can be mutated. This means that the ref and
806
- proxy pointers we got back earlier may have been collected,
807
- so we need to compute these values again before we use
808
- them. */
804
+ /* We do not need to recompute ref/proxy here; new_weakref() cannot
805
+ trigger cyclic GC.
806
+ */
809
807
result = new_weakref (ob , callback );
810
808
if (result != NULL ) {
811
- get_basic_refs (* list , & ref , & proxy );
812
809
if (callback == NULL ) {
813
810
if (ref == NULL )
814
811
insert_head (result , list );
815
- else {
816
- /* Someone else added a ref without a callback
817
- during GC. Return that one instead of this one
818
- to avoid violating the invariants of the list
819
- of weakrefs for ob. */
820
- Py_SETREF (result , (PyWeakReference * )Py_NewRef (ref ));
821
- }
822
812
}
823
813
else {
824
814
PyWeakReference * prev ;
@@ -858,11 +848,9 @@ PyWeakref_NewProxy(PyObject *ob, PyObject *callback)
858
848
if (result != NULL )
859
849
Py_INCREF (result );
860
850
else {
861
- /* Note: new_weakref() can trigger cyclic GC, so the weakref
862
- list on ob can be mutated. This means that the ref and
863
- proxy pointers we got back earlier may have been collected,
864
- so we need to compute these values again before we use
865
- them. */
851
+ /* We do not need to recompute ref/proxy here; new_weakref() cannot
852
+ trigger cyclic GC.
853
+ */
866
854
result = new_weakref (ob , callback );
867
855
if (result != NULL ) {
868
856
PyWeakReference * prev ;
@@ -873,16 +861,7 @@ PyWeakref_NewProxy(PyObject *ob, PyObject *callback)
873
861
else {
874
862
Py_SET_TYPE (result , & _PyWeakref_ProxyType );
875
863
}
876
- get_basic_refs (* list , & ref , & proxy );
877
864
if (callback == NULL ) {
878
- if (proxy != NULL ) {
879
- /* Someone else added a proxy without a callback
880
- during GC. Return that one instead of this one
881
- to avoid violating the invariants of the list
882
- of weakrefs for ob. */
883
- Py_SETREF (result , (PyWeakReference * )Py_NewRef (proxy ));
884
- goto skip_insert ;
885
- }
886
865
prev = ref ;
887
866
}
888
867
else
@@ -892,8 +871,6 @@ PyWeakref_NewProxy(PyObject *ob, PyObject *callback)
892
871
insert_head (result , list );
893
872
else
894
873
insert_after (result , prev );
895
- skip_insert :
896
- ;
897
874
}
898
875
}
899
876
return (PyObject * ) result ;
0 commit comments