Chris@87: /* Memory view object. In Python this is available as "memoryview". */ Chris@87: Chris@87: #ifndef Py_MEMORYOBJECT_H Chris@87: #define Py_MEMORYOBJECT_H Chris@87: #ifdef __cplusplus Chris@87: extern "C" { Chris@87: #endif Chris@87: Chris@87: PyAPI_DATA(PyTypeObject) PyMemoryView_Type; Chris@87: Chris@87: #define PyMemoryView_Check(op) (Py_TYPE(op) == &PyMemoryView_Type) Chris@87: Chris@87: /* Get a pointer to the underlying Py_buffer of a memoryview object. */ Chris@87: #define PyMemoryView_GET_BUFFER(op) (&((PyMemoryViewObject *)(op))->view) Chris@87: /* Get a pointer to the PyObject from which originates a memoryview object. */ Chris@87: #define PyMemoryView_GET_BASE(op) (((PyMemoryViewObject *)(op))->view.obj) Chris@87: Chris@87: Chris@87: PyAPI_FUNC(PyObject *) PyMemoryView_GetContiguous(PyObject *base, Chris@87: int buffertype, Chris@87: char fort); Chris@87: Chris@87: /* Return a contiguous chunk of memory representing the buffer Chris@87: from an object in a memory view object. If a copy is made then the Chris@87: base object for the memory view will be a *new* bytes object. Chris@87: Chris@87: Otherwise, the base-object will be the object itself and no Chris@87: data-copying will be done. Chris@87: Chris@87: The buffertype argument can be PyBUF_READ, PyBUF_WRITE, Chris@87: PyBUF_SHADOW to determine whether the returned buffer Chris@87: should be READONLY, WRITABLE, or set to update the Chris@87: original buffer if a copy must be made. If buffertype is Chris@87: PyBUF_WRITE and the buffer is not contiguous an error will Chris@87: be raised. In this circumstance, the user can use Chris@87: PyBUF_SHADOW to ensure that a a writable temporary Chris@87: contiguous buffer is returned. The contents of this Chris@87: contiguous buffer will be copied back into the original Chris@87: object after the memoryview object is deleted as long as Chris@87: the original object is writable and allows setting an Chris@87: exclusive write lock. If this is not allowed by the Chris@87: original object, then a BufferError is raised. Chris@87: Chris@87: If the object is multi-dimensional and if fortran is 'F', Chris@87: the first dimension of the underlying array will vary the Chris@87: fastest in the buffer. If fortran is 'C', then the last Chris@87: dimension will vary the fastest (C-style contiguous). If Chris@87: fortran is 'A', then it does not matter and you will get Chris@87: whatever the object decides is more efficient. Chris@87: Chris@87: A new reference is returned that must be DECREF'd when finished. Chris@87: */ Chris@87: Chris@87: PyAPI_FUNC(PyObject *) PyMemoryView_FromObject(PyObject *base); Chris@87: Chris@87: PyAPI_FUNC(PyObject *) PyMemoryView_FromBuffer(Py_buffer *info); Chris@87: /* create new if bufptr is NULL Chris@87: will be a new bytesobject in base */ Chris@87: Chris@87: Chris@87: /* The struct is declared here so that macros can work, but it shouldn't Chris@87: be considered public. Don't access those fields directly, use the macros Chris@87: and functions instead! */ Chris@87: typedef struct { Chris@87: PyObject_HEAD Chris@87: PyObject *base; Chris@87: Py_buffer view; Chris@87: } PyMemoryViewObject; Chris@87: Chris@87: Chris@87: #ifdef __cplusplus Chris@87: } Chris@87: #endif Chris@87: #endif /* !Py_MEMORYOBJECT_H */