buffer.pxd 4.8 KB

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