Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes15kdownloads
pybuffer.h146 linesDownload Raw Back to include
1/* Public Py_buffer API */2 3#ifndef Py_BUFFER_H4#define Py_BUFFER_H5#ifdef __cplusplus6extern "C" {7#endif8 9#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030b000010 11/* === New Buffer API ============================================12 * Limited API and stable ABI since Python 3.1113 *14 * Py_buffer struct layout and size is now part of the stable abi3. The15 * struct layout and size must not be changed in any way, as it would16 * break the ABI.17 *18 */19 20typedef struct {21    void *buf;22    PyObject *obj;        /* owned reference */23    Py_ssize_t len;24    Py_ssize_t itemsize;  /* This is Py_ssize_t so it can be25                             pointed to by strides in simple case.*/26    int readonly;27    int ndim;28    char *format;29    Py_ssize_t *shape;30    Py_ssize_t *strides;31    Py_ssize_t *suboffsets;32    void *internal;33} Py_buffer;34 35typedef int (*getbufferproc)(PyObject *, Py_buffer *, int);36typedef void (*releasebufferproc)(PyObject *, Py_buffer *);37 38/* Return 1 if the getbuffer function is available, otherwise return 0. */39PyAPI_FUNC(int) PyObject_CheckBuffer(PyObject *obj);40 41/* This is a C-API version of the getbuffer function call.  It checks42   to make sure object has the required function pointer and issues the43   call.44 45   Returns -1 and raises an error on failure and returns 0 on success. */46PyAPI_FUNC(int) PyObject_GetBuffer(PyObject *obj, Py_buffer *view,47                                   int flags);48 49/* Get the memory area pointed to by the indices for the buffer given.50   Note that view->ndim is the assumed size of indices. */51PyAPI_FUNC(void *) PyBuffer_GetPointer(const Py_buffer *view, const Py_ssize_t *indices);52 53/* Return the implied itemsize of the data-format area from a54   struct-style description. */55PyAPI_FUNC(Py_ssize_t) PyBuffer_SizeFromFormat(const char *format);56 57/* Implementation in memoryobject.c */58PyAPI_FUNC(int) PyBuffer_ToContiguous(void *buf, const Py_buffer *view,59                                      Py_ssize_t len, char order);60 61PyAPI_FUNC(int) PyBuffer_FromContiguous(const Py_buffer *view, const void *buf,62                                        Py_ssize_t len, char order);63 64/* Copy len bytes of data from the contiguous chunk of memory65   pointed to by buf into the buffer exported by obj.  Return66   0 on success and return -1 and raise a PyBuffer_Error on67   error (i.e. the object does not have a buffer interface or68   it is not working).69 70   If fort is 'F', then if the object is multi-dimensional,71   then the data will be copied into the array in72   Fortran-style (first dimension varies the fastest).  If73   fort is 'C', then the data will be copied into the array74   in C-style (last dimension varies the fastest).  If fort75   is 'A', then it does not matter and the copy will be made76   in whatever way is more efficient. */77PyAPI_FUNC(int) PyObject_CopyData(PyObject *dest, PyObject *src);78 79/* Copy the data from the src buffer to the buffer of destination. */80PyAPI_FUNC(int) PyBuffer_IsContiguous(const Py_buffer *view, char fort);81 82/*Fill the strides array with byte-strides of a contiguous83  (Fortran-style if fort is 'F' or C-style otherwise)84  array of the given shape with the given number of bytes85  per element. */86PyAPI_FUNC(void) PyBuffer_FillContiguousStrides(int ndims,87                                               Py_ssize_t *shape,88                                               Py_ssize_t *strides,89                                               int itemsize,90                                               char fort);91 92/* Fills in a buffer-info structure correctly for an exporter93   that can only share a contiguous chunk of memory of94   "unsigned bytes" of the given length.95 96   Returns 0 on success and -1 (with raising an error) on error. */97PyAPI_FUNC(int) PyBuffer_FillInfo(Py_buffer *view, PyObject *o, void *buf,98                                  Py_ssize_t len, int readonly,99                                  int flags);100 101/* Releases a Py_buffer obtained from getbuffer ParseTuple's "s*". */102PyAPI_FUNC(void) PyBuffer_Release(Py_buffer *view);103 104/* Maximum number of dimensions */105#define PyBUF_MAX_NDIM 64106 107/* Flags for getting buffers. Keep these in sync with inspect.BufferFlags. */108#define PyBUF_SIMPLE 0109#define PyBUF_WRITABLE 0x0001110 111#ifndef Py_LIMITED_API112/*  we used to include an E, backwards compatible alias */113#define PyBUF_WRITEABLE PyBUF_WRITABLE114#endif115 116#define PyBUF_FORMAT 0x0004117#define PyBUF_ND 0x0008118#define PyBUF_STRIDES (0x0010 | PyBUF_ND)119#define PyBUF_C_CONTIGUOUS (0x0020 | PyBUF_STRIDES)120#define PyBUF_F_CONTIGUOUS (0x0040 | PyBUF_STRIDES)121#define PyBUF_ANY_CONTIGUOUS (0x0080 | PyBUF_STRIDES)122#define PyBUF_INDIRECT (0x0100 | PyBUF_STRIDES)123 124#define PyBUF_CONTIG (PyBUF_ND | PyBUF_WRITABLE)125#define PyBUF_CONTIG_RO (PyBUF_ND)126 127#define PyBUF_STRIDED (PyBUF_STRIDES | PyBUF_WRITABLE)128#define PyBUF_STRIDED_RO (PyBUF_STRIDES)129 130#define PyBUF_RECORDS (PyBUF_STRIDES | PyBUF_WRITABLE | PyBUF_FORMAT)131#define PyBUF_RECORDS_RO (PyBUF_STRIDES | PyBUF_FORMAT)132 133#define PyBUF_FULL (PyBUF_INDIRECT | PyBUF_WRITABLE | PyBUF_FORMAT)134#define PyBUF_FULL_RO (PyBUF_INDIRECT | PyBUF_FORMAT)135 136 137#define PyBUF_READ  0x100138#define PyBUF_WRITE 0x200139 140#endif /* !Py_LIMITED_API || Py_LIMITED_API >= 3.11 */141 142#ifdef __cplusplus143}144#endif145#endif /* Py_BUFFER_H */146 
codekingpro/portable-devtools · Team Ai