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 9cbe1a6 commit 8c61450Copy full SHA for 8c61450
Modules/itertoolsmodule.c
@@ -545,11 +545,14 @@ groupby_next(PyObject *op)
545
break;
546
else {
547
int rcmp;
548
+
549
+ /* A user-defined __eq__ can re-enter groupby and advance the iterator,
550
+ mutating gbo->tgtkey / gbo->currkey while we are comparing them.
551
+ Take local snapshots and hold strong references so INCREF/DECREF
552
+ apply to the same objects even under re-entrancy. */
553
PyObject *tgtkey = gbo->tgtkey;
554
PyObject *currkey = gbo->currkey;
555
- /* Hold strong references during comparison to prevent re-entrant __eq__
- from advancing the iterator and invalidating borrowed references. */
556
Py_INCREF(tgtkey);
557
Py_INCREF(currkey);
558
0 commit comments