@@ -848,11 +848,9 @@ PyWeakref_NewProxy(PyObject *ob, PyObject *callback)
848848 if (result != NULL )
849849 Py_INCREF (result );
850850 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+ */
856854 result = new_weakref (ob , callback );
857855 if (result != NULL ) {
858856 PyWeakReference * prev ;
@@ -863,16 +861,7 @@ PyWeakref_NewProxy(PyObject *ob, PyObject *callback)
863861 else {
864862 Py_SET_TYPE (result , & _PyWeakref_ProxyType );
865863 }
866- get_basic_refs (* list , & ref , & proxy );
867864 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- }
876865 prev = ref ;
877866 }
878867 else
@@ -882,8 +871,6 @@ PyWeakref_NewProxy(PyObject *ob, PyObject *callback)
882871 insert_head (result , list );
883872 else
884873 insert_after (result , prev );
885- skip_insert :
886- ;
887874 }
888875 }
889876 return (PyObject * ) result ;
0 commit comments