You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
2.8 KiB

  1. /* Memory view object. In Python this is available as "memoryview". */
  2. #ifndef Py_MEMORYOBJECT_H
  3. #define Py_MEMORYOBJECT_H
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  7. PyAPI_DATA(PyTypeObject) PyMemoryView_Type;
  8. #define PyMemoryView_Check(op) (Py_TYPE(op) == &PyMemoryView_Type)
  9. #ifndef Py_LIMITED_API
  10. /* Get a pointer to the underlying Py_buffer of a memoryview object. */
  11. #define PyMemoryView_GET_BUFFER(op) (&((PyMemoryViewObject *)(op))->view)
  12. /* Get a pointer to the PyObject from which originates a memoryview object. */
  13. #define PyMemoryView_GET_BASE(op) (((PyMemoryViewObject *)(op))->view.obj)
  14. #endif
  15. PyAPI_FUNC(PyObject *) PyMemoryView_GetContiguous(PyObject *base,
  16. int buffertype,
  17. char fort);
  18. /* Return a contiguous chunk of memory representing the buffer
  19. from an object in a memory view object. If a copy is made then the
  20. base object for the memory view will be a *new* bytes object.
  21. Otherwise, the base-object will be the object itself and no
  22. data-copying will be done.
  23. The buffertype argument can be PyBUF_READ, PyBUF_WRITE,
  24. PyBUF_SHADOW to determine whether the returned buffer
  25. should be READONLY, WRITABLE, or set to update the
  26. original buffer if a copy must be made. If buffertype is
  27. PyBUF_WRITE and the buffer is not contiguous an error will
  28. be raised. In this circumstance, the user can use
  29. PyBUF_SHADOW to ensure that a a writable temporary
  30. contiguous buffer is returned. The contents of this
  31. contiguous buffer will be copied back into the original
  32. object after the memoryview object is deleted as long as
  33. the original object is writable and allows setting an
  34. exclusive write lock. If this is not allowed by the
  35. original object, then a BufferError is raised.
  36. If the object is multi-dimensional and if fortran is 'F',
  37. the first dimension of the underlying array will vary the
  38. fastest in the buffer. If fortran is 'C', then the last
  39. dimension will vary the fastest (C-style contiguous). If
  40. fortran is 'A', then it does not matter and you will get
  41. whatever the object decides is more efficient.
  42. A new reference is returned that must be DECREF'd when finished.
  43. */
  44. PyAPI_FUNC(PyObject *) PyMemoryView_FromObject(PyObject *base);
  45. #ifndef Py_LIMITED_API
  46. PyAPI_FUNC(PyObject *) PyMemoryView_FromBuffer(Py_buffer *info);
  47. /* create new if bufptr is NULL
  48. will be a new bytesobject in base */
  49. #endif
  50. /* The struct is declared here so that macros can work, but it shouldn't
  51. be considered public. Don't access those fields directly, use the macros
  52. and functions instead! */
  53. #ifndef Py_LIMITED_API
  54. typedef struct {
  55. PyObject_HEAD
  56. Py_buffer view;
  57. } PyMemoryViewObject;
  58. #endif
  59. #ifdef __cplusplus
  60. }
  61. #endif
  62. #endif /* !Py_MEMORYOBJECT_H */