input ndslice
output Py_buffer. Py_buffer.internal is initialized with null value, Py_buffer.obj is not initialized. Other Py_buffer fields are initialized according to the flags and slice.
requester flags
Single chunk of memory with the same alignment and size as Structure. The buffer is used to store shape and strides for the view.
one of the cannot_create_* PythonBufferErrorCode on failure and success otherwise.
import mir.ndslice.slice : Slice, Structure, Universal, Contiguous, SliceKind; Py_buffer bar(SliceKind kind)(Slice!(double*, 2, kind) slice) { import core.stdc.stdlib; enum N = 2; auto structurePtr = cast(Structure!N*) Structure!N.sizeof.malloc; if (!structurePtr) assert(0); Py_buffer view; if (auto error = slice.toPythonBuffer(view, PyBuf_records_ro, *structurePtr)) { view = view.init; // null buffer structurePtr.free; } else { assert(cast(sizediff_t*)&structurePtr.lengths == view.shape); assert(cast(sizediff_t*)&structurePtr.strides == view.strides); } return view; } alias barUni = bar!Universal; alias barCon = bar!Contiguous;
Fills the python view (structure) from the slice.