File tree Expand file tree Collapse file tree 1 file changed +20
-2
lines changed
Expand file tree Collapse file tree 1 file changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -1056,9 +1056,23 @@ setiter_len(PyObject *op, PyObject *Py_UNUSED(ignored))
10561056{
10571057 setiterobject * si = (setiterobject * )op ;
10581058 Py_ssize_t len = 0 ;
1059- PySetObject * so = si -> si_set ;
1060- if (so != NULL && si -> si_used == FT_ATOMIC_LOAD_SSIZE_RELAXED (so -> used ))
1059+ #ifdef Py_GIL_DISABLED
1060+ PyObject * so_obj = FT_ATOMIC_LOAD_PTR_ACQUIRE (si -> si_set );
1061+ if (so_obj != NULL ) {
1062+ /* Turn borrowed si->si_set into a strong ref safely. */
1063+ if (_Py_TryIncrefCompare ((PyObject * * )& si -> si_set , so_obj )) {
1064+ PySetObject * so = (PySetObject * )so_obj ;
1065+ if (si -> si_used == FT_ATOMIC_LOAD_SSIZE_RELAXED (so -> used )) {
1066+ len = si -> len ;
1067+ }
1068+ Py_DECREF (so_obj );
1069+ }
1070+ }
1071+ #else
1072+ if (si -> si_set != NULL && si -> si_used == si -> si_set -> used ) {
10611073 len = si -> len ;
1074+ }
1075+ #endif
10621076 return PyLong_FromSsize_t (len );
10631077}
10641078
@@ -1125,7 +1139,11 @@ static PyObject *setiter_iternext(PyObject *self)
11251139 Py_END_CRITICAL_SECTION ();
11261140 si -> si_pos = i + 1 ;
11271141 if (key == NULL ) {
1142+ #ifdef Py_GIL_DISABLED
1143+ FT_ATOMIC_STORE_PTR_RELEASE (si -> si_set , NULL );
1144+ #else
11281145 si -> si_set = NULL ;
1146+ #endif
11291147 Py_DECREF (so );
11301148 return NULL ;
11311149 }
You can’t perform that action at this time.
0 commit comments