/* Public Py_buffer API */12#ifndef Py_BUFFER_H3#define Py_BUFFER_H4#ifdef __cplusplus5extern "C" {6#endif78#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030b0000910/* === New Buffer API ============================================11* Limited API and stable ABI since Python 3.1112*13* Py_buffer struct layout and size is now part of the stable abi3. The14* struct layout and size must not be changed in any way, as it would15* break the ABI.16*17*/1819typedef struct {20void *buf;21PyObject *obj; /* owned reference */22Py_ssize_t len;23Py_ssize_t itemsize; /* This is Py_ssize_t so it can be24pointed to by strides in simple case.*/25int readonly;26int ndim;27char *format;28Py_ssize_t *shape;29Py_ssize_t *strides;30Py_ssize_t *suboffsets;31void *internal;32} Py_buffer;3334typedef int (*getbufferproc)(PyObject *, Py_buffer *, int);35typedef void (*releasebufferproc)(PyObject *, Py_buffer *);3637/* Return 1 if the getbuffer function is available, otherwise return 0. */38PyAPI_FUNC(int) PyObject_CheckBuffer(PyObject *obj);3940/* This is a C-API version of the getbuffer function call. It checks41to make sure object has the required function pointer and issues the42call.4344Returns -1 and raises an error on failure and returns 0 on success. */45PyAPI_FUNC(int) PyObject_GetBuffer(PyObject *obj, Py_buffer *view,46int flags);4748/* Get the memory area pointed to by the indices for the buffer given.49Note that view->ndim is the assumed size of indices. */50PyAPI_FUNC(void *) PyBuffer_GetPointer(const Py_buffer *view, const Py_ssize_t *indices);5152/* Return the implied itemsize of the data-format area from a53struct-style description. */54PyAPI_FUNC(Py_ssize_t) PyBuffer_SizeFromFormat(const char *format);5556/* Implementation in memoryobject.c */57PyAPI_FUNC(int) PyBuffer_ToContiguous(void *buf, const Py_buffer *view,58Py_ssize_t len, char order);5960PyAPI_FUNC(int) PyBuffer_FromContiguous(const Py_buffer *view, const void *buf,61Py_ssize_t len, char order);6263/* Copy len bytes of data from the contiguous chunk of memory64pointed to by buf into the buffer exported by obj. Return650 on success and return -1 and raise a PyBuffer_Error on66error (i.e. the object does not have a buffer interface or67it is not working).6869If fort is 'F', then if the object is multi-dimensional,70then the data will be copied into the array in71Fortran-style (first dimension varies the fastest). If72fort is 'C', then the data will be copied into the array73in C-style (last dimension varies the fastest). If fort74is 'A', then it does not matter and the copy will be made75in whatever way is more efficient. */76PyAPI_FUNC(int) PyObject_CopyData(PyObject *dest, PyObject *src);7778/* Copy the data from the src buffer to the buffer of destination. */79PyAPI_FUNC(int) PyBuffer_IsContiguous(const Py_buffer *view, char fort);8081/*Fill the strides array with byte-strides of a contiguous82(Fortran-style if fort is 'F' or C-style otherwise)83array of the given shape with the given number of bytes84per element. */85PyAPI_FUNC(void) PyBuffer_FillContiguousStrides(int ndims,86Py_ssize_t *shape,87Py_ssize_t *strides,88int itemsize,89char fort);9091/* Fills in a buffer-info structure correctly for an exporter92that can only share a contiguous chunk of memory of93"unsigned bytes" of the given length.9495Returns 0 on success and -1 (with raising an error) on error. */96PyAPI_FUNC(int) PyBuffer_FillInfo(Py_buffer *view, PyObject *o, void *buf,97Py_ssize_t len, int readonly,98int flags);99100/* Releases a Py_buffer obtained from getbuffer ParseTuple's "s*". */101PyAPI_FUNC(void) PyBuffer_Release(Py_buffer *view);102103/* Maximum number of dimensions */104#define PyBUF_MAX_NDIM 64105106/* Flags for getting buffers. Keep these in sync with inspect.BufferFlags. */107#define PyBUF_SIMPLE 0108#define PyBUF_WRITABLE 0x0001109110#ifndef Py_LIMITED_API111/* we used to include an E, backwards compatible alias */112#define PyBUF_WRITEABLE PyBUF_WRITABLE113#endif114115#define PyBUF_FORMAT 0x0004116#define PyBUF_ND 0x0008117#define PyBUF_STRIDES (0x0010 | PyBUF_ND)118#define PyBUF_C_CONTIGUOUS (0x0020 | PyBUF_STRIDES)119#define PyBUF_F_CONTIGUOUS (0x0040 | PyBUF_STRIDES)120#define PyBUF_ANY_CONTIGUOUS (0x0080 | PyBUF_STRIDES)121#define PyBUF_INDIRECT (0x0100 | PyBUF_STRIDES)122123#define PyBUF_CONTIG (PyBUF_ND | PyBUF_WRITABLE)124#define PyBUF_CONTIG_RO (PyBUF_ND)125126#define PyBUF_STRIDED (PyBUF_STRIDES | PyBUF_WRITABLE)127#define PyBUF_STRIDED_RO (PyBUF_STRIDES)128129#define PyBUF_RECORDS (PyBUF_STRIDES | PyBUF_WRITABLE | PyBUF_FORMAT)130#define PyBUF_RECORDS_RO (PyBUF_STRIDES | PyBUF_FORMAT)131132#define PyBUF_FULL (PyBUF_INDIRECT | PyBUF_WRITABLE | PyBUF_FORMAT)133#define PyBUF_FULL_RO (PyBUF_INDIRECT | PyBUF_FORMAT)134135136#define PyBUF_READ 0x100137#define PyBUF_WRITE 0x200138139#endif /* !Py_LIMITED_API || Py_LIMITED_API >= 3.11 */140141#ifdef __cplusplus142}143#endif144#endif /* Py_BUFFER_H */145146147