Skip to content

Commit 4d5bb3a

Browse files
committed
remove unnecessary crit sect in setstate
1 parent bb4bf90 commit 4d5bb3a

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

Modules/arraymodule.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3208,6 +3208,7 @@ array_iter(arrayobject *ao)
32083208
static PyObject *
32093209
arrayiter_next(arrayiterobject *it)
32103210
{
3211+
assert(it != NULL);
32113212
Py_ssize_t index = FT_ATOMIC_LOAD_SSIZE_RELAXED(it->index);
32123213
if (index < 0) {
32133214
return NULL;
@@ -3310,18 +3311,22 @@ array_arrayiterator___setstate__(arrayiterobject *self, PyObject *state)
33103311
return NULL;
33113312
}
33123313
if (FT_ATOMIC_LOAD_SSIZE_RELAXED(self->index) >= 0) {
3313-
Py_BEGIN_CRITICAL_SECTION(self->ao);
33143314
if (index < -1) {
33153315
index = -1;
33163316
}
33173317
else {
3318-
Py_ssize_t size = Py_SIZE(self->ao);
3318+
Py_ssize_t size;
3319+
#ifdef Py_GIL_DISABLED
3320+
size = _Py_atomic_load_ssize_relaxed(
3321+
&(_PyVarObject_CAST(self->ao)->ob_size));
3322+
#else
3323+
size = Py_SIZE(self->ao);
3324+
#endif
33193325
if (index > size) {
33203326
index = size; /* iterator at end */
33213327
}
33223328
}
33233329
FT_ATOMIC_STORE_SSIZE_RELAXED(self->index, index);
3324-
Py_END_CRITICAL_SECTION();
33253330
}
33263331
Py_RETURN_NONE;
33273332
}

0 commit comments

Comments
 (0)