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