Eliminate use of PyBUF_CHARACTER flag which is no longer part of the buffer interface. Fix up array module to export the correct format for wide-builds.
This commit is contained in:
parent
d417a154e4
commit
ddacf96868
|
@ -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)
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue