diff --git a/src/Wrap/PyArray.jl b/src/Wrap/PyArray.jl index 7b1dc8d3..dc11c085 100644 --- a/src/Wrap/PyArray.jl +++ b/src/Wrap/PyArray.jl @@ -531,6 +531,8 @@ end function PyArraySource_Buffer(x::Py) memview = pybuiltins.memoryview(x) buf = C.UnsafePtr(C.PyMemoryView_GET_BUFFER(memview)) + buf.suboffsets[] == C_NULL || + error("PyArray does not support buffers with non-trivial suboffsets (PIL-style indirect layout)") PyArraySource_Buffer(x, memview, buf) end diff --git a/test/Wrap.jl b/test/Wrap.jl index c42d45ab..5665003e 100644 --- a/test/Wrap.jl +++ b/test/Wrap.jl @@ -91,6 +91,17 @@ end end +@testitem "PyArray buffer with suboffsets is rejected" begin + tb = pyimport("_testbuffer") + nd = tb.ndarray( + pylist([1, 2, 3, 4, 5, 6]), + shape = pylist([2, 3]), + format = "i", + flags = tb.ND_PIL | tb.ND_WRITABLE, + ) + @test_throws Exception PyArray(nd; array = false, buffer = true) +end + @testitem "PyDict" begin x = pydict(["foo" => 12]) y = PyDict(x)