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