memoryobject.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. #ifndef Py_LIMITED_API
  8. PyAPI_DATA(PyTypeObject) _PyManagedBuffer_Type;
  9. #endif
  10. PyAPI_DATA(PyTypeObject) PyMemoryView_Type;
  11. #define PyMemoryView_Check(op) Py_IS_TYPE(op, &PyMemoryView_Type)
  12. #ifndef Py_LIMITED_API
  13. /* Get a pointer to the memoryview's private copy of the exporter's buffer. */
  14. #define PyMemoryView_GET_BUFFER(op) (&((PyMemoryViewObject *)(op))->view)
  15. /* Get a pointer to the exporting object (this may be NULL!). */
  16. #define PyMemoryView_GET_BASE(op) (((PyMemoryViewObject *)(op))->view.obj)
  17. #endif
  18. PyAPI_FUNC(PyObject *) PyMemoryView_FromObject(PyObject *base);
  19. #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000
  20. PyAPI_FUNC(PyObject *) PyMemoryView_FromMemory(char *mem, Py_ssize_t size,
  21. int flags);
  22. #endif
  23. #ifndef Py_LIMITED_API
  24. PyAPI_FUNC(PyObject *) PyMemoryView_FromBuffer(Py_buffer *info);
  25. #endif
  26. PyAPI_FUNC(PyObject *) PyMemoryView_GetContiguous(PyObject *base,
  27. int buffertype,
  28. char order);
  29. /* The structs are declared here so that macros can work, but they shouldn't
  30. be considered public. Don't access their fields directly, use the macros
  31. and functions instead! */
  32. #ifndef Py_LIMITED_API
  33. #define _Py_MANAGED_BUFFER_RELEASED 0x001 /* access to exporter blocked */
  34. #define _Py_MANAGED_BUFFER_FREE_FORMAT 0x002 /* free format */
  35. typedef struct {
  36. PyObject_HEAD
  37. int flags; /* state flags */
  38. Py_ssize_t exports; /* number of direct memoryview exports */
  39. Py_buffer master; /* snapshot buffer obtained from the original exporter */
  40. } _PyManagedBufferObject;
  41. /* memoryview state flags */
  42. #define _Py_MEMORYVIEW_RELEASED 0x001 /* access to master buffer blocked */
  43. #define _Py_MEMORYVIEW_C 0x002 /* C-contiguous layout */
  44. #define _Py_MEMORYVIEW_FORTRAN 0x004 /* Fortran contiguous layout */
  45. #define _Py_MEMORYVIEW_SCALAR 0x008 /* scalar: ndim = 0 */
  46. #define _Py_MEMORYVIEW_PIL 0x010 /* PIL-style layout */
  47. typedef struct {
  48. PyObject_VAR_HEAD
  49. _PyManagedBufferObject *mbuf; /* managed buffer */
  50. Py_hash_t hash; /* hash value for read-only views */
  51. int flags; /* state flags */
  52. Py_ssize_t exports; /* number of buffer re-exports */
  53. Py_buffer view; /* private copy of the exporter's view */
  54. PyObject *weakreflist;
  55. Py_ssize_t ob_array[1]; /* shape, strides, suboffsets */
  56. } PyMemoryViewObject;
  57. #endif
  58. #ifdef __cplusplus
  59. }
  60. #endif
  61. #endif /* !Py_MEMORYOBJECT_H */