File tree Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -854,15 +854,26 @@ PyWeakref_NewProxy(PyObject *ob, PyObject *callback)
854
854
return NULL ;
855
855
}
<
8000
td data-grid-cell-id="diff-203baf73fbb7f03732f24a6070851675c64af2e125892f45639e715e83030d61-856-856-0" data-selected="false" role="gridcell" style="background-color:var(--bgColor-default);text-align:center" tabindex="-1" valign="top" class="focusable-grid-cell diff-line-number position-relative diff-line-number-neutral left-side">856
856
list = GET_WEAKREFS_LISTPTR (ob );
857
+ /* NB: For free-threaded builds its critical that no code inside the
858
+ * critical section can release it. We need to recompute ref/proxy after
859
+ * any code that may release the critical section.
860
+ */
861
+ Py_BEGIN_CRITICAL_SECTION (ob );
857
862
get_basic_refs (* list , & ref , & proxy );
858
863
if (callback == Py_None )
859
864
callback = NULL ;
860
865
if (callback == NULL )
861
866
/* attempt to return an existing weak reference if it exists */
862
867
result = proxy ;
868
+ #ifdef Py_GIL_DISABLED
869
+ /* Incref will fail if the existing weakref is being destroyed */
870
+ if (result == NULL ||
871
+ !_Py_TryIncref ((PyObject * * )& result , (PyObject * )result )) {
872
+ #else
863
873
if (result != NULL )
864
874
Py_INCREF (result );
865
875
else {
876
+ #endif
866
877
/* We do not need to recompute ref/proxy; new_weakref cannot
867
878
trigger GC.
868
879
*/
@@ -888,6 +899,7 @@ PyWeakref_NewProxy(PyObject *ob, PyObject *callback)
888
899
insert_after (result , prev );
889
900
}
890
901
}
902
+ Py_END_CRITICAL_SECTION ();
891
903
return (PyObject * ) result ;
892
904
}
893
905
You can’t perform that action at this time.
0 commit comments