summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorStefan Krah <skrah@bytereef.org>2012-07-28 10:25:55 (GMT)
committerStefan Krah <skrah@bytereef.org>2012-07-28 10:25:55 (GMT)
commit7d12d9df136b45785fb945dcb4812fdb068a2498 (patch)
treea68da71ef9e618cad72d9d6b589d6bdbc589873e /Modules
parent6c779ea55329947577119b8a7ea732f6d540d516 (diff)
downloadcpython-7d12d9df136b45785fb945dcb4812fdb068a2498.zip
cpython-7d12d9df136b45785fb945dcb4812fdb068a2498.tar.gz
cpython-7d12d9df136b45785fb945dcb4812fdb068a2498.tar.bz2
Issue #12834: Fix PyBuffer_ToContiguous() for non-contiguous arrays.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_testbuffer.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/Modules/_testbuffer.c b/Modules/_testbuffer.c
index 1ff685c..b291a14 100644
--- a/Modules/_testbuffer.c
+++ b/Modules/_testbuffer.c
@@ -2397,6 +2397,49 @@ get_contiguous(PyObject *self, PyObject *args)
return PyMemoryView_GetContiguous(obj, (int)type, ord);
}
+/* PyBuffer_ToContiguous() */
+static PyObject *
+py_buffer_to_contiguous(PyObject *self, PyObject *args)
+{
+ PyObject *obj;
+ PyObject *order;
+ PyObject *ret = NULL;
+ int flags;
+ char ord;
+ Py_buffer view;
+ char *buf = NULL;
+
+ if (!PyArg_ParseTuple(args, "OOi", &obj, &order, &flags)) {
+ return NULL;
+ }
+
+ if (PyObject_GetBuffer(obj, &view, flags) < 0) {
+ return NULL;
+ }
+
+ ord = get_ascii_order(order);
+ if (ord == CHAR_MAX) {
+ goto out;
+ }
+
+ buf = PyMem_Malloc(view.len);
+ if (buf == NULL) {
+ PyErr_NoMemory();
+ goto out;
+ }
+
+ if (PyBuffer_ToContiguous(buf, &view, view.len, ord) < 0) {
+ goto out;
+ }
+
+ ret = PyBytes_FromStringAndSize(buf, view.len);
+
+out:
+ PyBuffer_Release(&view);
+ PyMem_XFree(buf);
+ return ret;
+}
+
static int
fmtcmp(const char *fmt1, const char *fmt2)
{
@@ -2734,6 +2777,7 @@ static struct PyMethodDef _testbuffer_functions[] = {
{"get_pointer", get_pointer, METH_VARARGS, NULL},
{"get_sizeof_void_p", (PyCFunction)get_sizeof_void_p, METH_NOARGS, NULL},
{"get_contiguous", get_contiguous, METH_VARARGS, NULL},
+ {"py_buffer_to_contiguous", py_buffer_to_contiguous, METH_VARARGS, NULL},
{"is_contiguous", is_contiguous, METH_VARARGS, NULL},
{"cmp_contig", cmp_contig, METH_VARARGS, NULL},
{NULL, NULL}