summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorPauli Virtanen <pav@iki.fi>2010-02-20 18:04:27 +0000
committerPauli Virtanen <pav@iki.fi>2010-02-20 18:04:27 +0000
commit3577b83422361c67ddb0efe6fcafe5a18467bf44 (patch)
treef8b04c23d45251e7e440b2610db42f34f913b974 /numpy
parent4a59b9f51787de1d9ad8effb53498e93bbfd8d23 (diff)
downloadnumpy-3577b83422361c67ddb0efe6fcafe5a18467bf44.tar.gz
ENH: core: require PEP 3118 buffer contiguity only with ND and not STRIDES
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/src/multiarray/buffer.c29
1 files changed, 21 insertions, 8 deletions
diff --git a/numpy/core/src/multiarray/buffer.c b/numpy/core/src/multiarray/buffer.c
index 1fe2fc367..b379aebcd 100644
--- a/numpy/core/src/multiarray/buffer.c
+++ b/numpy/core/src/multiarray/buffer.c
@@ -471,10 +471,6 @@ array_getbuffer(PyObject *obj, Py_buffer *view, int flags)
self = (PyArrayObject*)obj;
- if (view == NULL) {
- goto fail;
- }
-
/* Check whether we can provide the wanted properties */
if ((flags & PyBUF_C_CONTIGUOUS) == PyBUF_C_CONTIGUOUS &&
!PyArray_CHKFLAGS(self, NPY_C_CONTIGUOUS)) {
@@ -492,8 +488,9 @@ array_getbuffer(PyObject *obj, Py_buffer *view, int flags)
goto fail;
}
if ((flags & PyBUF_STRIDES) != PyBUF_STRIDES &&
+ (flags & PyBUF_ND) == PyBUF_ND &&
!PyArray_CHKFLAGS(self, NPY_C_CONTIGUOUS)) {
- /* Non-strided buffers must be C-contiguous */
+ /* Non-strided N-dim buffers must be C-contiguous */
PyErr_SetString(PyExc_ValueError, "ndarray is not C-contiguous");
goto fail;
}
@@ -503,6 +500,11 @@ array_getbuffer(PyObject *obj, Py_buffer *view, int flags)
goto fail;
}
+ if (view == NULL) {
+ PyErr_SetString(PyExc_ValueError, "NULL view in getbuffer");
+ goto fail;
+ }
+
/* Fill in information */
info = _buffer_get_info(obj);
if (info == NULL) {
@@ -520,9 +522,20 @@ array_getbuffer(PyObject *obj, Py_buffer *view, int flags)
} else {
view->format = NULL;
}
- view->ndim = info->ndim;
- view->shape = info->shape;
- view->strides = info->strides;
+ if ((flags & PyBUF_ND) == PyBUF_ND) {
+ view->ndim = info->ndim;
+ view->shape = info->shape;
+ }
+ else {
+ view->ndim = 0;
+ view->shape = NULL;
+ }
+ if ((flags & PyBUF_STRIDES) == PyBUF_STRIDES) {
+ view->strides = info->strides;
+ }
+ else {
+ view->strides = NULL;
+ }
view->obj = (PyObject*)self;
Py_INCREF(self);