Author: christian.heimes
Date: Sat Nov  3 13:30:43 2007
New Revision: 58826

Modified:
   python/branches/py3k-pep3137/Modules/_fileio.c
   python/branches/py3k-pep3137/Modules/arraymodule.c
Log:
Fixed bug in test_array as mentioned by Brett on the ml. 
Changed fileio_read() and _readall() to use PyString instead of PyBytes
Fixed array to support PyString, too.

Modified: python/branches/py3k-pep3137/Modules/_fileio.c
==============================================================================
--- python/branches/py3k-pep3137/Modules/_fileio.c      (original)
+++ python/branches/py3k-pep3137/Modules/_fileio.c      Sat Nov  3 13:30:43 2007
@@ -400,14 +400,14 @@
        Py_ssize_t total = 0;
        int n;
 
-       result = PyBytes_FromStringAndSize(NULL, DEFAULT_BUFFER_SIZE);
+       result = PyString_FromStringAndSize(NULL, DEFAULT_BUFFER_SIZE);
        if (result == NULL)
                return NULL;
 
        while (1) {
                Py_ssize_t newsize = total + DEFAULT_BUFFER_SIZE;
-               if (PyBytes_GET_SIZE(result) < newsize) {
-                       if (PyBytes_Resize(result, newsize) < 0) {
+               if (PyString_GET_SIZE(result) < newsize) {
+                       if (_PyString_Resize(&result, newsize) < 0) {
                                if (total == 0) {
                                        Py_DECREF(result);
                                        return NULL;
@@ -419,7 +419,7 @@
                Py_BEGIN_ALLOW_THREADS
                errno = 0;
                n = read(self->fd,
-                        PyBytes_AS_STRING(result) + total,
+                        PyString_AS_STRING(result) + total,
                         newsize - total);
                Py_END_ALLOW_THREADS
                if (n == 0)
@@ -438,8 +438,8 @@
                total += n;
        }
 
-       if (PyBytes_GET_SIZE(result) > total) {
-               if (PyBytes_Resize(result, total) < 0) {
+       if (PyString_GET_SIZE(result) > total) {
+               if (_PyString_Resize(&result, total) < 0) {
                        /* This should never happen, but just in case */
                        Py_DECREF(result);
                        return NULL;
@@ -468,10 +468,10 @@
                return fileio_readall(self);
        }
 
-       bytes = PyBytes_FromStringAndSize(NULL, size);
+       bytes = PyString_FromStringAndSize(NULL, size);
        if (bytes == NULL)
                return NULL;
-       ptr = PyBytes_AsString(bytes);
+       ptr = PyString_AS_STRING(bytes);
 
        Py_BEGIN_ALLOW_THREADS
        errno = 0;
@@ -486,7 +486,7 @@
        }
 
        if (n != size) {
-               if (PyBytes_Resize(bytes, n) < 0) {
+               if (_PyString_Resize(&bytes, n) < 0) {
                        Py_DECREF(bytes);
                        return NULL;
                }

Modified: python/branches/py3k-pep3137/Modules/arraymodule.c
==============================================================================
--- python/branches/py3k-pep3137/Modules/arraymodule.c  (original)
+++ python/branches/py3k-pep3137/Modules/arraymodule.c  Sat Nov  3 13:30:43 2007
@@ -1212,14 +1212,14 @@
        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 @@
                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 @@
 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 @@
 
        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 @@
                                        }
                                        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 @@
                                        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;
_______________________________________________
Python-3000-checkins mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-3000-checkins

Reply via email to