1 # Please see the Python header files (object.h/abstract.h) for docs 2 3 cdef extern from "Python.h": 4 5 cdef enum: 6 PyBUF_SIMPLE, 7 PyBUF_WRITABLE, 8 PyBUF_WRITEABLE, # backwards compatability 9 PyBUF_FORMAT, 10 PyBUF_ND, 11 PyBUF_STRIDES, 12 PyBUF_C_CONTIGUOUS, 13 PyBUF_F_CONTIGUOUS, 14 PyBUF_ANY_CONTIGUOUS, 15 PyBUF_INDIRECT, 16 PyBUF_CONTIG, 17 PyBUF_CONTIG_RO, 18 PyBUF_STRIDED, 19 PyBUF_STRIDED_RO, 20 PyBUF_RECORDS, 21 PyBUF_RECORDS_RO, 22 PyBUF_FULL, 23 PyBUF_FULL_RO, 24 PyBUF_READ, 25 PyBUF_WRITE, 26 PyBUF_SHADOW 27 28 bint PyObject_CheckBuffer(object obj) 29 # Return 1 if obj supports the buffer interface otherwise 0. 30 31 int PyObject_GetBuffer(object obj, Py_buffer *view, int flags) except -1 32 # Export obj into a Py_buffer, view. These arguments must never be 33 # NULL. The flags argument is a bit field indicating what kind of 34 # buffer the caller is prepared to deal with and therefore what 35 # kind of buffer the exporter is allowed to return. The buffer 36 # interface allows for complicated memory sharing possibilities, 37 # but some caller may not be able to handle all the complexity but 38 # may want to see if the exporter will let them take a simpler 39 # view to its memory. 40 41 # Some exporters may not be able to share memory in every possible 42 # way and may need to raise errors to signal to some consumers 43 # that something is just not possible. These errors should be a 44 # BufferError unless there is another error that is actually 45 # causing the problem. The exporter can use flags information to 46 # simplify how much of the Py_buffer structure is filled in with 47 # non-default values and/or raise an error if the object cant 48 # support a simpler view of its memory. 49 50 # 0 is returned on success and -1 on error. 51 52 void PyBuffer_Release(Py_buffer *view) 53 # Release the buffer view. This should be called when the buffer 54 # is no longer being used as it may free memory from it. 55 56 void* PyBuffer_GetPointer(Py_buffer *view, Py_ssize_t *indices) 57 # ?? 58 59 Py_ssize_t PyBuffer_SizeFromFormat(char *) # actually const char 60 # Return the implied ~Py_buffer.itemsize from the struct-stype 61 # ~Py_buffer.format 62 63 int PyBuffer_ToContiguous(void *buf, Py_buffer *view, Py_ssize_t len, char fort) 64 # ?? 65 66 int PyBuffer_FromContiguous(Py_buffer *view, void *buf, Py_ssize_t len, char fort) 67 # ?? 68 69 int PyObject_CopyToObject(object obj, void *buf, Py_ssize_t len, char fortran) except -1 70 # Copy len bytes of data pointed to by the contiguous chunk of 71 # memory pointed to by buf into the buffer exported by obj. The 72 # buffer must of course be writable. Return 0 on success and 73 # return -1 and raise an error on failure. If the object does not 74 # have a writable buffer, then an error is raised. If fortran is 75 # 'F', then if the object is multi-dimensional, then the data will 76 # be copied into the array in Fortran-style (first dimension 77 # varies the fastest). If fortran is 'C', then the data will be 78 # copied into the array in C-style (last dimension varies the 79 # fastest). If fortran is 'A', then it does not matter and the 80 # copy will be made in whatever way is more efficient. 81 82 int PyObject_CopyData(object dest, object src) except -1 83 # Copy the data from the src buffer to the buffer of destination 84 85 bint PyBuffer_IsContiguous(Py_buffer *view, char fort) 86 # Return 1 if the memory defined by the view is C-style (fortran 87 # is 'C') or Fortran-style (fortran is 'F') contiguous or either 88 # one (fortran is 'A'). Return 0 otherwise. 89 90 void PyBuffer_FillContiguousStrides(int ndims, 91 Py_ssize_t *shape, 92 Py_ssize_t *strides, 93 Py_ssize_t itemsize, 94 char fort) 95 # Fill the strides array with byte-strides of a contiguous 96 # (Fortran-style if fort is 'F' or C-style otherwise) array of the 97 # given shape with the given number of bytes per element. 98 99 int PyBuffer_FillInfo(Py_buffer *view, object exporter, void *buf, 100 Py_ssize_t len, int readonly, int flags) except -1 101 # Fill in a buffer-info structure, view, correctly for an exporter 102 # that can only share a contiguous chunk of memory of unsigned 103 # bytes of the given length. Return 0 on success and -1 (with 104 # raising an error) on error. 105 106 # DEPRECATED HERE: do not cimport from here, cimport from cpython.object instead 107 object PyObject_Format(object obj, object format_spec) 108 # Takes an arbitrary object and returns the result of calling 109 # obj.__format__(format_spec). 110