1 # Please see the Python header files (object.h/abstract.h) for docs
3 cdef extern from "Python.h":
8 PyBUF_WRITEABLE, # backwards compatability
28 bint PyObject_CheckBuffer(object obj)
29 # Return 1 if obj supports the buffer interface otherwise 0.
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
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 can’t
48 # support a simpler view of its memory.
50 # 0 is returned on success and -1 on error.
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.
56 void* PyBuffer_GetPointer(Py_buffer *view, Py_ssize_t *indices)
59 Py_ssize_t PyBuffer_SizeFromFormat(char *) # actually const char
60 # Return the implied ~Py_buffer.itemsize from the struct-stype
63 int PyBuffer_ToContiguous(void *buf, Py_buffer *view, Py_ssize_t len, char fort)
66 int PyBuffer_FromContiguous(Py_buffer *view, void *buf, Py_ssize_t len, char fort)
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.
82 int PyObject_CopyData(object dest, object src) except -1
83 # Copy the data from the src buffer to the buffer of destination
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.
90 void PyBuffer_FillContiguousStrides(int ndims,
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.
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.
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).