summaryrefslogtreecommitdiff
path: root/Cython/Utility/MemoryView_C.c
diff options
context:
space:
mode:
Diffstat (limited to 'Cython/Utility/MemoryView_C.c')
-rw-r--r--Cython/Utility/MemoryView_C.c22
1 files changed, 13 insertions, 9 deletions
diff --git a/Cython/Utility/MemoryView_C.c b/Cython/Utility/MemoryView_C.c
index 9f4828d1f..0a5d8ee2c 100644
--- a/Cython/Utility/MemoryView_C.c
+++ b/Cython/Utility/MemoryView_C.c
@@ -347,18 +347,22 @@ static int __Pyx_ValidateAndInit_memviewslice(
}
/* Check axes */
- for (i = 0; i < ndim; i++) {
- spec = axes_specs[i];
- if (unlikely(!__pyx_check_strides(buf, i, ndim, spec)))
- goto fail;
- if (unlikely(!__pyx_check_suboffsets(buf, i, ndim, spec)))
+ if (buf->len > 0) {
+ // 0-sized arrays do not undergo these checks since their strides are
+ // irrelevant and they are always both C- and F-contiguous.
+ for (i = 0; i < ndim; i++) {
+ spec = axes_specs[i];
+ if (unlikely(!__pyx_check_strides(buf, i, ndim, spec)))
+ goto fail;
+ if (unlikely(!__pyx_check_suboffsets(buf, i, ndim, spec)))
+ goto fail;
+ }
+
+ /* Check contiguity */
+ if (unlikely(buf->strides && !__pyx_verify_contig(buf, ndim, c_or_f_flag)))
goto fail;
}
- /* Check contiguity */
- if (unlikely(buf->strides && !__pyx_verify_contig(buf, ndim, c_or_f_flag)))
- goto fail;
-
/* Initialize */
if (unlikely(__Pyx_init_memviewslice(memview, ndim, memviewslice,
new_memview != NULL) == -1)) {