]> granicus.if.org Git - python/commitdiff
Eliminate use of PyBUF_CHARACTER flag which is no longer part of the buffer interface...
authorTravis E. Oliphant <oliphant@enthought.com>
Sat, 13 Oct 2007 21:03:27 +0000 (21:03 +0000)
committerTravis E. Oliphant <oliphant@enthought.com>
Sat, 13 Oct 2007 21:03:27 +0000 (21:03 +0000)
Include/object.h
Modules/arraymodule.c
Objects/abstract.c
Objects/unicodeobject.c
Python/getargs.c

index c9d2217f212b603c0b9f22064c0f4554c3405fa8..061fe116f9bc51f6001f27c4ca49ef7783fdc705 100644 (file)
@@ -160,18 +160,17 @@ typedef void (*releasebufferproc)(PyObject *, Py_buffer *);
 
         /* Flags for getting buffers */
 #define PyBUF_SIMPLE 0
-#define PyBUF_CHARACTER 1
-#define PyBUF_WRITABLE 0x0002
+#define PyBUF_WRITABLE 0x0001
 /*  we used to include an E, backwards compatible alias  */
 #define PyBUF_WRITEABLE PyBUF_WRITABLE
-#define PyBUF_LOCK 0x0004
-#define PyBUF_FORMAT 0x0008
-#define PyBUF_ND 0x0010
-#define PyBUF_STRIDES (0x0020 | PyBUF_ND)
-#define PyBUF_C_CONTIGUOUS (0x0040 | PyBUF_STRIDES)
-#define PyBUF_F_CONTIGUOUS (0x0080 | PyBUF_STRIDES)
-#define PyBUF_ANY_CONTIGUOUS (0x0100 | PyBUF_STRIDES)
-#define PyBUF_INDIRECT (0x0200 | PyBUF_STRIDES)
+#define PyBUF_LOCK 0x0002
+#define PyBUF_FORMAT 0x0004
+#define PyBUF_ND 0x0008
+#define PyBUF_STRIDES (0x0010 | PyBUF_ND)
+#define PyBUF_C_CONTIGUOUS (0x0020 | PyBUF_STRIDES)
+#define PyBUF_F_CONTIGUOUS (0x0040 | PyBUF_STRIDES)
+#define PyBUF_ANY_CONTIGUOUS (0x0080 | PyBUF_STRIDES)
+#define PyBUF_INDIRECT (0x0100 | PyBUF_STRIDES)
 
 #define PyBUF_CONTIG (PyBUF_ND | PyBUF_WRITABLE)
 #define PyBUF_CONTIG_RO (PyBUF_ND)
index 051063b86c39e3a02f2997cb8973bffdae64584c..cc7769f162f8ce7dfacd76cca98d161f8151304e 100644 (file)
@@ -385,7 +385,7 @@ d_setitem(arrayobject *ap, Py_ssize_t i, PyObject *v)
 static struct arraydescr descriptors[] = {
        {'b', 1, b_getitem, b_setitem, "b"},
        {'B', 1, BB_getitem, BB_setitem, "B"},
-       {'u', sizeof(Py_UNICODE), u_getitem, u_setitem, "U"},
+       {'u', sizeof(Py_UNICODE), u_getitem, u_setitem, "u"},
        {'h', sizeof(short), h_getitem, h_setitem, "h"},
        {'H', sizeof(short), HH_getitem, HH_setitem, "H"},
        {'i', sizeof(int), i_getitem, i_setitem, "i"},
@@ -1784,11 +1784,6 @@ static const void *emptybuf = "";
 static int
 array_buffer_getbuf(arrayobject *self, Py_buffer *view, int flags)
 {
-        if ((flags & PyBUF_CHARACTER)) {
-                PyErr_SetString(PyExc_TypeError,
-                                "Cannot be a character buffer");
-                return -1;
-        }
         if ((flags & PyBUF_LOCK)) {
                 PyErr_SetString(PyExc_BufferError,
                                 "Cannot lock data");
@@ -1815,6 +1810,11 @@ array_buffer_getbuf(arrayobject *self, Py_buffer *view, int flags)
         view->internal = NULL;
         if ((flags & PyBUF_FORMAT) == PyBUF_FORMAT) {
                 view->format = self->ob_descr->formats;
+#ifdef Py_UNICODE_WIDE
+               if (self->ob_descr->typecode == 'u') {
+                       view->formats = "w";
+               }
+#endif
         }
 
  finish:
index 3d736d1c132da8a1447d9560bdfe798d63dae2cd..e848f8fd7fdaba4ad09121859760ea167fcf736d 100644 (file)
@@ -236,7 +236,7 @@ PyObject_AsCharBuffer(PyObject *obj,
                                "expected an object with the buffer interface");
                return -1;
        }
-       if ((*pb->bf_getbuffer)(obj, &view, PyBUF_CHARACTER)) return -1;
+       if ((*pb->bf_getbuffer)(obj, &view, PyBUF_SIMPLE)) return -1;
 
        *buffer = view.buf;
        *buffer_len = view.len;
index e622967d1d9c33e89d308236b6a281c47fd38fbe..73aeec4ab4bf1043248bf68984ae6d14c0cd7c1c 100644 (file)
@@ -8117,10 +8117,6 @@ static int
 unicode_buffer_getbuffer(PyUnicodeObject *self, Py_buffer *view, int flags)
 {
 
-    if (flags & PyBUF_CHARACTER) {
-        PyErr_SetString(PyExc_SystemError, "can't use str as char buffer");
-        return -1;
-    }
     return PyBuffer_FillInfo(view, (void *)self->str,
                              PyUnicode_GET_DATA_SIZE(self), 1, flags);
 }
index dc1bae00f0674ced2a92c1cbce7eb178e18f8274..de9cc93afacf9d5e28c4335cc31d0f393281b7d9 100644 (file)
@@ -1237,7 +1237,9 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
                         (*pb->bf_releasebuffer)(arg, &view);
                break;
        }
-               
+
+         /*TEO: This can be eliminated --- here only for backward
+           compatibility */
        case 't': { /* 8-bit character buffer, read-only access */
                char **p = va_arg(*p_va, char **);
                PyBufferProcs *pb = arg->ob_type->tp_as_buffer;
@@ -1253,7 +1255,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
                                "string or read-only character buffer",
                                arg, msgbuf, bufsize);
 
-               if ((*pb->bf_getbuffer)(arg, &view, PyBUF_CHARACTER) != 0) 
+               if ((*pb->bf_getbuffer)(arg, &view, PyBUF_SIMPLE) != 0) 
                        return converterr("string or single-segment read-only buffer",
                                           arg, msgbuf, bufsize);