Skip to content

Commit cb4cc82

Browse files
sampsoncencukou
andauthored
Update Modules/itertoolsmodule.c
Co-authored-by: Petr Viktorin <encukou@gmail.com>
1 parent 867c8ee commit cb4cc82

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

Modules/itertoolsmodule.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -678,14 +678,8 @@ _grouper_next(PyObject *op)
678678
}
679679

680680
assert(gbo->currkey != NULL);
681-
/* A user-defined __eq__ can re-enter groupby (via the parent iterator)
682-
and call groupby_step(), which frees gbo->currkey via Py_XSETREF while
683-
we are still comparing it. Take local snapshots with strong references
684-
so INCREF/DECREF apply to the same objects even under re-entrancy. */
685-
PyObject *tgtkey = igo->tgtkey;
686-
PyObject *currkey = gbo->currkey;
687-
Py_INCREF(tgtkey);
688-
Py_INCREF(currkey);
681+
PyObject *tgtkey = Py_NewRef(igo->tgtkey);
682+
PyObject *currkey = Py_NewRef(gbo->currkey);
689683
rcmp = PyObject_RichCompareBool(tgtkey, currkey, Py_EQ);
690684
Py_DECREF(tgtkey);
691685
Py_DECREF(currkey);

0 commit comments

Comments
 (0)