summaryrefslogtreecommitdiffstats
path: root/Modules/arraymodule.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2007-11-06 21:34:58 (GMT)
committerGuido van Rossum <guido@python.org>2007-11-06 21:34:58 (GMT)
commit98297ee7815939b124156e438b22bd652d67b5db (patch)
treea9d239ebd87c73af2571ab48003984c4e18e27e5 /Modules/arraymodule.c
parenta19f80c6df2df5e8a5d0cff37131097835ef971e (diff)
downloadcpython-98297ee7815939b124156e438b22bd652d67b5db.zip
cpython-98297ee7815939b124156e438b22bd652d67b5db.tar.gz
cpython-98297ee7815939b124156e438b22bd652d67b5db.tar.bz2
Merging the py3k-pep3137 branch back into the py3k branch.
No detailed change log; just check out the change log for the py3k-pep3137 branch. The most obvious changes: - str8 renamed to bytes (PyString at the C level); - bytes renamed to buffer (PyBytes at the C level); - PyString and PyUnicode are no longer compatible. I.e. we now have an immutable bytes type and a mutable bytes type. The behavior of PyString was modified quite a bit, to make it more bytes-like. Some changes are still on the to-do list.
Diffstat (limited to 'Modules/arraymodule.c')
-rw-r--r--Modules/arraymodule.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c
index 8a24a7e..c7aeb5b 100644
--- a/Modules/arraymodule.c
+++ b/Modules/arraymodule.c
@@ -1212,14 +1212,14 @@ array_fromfile(arrayobject *self, PyObject *args)
if (b == NULL)
return NULL;
- if (!PyBytes_Check(b)) {
+ if (!PyString_Check(b)) {
PyErr_SetString(PyExc_TypeError,
"read() didn't return bytes");
Py_DECREF(b);
return NULL;
}
- if (PyBytes_GET_SIZE(b) != nbytes) {
+ if (PyString_GET_SIZE(b) != nbytes) {
PyErr_SetString(PyExc_EOFError,
"read() didn't return enough bytes");
Py_DECREF(b);
@@ -1263,7 +1263,7 @@ array_tofile(arrayobject *self, PyObject *f)
PyObject *bytes, *res;
if (i*BLOCKSIZE + size > nbytes)
size = nbytes - i*BLOCKSIZE;
- bytes = PyBytes_FromStringAndSize(ptr, size);
+ bytes = PyString_FromStringAndSize(ptr, size);
if (bytes == NULL)
return NULL;
res = PyObject_CallMethod(f, "write", "O", bytes);
@@ -1395,7 +1395,7 @@ values, as if it had been read from a file using the fromfile() method).");
static PyObject *
array_tostring(arrayobject *self, PyObject *unused)
{
- return PyBytes_FromStringAndSize(self->ob_item,
+ return PyString_FromStringAndSize(self->ob_item,
Py_Size(self) * self->ob_descr->itemsize);
}
@@ -1861,6 +1861,7 @@ array_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
if (!(initial == NULL || PyList_Check(initial)
|| PyBytes_Check(initial)
+ || PyString_Check(initial)
|| PyTuple_Check(initial)
|| ((c=='u') && PyUnicode_Check(initial)))) {
it = PyObject_GetIter(initial);
@@ -1904,7 +1905,9 @@ array_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
}
Py_DECREF(v);
}
- } else if (initial != NULL && PyBytes_Check(initial)) {
+ }
+ else if (initial != NULL && (PyBytes_Check(initial) ||
+ PyString_Check(initial))) {
PyObject *t_initial, *v;
t_initial = PyTuple_Pack(1, initial);
if (t_initial == NULL) {
@@ -1919,7 +1922,8 @@ array_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
return NULL;
}
Py_DECREF(v);
- } else if (initial != NULL && PyUnicode_Check(initial)) {
+ }
+ else if (initial != NULL && PyUnicode_Check(initial)) {
Py_ssize_t n = PyUnicode_GET_DATA_SIZE(initial);
if (n > 0) {
arrayobject *self = (arrayobject *)a;