SF bug #910986: copy.copy fails for array.array
Added support for the copy module.
diff --git a/Lib/test/test_array.py b/Lib/test/test_array.py
index 0331280..c9b05c2 100755
--- a/Lib/test/test_array.py
+++ b/Lib/test/test_array.py
@@ -73,6 +73,13 @@
b.byteswap()
self.assertEqual(a, b)
+ def test_copy(self):
+ import copy
+ a = array.array(self.typecode, self.example)
+ b = copy.copy(a)
+ self.assertNotEqual(id(a), id(b))
+ self.assertEqual(a, b)
+
def test_insert(self):
a = array.array(self.typecode, self.example)
a.insert(0, self.example[0])
diff --git a/Misc/NEWS b/Misc/NEWS
index 9c5d80a..350bf7e 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -180,6 +180,8 @@
Extension modules
-----------------
+- array objects now support the copy module
+
- cStringIO.writelines() now accepts any iterable argument and writes
the lines one at a time rather than joining them and writing once.
Made a parallel change to StringIO.writelines(). Saves memory and
diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c
index 9382927..bda5fef 100644
--- a/Modules/arraymodule.c
+++ b/Modules/arraymodule.c
@@ -617,6 +617,17 @@
}
static PyObject *
+array_copy(arrayobject *a, PyObject *unused)
+{
+ return array_slice(a, 0, a->ob_size);
+}
+
+PyDoc_STRVAR(copy_doc,
+"copy(array)\n\
+\n\
+ Return a copy of the array.");
+
+static PyObject *
array_concat(arrayobject *a, PyObject *bb)
{
int size;
@@ -1409,8 +1420,12 @@
buffer_info_doc},
{"byteswap", (PyCFunction)array_byteswap, METH_NOARGS,
byteswap_doc},
+ {"__copy__", (PyCFunction)array_copy, METH_NOARGS,
+ copy_doc},
{"count", (PyCFunction)array_count, METH_O,
count_doc},
+ {"__deepcopy__",(PyCFunction)array_copy, METH_NOARGS,
+ copy_doc},
{"extend", (PyCFunction)array_extend, METH_O,
extend_doc},
{"fromfile", (PyCFunction)array_fromfile, METH_VARARGS,