jpayne@69: /* Memory view object. In Python this is available as "memoryview". */ jpayne@69: jpayne@69: #ifndef Py_MEMORYOBJECT_H jpayne@69: #define Py_MEMORYOBJECT_H jpayne@69: #ifdef __cplusplus jpayne@69: extern "C" { jpayne@69: #endif jpayne@69: jpayne@69: #ifndef Py_LIMITED_API jpayne@69: PyAPI_DATA(PyTypeObject) _PyManagedBuffer_Type; jpayne@69: #endif jpayne@69: PyAPI_DATA(PyTypeObject) PyMemoryView_Type; jpayne@69: jpayne@69: #define PyMemoryView_Check(op) (Py_TYPE(op) == &PyMemoryView_Type) jpayne@69: jpayne@69: #ifndef Py_LIMITED_API jpayne@69: /* Get a pointer to the memoryview's private copy of the exporter's buffer. */ jpayne@69: #define PyMemoryView_GET_BUFFER(op) (&((PyMemoryViewObject *)(op))->view) jpayne@69: /* Get a pointer to the exporting object (this may be NULL!). */ jpayne@69: #define PyMemoryView_GET_BASE(op) (((PyMemoryViewObject *)(op))->view.obj) jpayne@69: #endif jpayne@69: jpayne@69: PyAPI_FUNC(PyObject *) PyMemoryView_FromObject(PyObject *base); jpayne@69: #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000 jpayne@69: PyAPI_FUNC(PyObject *) PyMemoryView_FromMemory(char *mem, Py_ssize_t size, jpayne@69: int flags); jpayne@69: #endif jpayne@69: #ifndef Py_LIMITED_API jpayne@69: PyAPI_FUNC(PyObject *) PyMemoryView_FromBuffer(Py_buffer *info); jpayne@69: #endif jpayne@69: PyAPI_FUNC(PyObject *) PyMemoryView_GetContiguous(PyObject *base, jpayne@69: int buffertype, jpayne@69: char order); jpayne@69: jpayne@69: jpayne@69: /* The structs are declared here so that macros can work, but they shouldn't jpayne@69: be considered public. Don't access their fields directly, use the macros jpayne@69: and functions instead! */ jpayne@69: #ifndef Py_LIMITED_API jpayne@69: #define _Py_MANAGED_BUFFER_RELEASED 0x001 /* access to exporter blocked */ jpayne@69: #define _Py_MANAGED_BUFFER_FREE_FORMAT 0x002 /* free format */ jpayne@69: typedef struct { jpayne@69: PyObject_HEAD jpayne@69: int flags; /* state flags */ jpayne@69: Py_ssize_t exports; /* number of direct memoryview exports */ jpayne@69: Py_buffer master; /* snapshot buffer obtained from the original exporter */ jpayne@69: } _PyManagedBufferObject; jpayne@69: jpayne@69: jpayne@69: /* memoryview state flags */ jpayne@69: #define _Py_MEMORYVIEW_RELEASED 0x001 /* access to master buffer blocked */ jpayne@69: #define _Py_MEMORYVIEW_C 0x002 /* C-contiguous layout */ jpayne@69: #define _Py_MEMORYVIEW_FORTRAN 0x004 /* Fortran contiguous layout */ jpayne@69: #define _Py_MEMORYVIEW_SCALAR 0x008 /* scalar: ndim = 0 */ jpayne@69: #define _Py_MEMORYVIEW_PIL 0x010 /* PIL-style layout */ jpayne@69: jpayne@69: typedef struct { jpayne@69: PyObject_VAR_HEAD jpayne@69: _PyManagedBufferObject *mbuf; /* managed buffer */ jpayne@69: Py_hash_t hash; /* hash value for read-only views */ jpayne@69: int flags; /* state flags */ jpayne@69: Py_ssize_t exports; /* number of buffer re-exports */ jpayne@69: Py_buffer view; /* private copy of the exporter's view */ jpayne@69: PyObject *weakreflist; jpayne@69: Py_ssize_t ob_array[1]; /* shape, strides, suboffsets */ jpayne@69: } PyMemoryViewObject; jpayne@69: #endif jpayne@69: jpayne@69: #ifdef __cplusplus jpayne@69: } jpayne@69: #endif jpayne@69: #endif /* !Py_MEMORYOBJECT_H */