Mercurial > cpython-lru_cache-weakref
diff Modules/itertoolsmodule.c @ 33616:31b08670ebdd legacy-trunk
* Increase test coverage.
* Have groupby() be careful about decreffing structure members.
| author | Raymond Hettinger <python@rcn.com> |
|---|---|
| date | Tue, 28 Sep 2004 04:45:28 +0000 |
| parents | c2c49ee727d0 |
| children | 3d8d78217599 |
line wrap: on
line diff
--- a/Modules/itertoolsmodule.c Tue Sep 28 04:29:57 2004 +0000 +++ b/Modules/itertoolsmodule.c Tue Sep 28 04:45:28 2004 +0000 @@ -75,7 +75,7 @@ static PyObject * groupby_next(groupbyobject *gbo) { - PyObject *newvalue, *newkey, *r, *grouper; + PyObject *newvalue, *newkey, *r, *grouper, *tmp; /* skip to next iteration group */ for (;;) { @@ -110,15 +110,19 @@ } } - Py_XDECREF(gbo->currkey); + tmp = gbo->currkey; gbo->currkey = newkey; - Py_XDECREF(gbo->currvalue); + Py_XDECREF(tmp); + + tmp = gbo->currvalue; gbo->currvalue = newvalue; + Py_XDECREF(tmp); } - Py_XDECREF(gbo->tgtkey); + Py_INCREF(gbo->currkey); + tmp = gbo->tgtkey; gbo->tgtkey = gbo->currkey; - Py_INCREF(gbo->currkey); + Py_XDECREF(tmp); grouper = _grouper_create(gbo, gbo->tgtkey); if (grouper == NULL)
