10000 bpo-34573: Simplify __reduce__() of set and dict iterators. by sir-sigurd · Pull Request #9050 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-34573: Simplify __reduce__() of set and dict iterators. #9050

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 20, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Don't touch odict iterator as it's handled in other PR.
  • Loading branch information
sir-sigurd committed Sep 4, 2018
commit baaecd6c7f31bb94fb38c1969dab7ad06779796b
35 changes: 28 additions & 7 deletions Objects/odictobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -1837,17 +1837,38 @@ PyDoc_STRVAR(reduce_doc, "Return state information for pickling");
static PyObject *
odictiter_reduce(odictiterobject *di)
{
/* copy the iterator state */
odictiterobject tmp = *di;
Py_XINCREF(tmp.di_odict);
PyObject *list, *iter;

list = PyList_New(0);
if (!list)
return NULL;

/* iterate the temporary into a list */
PyObject *list = PySequence_List((PyObject*)&tmp);
Py_XDECREF(tmp.di_odict);
if (list == NULL) {
for(;;) {
PyObject *element = odictiter_iternext(di);
if (element) {
if (PyList_Append(list, element)) {
Py_DECREF(element);
Py_DECREF(list);
return NULL;
}
Py_DECREF(element);
}
else {
/* done iterating? */
break;
}
}
if (PyErr_Occurred()) {
Py_DECREF(list);
return NULL;
}
iter = _PyObject_GetBuiltin("iter");
if (iter == NULL) {
Py_DECREF(list);
return NULL;
}
return Py_BuildValue("N(N)", _PyObject_GetBuiltin("iter"), list);
return Py_BuildValue("N(N)", iter, list);
}

static PyMethodDef odictiter_methods[] = {
Expand Down
0