diff options
author | Eric Snow <ericsnowcurrently@gmail.com> | 2013-02-16 18:20:32 -0700 |
---|---|---|
committer | Eric Snow <ericsnowcurrently@gmail.com> | 2013-02-16 18:20:32 -0700 |
commit | 9d05c8c0e0b0f3ebd19d7add842d2db8269f7d75 (patch) | |
tree | f9fbeb1d362995d5c6adce96ca1c38de57964013 /Objects/namespaceobject.c | |
parent | dcbe46bc5bad217e934568cfe59e3e807501acc3 (diff) | |
download | cpython-git-9d05c8c0e0b0f3ebd19d7add842d2db8269f7d75.tar.gz |
Issue #15022: Ensure all pickle protocols are supported.
Diffstat (limited to 'Objects/namespaceobject.c')
-rw-r--r-- | Objects/namespaceobject.c | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/Objects/namespaceobject.c b/Objects/namespaceobject.c index f9a6f6549d..7e9107a744 100644 --- a/Objects/namespaceobject.c +++ b/Objects/namespaceobject.c @@ -173,6 +173,29 @@ namespace_richcompare(PyObject *self, PyObject *other, int op) } +PyDoc_STRVAR(namespace_reduce__doc__, "Return state information for pickling"); + +static PyObject * +namespace_reduce(register _PyNamespaceObject *ns) +{ + PyObject *result, *args = PyTuple_New(0); + + if (!args) + return NULL; + + result = PyTuple_Pack(3, (PyObject *)Py_TYPE(ns), args, ns->ns_dict); + Py_DECREF(args); + return result; +} + + +static PyMethodDef namespace_methods[] = { + {"__reduce__", (PyCFunction)namespace_reduce, METH_NOARGS, + namespace_reduce__doc__}, + {NULL, NULL} /* sentinel */ +}; + + PyDoc_STRVAR(namespace_doc, "A simple attribute-based namespace.\n\ \n\ @@ -207,7 +230,7 @@ PyTypeObject _PyNamespace_Type = { 0, /* tp_weaklistoffset */ 0, /* tp_iter */ 0, /* tp_iternext */ - 0, /* tp_methods */ + namespace_methods, /* tp_methods */ namespace_members, /* tp_members */ 0, /* tp_getset */ 0, /* tp_base */ |