summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2004-12-16 16:23:40 (GMT)
committerRaymond Hettinger <python@rcn.com>2004-12-16 16:23:40 (GMT)
commitb0900e6a217480def244b0b55d718ce705e8e73a (patch)
treeded97348a4d0d9b1fd519acd9b0d1cfad4b9cc86 /Modules
parente6bdb37e5bc7d250e17c3d4fef6961e178e02b64 (diff)
downloadcpython-b0900e6a217480def244b0b55d718ce705e8e73a.zip
cpython-b0900e6a217480def244b0b55d718ce705e8e73a.tar.gz
cpython-b0900e6a217480def244b0b55d718ce705e8e73a.tar.bz2
SF #1085304: Make array.array pickle-able
Diffstat (limited to 'Modules')
-rw-r--r--Modules/arraymodule.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c
index 7ed3b73..6430333 100644
--- a/Modules/arraymodule.c
+++ b/Modules/arraymodule.c
@@ -1133,6 +1133,29 @@ Byteswap all items of the array. If the items in the array are not 1, 2,\n\
4, or 8 bytes in size, RuntimeError is raised.");
static PyObject *
+array_reduce(arrayobject *array)
+{
+ PyObject *dict, *result;
+
+ dict = PyObject_GetAttrString((PyObject *)array, "__dict__");
+ if (dict == NULL) {
+ PyErr_Clear();
+ dict = Py_None;
+ Py_INCREF(dict);
+ }
+ result = Py_BuildValue("O(cs#)O",
+ array->ob_type,
+ array->ob_descr->typecode,
+ array->ob_item,
+ array->ob_size * array->ob_descr->itemsize,
+ dict);
+ Py_DECREF(dict);
+ return result;
+}
+
+PyDoc_STRVAR(array_doc, "Return state information for pickling.");
+
+static PyObject *
array_reverse(arrayobject *self, PyObject *unused)
{
register int itemsize = self->ob_descr->itemsize;
@@ -1490,6 +1513,8 @@ PyMethodDef array_methods[] = {
pop_doc},
{"read", (PyCFunction)array_fromfile, METH_VARARGS,
fromfile_doc},
+ {"__reduce__", (PyCFunction)array_reduce, METH_NOARGS,
+ array_doc},
{"remove", (PyCFunction)array_remove, METH_O,
remove_doc},
{"reverse", (PyCFunction)array_reverse, METH_NOARGS,