Skip to content

Commit 931b2f9

Browse files
committed
add comment for incref rationale
1 parent 11e727d commit 931b2f9

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Modules/itertoolsmodule.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ pairwise_next_lock_held(PyObject *op)
366366
return NULL;
367367
}
368368
}
369-
Py_INCREF(old);
369+
Py_INCREF(old); // needed because of reentant calls via call to the iterator
370370
new = (*Py_TYPE(it)->tp_iternext)(it);
371371
if (new == NULL) {
372372
Py_CLEAR(po->it);
@@ -380,7 +380,7 @@ pairwise_next_lock_held(PyObject *op)
380380
Py_INCREF(result);
381381
PyObject *last_old = PyTuple_GET_ITEM(result, 0);
382382
PyObject *last_new = PyTuple_GET_ITEM(result, 1);
383-
PyTuple_SET_ITEM(result, 0, old);
383+
PyTuple_SET_ITEM(result, 0, old); // consume the reference from old
384384
PyTuple_SET_ITEM(result, 1, Py_NewRef(new));
385385
Py_DECREF(last_old);
386386
Py_DECREF(last_new);

0 commit comments

Comments
 (0)