We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 0e86303 commit 740218cCopy full SHA for 740218c
Modules/itertoolsmodule.c
@@ -548,13 +548,15 @@ groupby_next(PyObject *op)
548
PyObject *tgtkey = gbo->tgtkey;
549
PyObject *currkey = gbo->currkey;
550
551
- Py_INCREF(tgtkey);
552
- Py_INCREF(currkey);
+ /* Hold strong references during comparison to prevent re-entrant __eq__
+ from advancing the iterator and invalidating borrowed references. */
553
+ Py_INCREF(gbo -> tgtkey);
554
+ Py_INCREF(gbo -> currkey);
555
556
rcmp = PyObject_RichCompareBool(tgtkey, currkey, Py_EQ);
557
- Py_DECREF(tgtkey);
- Py_DECREF(currkey);
558
+ Py_DECREF(gbo -> tgtkey);
559
+ Py_DECREF(gbo -> currkey);
560
561
if (rcmp == -1)
562
return NULL;
0 commit comments