memoryview.pxd 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. cdef extern from "Python.h":
  2. ###########################################################################
  3. # MemoryView Objects
  4. ###########################################################################
  5. # A memoryview object exposes the C level buffer interface as a Python
  6. # object which can then be passed around like any other object
  7. object PyMemoryView_FromObject(object obj)
  8. # Return value: New reference.
  9. # Create a memoryview object from an object that provides the buffer
  10. # interface. If obj supports writable buffer exports, the memoryview object
  11. # will be read/write, otherwise it may be either read-only or read/write at
  12. # the discretion of the exporter.
  13. object PyMemoryView_FromMemory(char *mem, Py_ssize_t size, int flags)
  14. # Return value: New reference.
  15. # Create a memoryview object using mem as the underlying buffer. flags can
  16. # be one of PyBUF_READ or PyBUF_WRITE.
  17. # New in version 3.3.
  18. object PyMemoryView_FromBuffer(Py_buffer *view)
  19. # Return value: New reference.
  20. # Create a memoryview object wrapping the given buffer structure view. For
  21. # simple byte buffers, PyMemoryView_FromMemory() is the preferred function.
  22. object PyMemoryView_GetContiguous(object obj,
  23. int buffertype,
  24. char order)
  25. # Return value: New reference.
  26. # Create a memoryview object to a contiguous chunk of memory (in either ‘C’
  27. # or ‘F’ortran order) from an object that defines the buffer interface. If
  28. # memory is contiguous, the memoryview object points to the original
  29. # memory. Otherwise, a copy is made and the memoryview points to a new
  30. # bytes object.
  31. bint PyMemoryView_Check(object obj)
  32. # Return true if the object obj is a memoryview object. It is not currently
  33. # allowed to create subclasses of memoryview.
  34. Py_buffer *PyMemoryView_GET_BUFFER(object mview)
  35. # Return a pointer to the memoryview’s private copy of the exporter’s
  36. # buffer. mview must be a memoryview instance; this macro doesn’t check its
  37. # type, you must do it yourself or you will risk crashes.
  38. Py_buffer *PyMemoryView_GET_BASE(object mview)
  39. # Return either a pointer to the exporting object that the memoryview is
  40. # based on or NULL if the memoryview has been created by one of the
  41. # functions PyMemoryView_FromMemory() or PyMemoryView_FromBuffer(). mview
  42. # must be a memoryview instance.