diff options
author | Raymond Hettinger <python@rcn.com> | 2004-11-09 07:25:31 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2004-11-09 07:25:31 (GMT) |
commit | 15056a5202c89846d75006d66541d5a634ac79b5 (patch) | |
tree | dc4a2a104e7e73d8ae4965ff5d511f30902b712a /Objects/setobject.c | |
parent | f8c075cefcd737618ea25924f62e07dc003fa0db (diff) | |
download | cpython-15056a5202c89846d75006d66541d5a634ac79b5.zip cpython-15056a5202c89846d75006d66541d5a634ac79b5.tar.gz cpython-15056a5202c89846d75006d66541d5a634ac79b5.tar.bz2 |
SF 1062353: set pickling problems
Support automatic pickling of dictionaries in instance of set subclasses.
Diffstat (limited to 'Objects/setobject.c')
-rw-r--r-- | Objects/setobject.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/Objects/setobject.c b/Objects/setobject.c index d57217c..8ef671e 100644 --- a/Objects/setobject.c +++ b/Objects/setobject.c @@ -844,7 +844,7 @@ PyDoc_STRVAR(pop_doc, "Remove and return an arbitrary set element."); static PyObject * set_reduce(PySetObject *so) { - PyObject *keys=NULL, *args=NULL, *result=NULL; + PyObject *keys=NULL, *args=NULL, *result=NULL, *dict=NULL; keys = PyDict_Keys(so->data); if (keys == NULL) @@ -852,10 +852,17 @@ set_reduce(PySetObject *so) args = PyTuple_Pack(1, keys); if (args == NULL) goto done; - result = PyTuple_Pack(2, so->ob_type, args); + dict = PyObject_GetAttrString((PyObject *)so, "__dict__"); + if (dict == NULL) { + PyErr_Clear(); + dict = Py_None; + Py_INCREF(dict); + } + result = PyTuple_Pack(3, so->ob_type, args, dict); done: Py_XDECREF(args); Py_XDECREF(keys); + Py_XDECREF(dict); return result; } |