summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2016-03-06 06:55:21 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2016-03-06 06:55:21 (GMT)
commita0d416f0d186b5ee6ea6a898418871157a55b4f6 (patch)
tree026f19318df96522ce2dcca993f74e3dfa5a2538 /Modules
parent841b930a41be90c6c05fb4bab8392f50e01d86b7 (diff)
downloadcpython-a0d416f0d186b5ee6ea6a898418871157a55b4f6.zip
cpython-a0d416f0d186b5ee6ea6a898418871157a55b4f6.tar.gz
cpython-a0d416f0d186b5ee6ea6a898418871157a55b4f6.tar.bz2
Issue #26482: Allowed pickling recursive dequeues.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_collectionsmodule.c36
1 files changed, 18 insertions, 18 deletions
diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c
index 19a86d1..d57f1ba 100644
--- a/Modules/_collectionsmodule.c
+++ b/Modules/_collectionsmodule.c
@@ -1296,31 +1296,31 @@ deque_traverse(dequeobject *deque, visitproc visit, void *arg)
static PyObject *
deque_reduce(dequeobject *deque)
{
- PyObject *dict, *result, *aslist;
+ PyObject *dict, *it;
_Py_IDENTIFIER(__dict__);
dict = _PyObject_GetAttrId((PyObject *)deque, &PyId___dict__);
- if (dict == NULL)
+ if (dict == NULL) {
+ if (!PyErr_ExceptionMatches(PyExc_AttributeError)) {
+ return NULL;
+ }
PyErr_Clear();
- aslist = PySequence_List((PyObject *)deque);
- if (aslist == NULL) {
- Py_XDECREF(dict);
+ dict = Py_None;
+ Py_INCREF(dict);
+ }
+
+ it = PyObject_GetIter((PyObject *)deque);
+ if (it == NULL) {
+ Py_DECREF(dict);
return NULL;
}
- if (dict == NULL) {
- if (deque->maxlen < 0)
- result = Py_BuildValue("O(O)", Py_TYPE(deque), aslist);
- else
- result = Py_BuildValue("O(On)", Py_TYPE(deque), aslist, deque->maxlen);
- } else {
- if (deque->maxlen < 0)
- result = Py_BuildValue("O(OO)O", Py_TYPE(deque), aslist, Py_None, dict);
- else
- result = Py_BuildValue("O(On)O", Py_TYPE(deque), aslist, deque->maxlen, dict);
+
+ if (deque->maxlen < 0) {
+ return Py_BuildValue("O()NN", Py_TYPE(deque), dict, it);
+ }
+ else {
+ return Py_BuildValue("O(()n)NN", Py_TYPE(deque), deque->maxlen, dict, it);
}
- Py_XDECREF(dict);
- Py_DECREF(aslist);
- return result;
}
PyDoc_STRVAR(reduce_doc, "Return state information for pickling.");