diff options
-rw-r--r-- | Include/object.h | 19 | ||||
-rw-r--r-- | Modules/arraymodule.c | 12 | ||||
-rw-r--r-- | Objects/abstract.c | 2 | ||||
-rw-r--r-- | Objects/unicodeobject.c | 4 | ||||
-rw-r--r-- | Python/getargs.c | 6 |
5 files changed, 20 insertions, 23 deletions
diff --git a/Include/object.h b/Include/object.h index c9d2217..061fe11 100644 --- a/Include/object.h +++ b/Include/object.h @@ -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) diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c index 051063b..cc7769f 100644 --- a/Modules/arraymodule.c +++ b/Modules/arraymodule.c @@ -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: diff --git a/Objects/abstract.c b/Objects/abstract.c index 3d736d1..e848f8f 100644 --- a/Objects/abstract.c +++ b/Objects/abstract.c @@ -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; diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index e622967..73aeec4 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -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); } diff --git a/Python/getargs.c b/Python/getargs.c index dc1bae0..de9cc93 100644 --- a/Python/getargs.c +++ b/Python/getargs.c @@ -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); |