Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 93b2cc4

Browse files
committed
A bogus assert in the new listiter code prevented starting Python in a
debug build. Repaired that, and rewrote other parts to reduce long-winded casting.
1 parent bb98c8c commit 93b2cc4

1 file changed

Lines changed: 12 additions & 10 deletions

File tree

Objects/listobject.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1819,8 +1819,8 @@ static PyTypeObject immutable_list_type = {
18191819

18201820
typedef struct {
18211821
PyObject_HEAD
1822-
long it_index;
1823-
PyObject *it_seq;
1822+
long it_index;
1823+
PyListObject *it_seq;
18241824
} listiterobject;
18251825

18261826
PyTypeObject PyListIter_Type;
@@ -1839,7 +1839,7 @@ list_iter(PyObject *seq)
18391839
return NULL;
18401840
it->it_index = 0;
18411841
Py_INCREF(seq);
1842-
it->it_seq = seq;
1842+
it->it_seq = (PyListObject *)seq;
18431843
_PyObject_GC_TRACK(it);
18441844
return (PyObject *)it;
18451845
}
@@ -1855,7 +1855,7 @@ listiter_dealloc(listiterobject *it)
18551855
static int
18561856
listiter_traverse(listiterobject *it, visitproc visit, void *arg)
18571857
{
1858-
return visit(it->it_seq, arg);
1858+
return visit((PyObject *)it->it_seq, arg);
18591859
}
18601860

18611861

@@ -1867,16 +1867,18 @@ listiter_getiter(PyObject *it)
18671867
}
18681868

18691869
static PyObject *
1870-
listiter_next(PyObject *it)
1870+
listiter_next(listiterobject *it)
18711871
{
1872-
PyObject *seq;
1872+
PyListObject *seq;
18731873
PyObject *item;
18741874

1875-
assert(PyList_Check(it));
1876-
seq = ((listiterobject *)it)->it_seq;
1875+
assert(it != NULL);
1876+
seq = it->it_seq;
1877+
assert(PyList_Check(seq));
18771878

1878-
if (((listiterobject *)it)->it_index < PyList_GET_SIZE(seq)) {
1879-
item = ((PyListObject *)(seq))->ob_item[((listiterobject *)it)->it_index++];
1879+
if (it->it_index < PyList_GET_SIZE(seq)) {
1880+
item = PyList_GET_ITEM(seq, it->it_index);
1881+
++it->it_index;
18801882
Py_INCREF(item);
18811883
return item;
18821884
}

0 commit comments

Comments
 (0)