Skip to content

Commit 4028dfe

Browse files
committed
Address reviewer comments.
1 parent dd56d89 commit 4028dfe

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

Objects/tupleobject.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,14 +1016,16 @@ tupleiter_next(PyObject *self)
10161016

10171017
assert(it != NULL);
10181018
seq = it->it_seq;
1019+
#ifndef Py_GIL_DISABLED
10191020
if (seq == NULL)
10201021
return NULL;
1022+
#endif
10211023
assert(PyTuple_Check(seq));
10221024

10231025
Py_ssize_t index = FT_ATOMIC_LOAD_SSIZE_RELAXED(it->it_index);
10241026
if (index < PyTuple_GET_SIZE(seq)) {
1025-
item = PyTuple_GET_ITEM(seq, index);
10261027
FT_ATOMIC_STORE_SSIZE_RELAXED(it->it_index, index + 1);
1028+
item = PyTuple_GET_ITEM(seq, index);
10271029
return Py_NewRef(item);
10281030
}
10291031

@@ -1041,8 +1043,9 @@ tupleiter_len(PyObject *self, PyObject *Py_UNUSED(ignored))
10411043
Py_ssize_t len = 0;
10421044
#ifdef Py_GIL_DISABLED
10431045
Py_ssize_t idx = FT_ATOMIC_LOAD_SSIZE_RELAXED(it->it_index);
1044-
if (it->it_seq && idx >= 0 && idx < PyTuple_GET_SIZE(it->it_seq))
1045-
len = PyTuple_GET_SIZE(it->it_seq) - idx;
1046+
Py_ssize_t seq_len = PyTuple_GET_SIZE(it->it_seq);
1047+
if (idx < seq_len)
1048+
len = seq_len - idx;
10461049
#else
10471050
if (it->it_seq)
10481051
len = PyTuple_GET_SIZE(it->it_seq) - it->it_index;
@@ -1064,7 +1067,7 @@ tupleiter_reduce(PyObject *self, PyObject *Py_UNUSED(ignored))
10641067

10651068
#ifdef Py_GIL_DISABLED
10661069
Py_ssize_t idx = FT_ATOMIC_LOAD_SSIZE_RELAXED(it->it_index);
1067-
if (it->it_seq && idx >= 0 && idx < PyTuple_GET_SIZE(it->it_seq))
1070+
if (idx < PyTuple_GET_SIZE(it->it_seq))
10681071
return Py_BuildValue("N(O)n", iter, it->it_seq, idx);
10691072
#else
10701073
if (it->it_seq)

0 commit comments

Comments
 (0)