memoryobject.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #ifndef Py_CPYTHON_MEMORYOBJECT_H
  2. # error "this header file must not be included directly"
  3. #endif
  4. PyAPI_DATA(PyTypeObject) _PyManagedBuffer_Type;
  5. /* The structs are declared here so that macros can work, but they shouldn't
  6. be considered public. Don't access their fields directly, use the macros
  7. and functions instead! */
  8. #define _Py_MANAGED_BUFFER_RELEASED 0x001 /* access to exporter blocked */
  9. #define _Py_MANAGED_BUFFER_FREE_FORMAT 0x002 /* free format */
  10. typedef struct {
  11. PyObject_HEAD
  12. int flags; /* state flags */
  13. Py_ssize_t exports; /* number of direct memoryview exports */
  14. Py_buffer master; /* snapshot buffer obtained from the original exporter */
  15. } _PyManagedBufferObject;
  16. /* memoryview state flags */
  17. #define _Py_MEMORYVIEW_RELEASED 0x001 /* access to master buffer blocked */
  18. #define _Py_MEMORYVIEW_C 0x002 /* C-contiguous layout */
  19. #define _Py_MEMORYVIEW_FORTRAN 0x004 /* Fortran contiguous layout */
  20. #define _Py_MEMORYVIEW_SCALAR 0x008 /* scalar: ndim = 0 */
  21. #define _Py_MEMORYVIEW_PIL 0x010 /* PIL-style layout */
  22. #define _Py_MEMORYVIEW_RESTRICTED 0x020 /* Disallow new references to the memoryview's buffer */
  23. typedef struct {
  24. PyObject_VAR_HEAD
  25. _PyManagedBufferObject *mbuf; /* managed buffer */
  26. Py_hash_t hash; /* hash value for read-only views */
  27. int flags; /* state flags */
  28. Py_ssize_t exports; /* number of buffer re-exports */
  29. Py_buffer view; /* private copy of the exporter's view */
  30. PyObject *weakreflist;
  31. Py_ssize_t ob_array[1]; /* shape, strides, suboffsets */
  32. } PyMemoryViewObject;
  33. #define _PyMemoryView_CAST(op) _Py_CAST(PyMemoryViewObject*, op)
  34. /* Get a pointer to the memoryview's private copy of the exporter's buffer. */
  35. static inline Py_buffer* PyMemoryView_GET_BUFFER(PyObject *op) {
  36. return (&_PyMemoryView_CAST(op)->view);
  37. }
  38. #define PyMemoryView_GET_BUFFER(op) PyMemoryView_GET_BUFFER(_PyObject_CAST(op))
  39. /* Get a pointer to the exporting object (this may be NULL!). */
  40. static inline PyObject* PyMemoryView_GET_BASE(PyObject *op) {
  41. return _PyMemoryView_CAST(op)->view.obj;
  42. }
  43. #define PyMemoryView_GET_BASE(op) PyMemoryView_GET_BASE(_PyObject_CAST(op))