Antoine Pitrou | ee58fa4 | 2008-08-19 18:22:14 +0000 | [diff] [blame] | 1 | /* Memory view object. In Python this is available as "memoryview". */ |
Travis E. Oliphant | b99f762 | 2007-08-18 11:21:56 +0000 | [diff] [blame] | 2 | |
| 3 | #ifndef Py_MEMORYOBJECT_H |
| 4 | #define Py_MEMORYOBJECT_H |
| 5 | #ifdef __cplusplus |
| 6 | extern "C" { |
| 7 | #endif |
| 8 | |
Stefan Krah | 9a2d99e | 2012-02-25 12:24:21 +0100 | [diff] [blame] | 9 | #ifndef Py_LIMITED_API |
| 10 | PyAPI_DATA(PyTypeObject) _PyManagedBuffer_Type; |
| 11 | #endif |
Travis E. Oliphant | b99f762 | 2007-08-18 11:21:56 +0000 | [diff] [blame] | 12 | PyAPI_DATA(PyTypeObject) PyMemoryView_Type; |
| 13 | |
Antoine Pitrou | ee58fa4 | 2008-08-19 18:22:14 +0000 | [diff] [blame] | 14 | #define PyMemoryView_Check(op) (Py_TYPE(op) == &PyMemoryView_Type) |
Travis E. Oliphant | b99f762 | 2007-08-18 11:21:56 +0000 | [diff] [blame] | 15 | |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 16 | #ifndef Py_LIMITED_API |
Stefan Krah | 9a2d99e | 2012-02-25 12:24:21 +0100 | [diff] [blame] | 17 | /* Get a pointer to the memoryview's private copy of the exporter's buffer. */ |
Antoine Pitrou | ee58fa4 | 2008-08-19 18:22:14 +0000 | [diff] [blame] | 18 | #define PyMemoryView_GET_BUFFER(op) (&((PyMemoryViewObject *)(op))->view) |
Stefan Krah | 9a2d99e | 2012-02-25 12:24:21 +0100 | [diff] [blame] | 19 | /* Get a pointer to the exporting object (this may be NULL!). */ |
Antoine Pitrou | ee58fa4 | 2008-08-19 18:22:14 +0000 | [diff] [blame] | 20 | #define PyMemoryView_GET_BASE(op) (((PyMemoryViewObject *)(op))->view.obj) |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 21 | #endif |
Antoine Pitrou | ee58fa4 | 2008-08-19 18:22:14 +0000 | [diff] [blame] | 22 | |
Travis E. Oliphant | b99f762 | 2007-08-18 11:21:56 +0000 | [diff] [blame] | 23 | PyAPI_FUNC(PyObject *) PyMemoryView_FromObject(PyObject *base); |
Stefan Krah | 9a2d99e | 2012-02-25 12:24:21 +0100 | [diff] [blame] | 24 | PyAPI_FUNC(PyObject *) PyMemoryView_FromMemory(char *mem, Py_ssize_t size, |
| 25 | int flags); |
Martin v. Löwis | c83bc3c | 2011-01-06 19:15:47 +0000 | [diff] [blame] | 26 | #ifndef Py_LIMITED_API |
Antoine Pitrou | ee58fa4 | 2008-08-19 18:22:14 +0000 | [diff] [blame] | 27 | PyAPI_FUNC(PyObject *) PyMemoryView_FromBuffer(Py_buffer *info); |
Martin v. Löwis | c83bc3c | 2011-01-06 19:15:47 +0000 | [diff] [blame] | 28 | #endif |
Stefan Krah | 9a2d99e | 2012-02-25 12:24:21 +0100 | [diff] [blame] | 29 | PyAPI_FUNC(PyObject *) PyMemoryView_GetContiguous(PyObject *base, |
| 30 | int buffertype, |
| 31 | char order); |
Travis E. Oliphant | b99f762 | 2007-08-18 11:21:56 +0000 | [diff] [blame] | 32 | |
Antoine Pitrou | 35b7e83 | 2009-01-03 19:20:36 +0000 | [diff] [blame] | 33 | |
Stefan Krah | 9a2d99e | 2012-02-25 12:24:21 +0100 | [diff] [blame] | 34 | /* The structs are declared here so that macros can work, but they shouldn't |
| 35 | be considered public. Don't access their fields directly, use the macros |
Antoine Pitrou | ee58fa4 | 2008-08-19 18:22:14 +0000 | [diff] [blame] | 36 | and functions instead! */ |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 37 | #ifndef Py_LIMITED_API |
Stefan Krah | 9a2d99e | 2012-02-25 12:24:21 +0100 | [diff] [blame] | 38 | #define _Py_MANAGED_BUFFER_RELEASED 0x001 /* access to exporter blocked */ |
| 39 | #define _Py_MANAGED_BUFFER_FREE_FORMAT 0x002 /* free format */ |
Antoine Pitrou | ee58fa4 | 2008-08-19 18:22:14 +0000 | [diff] [blame] | 40 | typedef struct { |
Antoine Pitrou | 35b7e83 | 2009-01-03 19:20:36 +0000 | [diff] [blame] | 41 | PyObject_HEAD |
Stefan Krah | 9a2d99e | 2012-02-25 12:24:21 +0100 | [diff] [blame] | 42 | int flags; /* state flags */ |
| 43 | Py_ssize_t exports; /* number of direct memoryview exports */ |
| 44 | Py_buffer master; /* snapshot buffer obtained from the original exporter */ |
| 45 | } _PyManagedBufferObject; |
| 46 | |
| 47 | |
| 48 | /* static storage used for casting between formats */ |
| 49 | #define _Py_MEMORYVIEW_MAX_FORMAT 3 /* must be >= 3 */ |
| 50 | |
| 51 | /* memoryview state flags */ |
| 52 | #define _Py_MEMORYVIEW_RELEASED 0x001 /* access to master buffer blocked */ |
| 53 | #define _Py_MEMORYVIEW_C 0x002 /* C-contiguous layout */ |
| 54 | #define _Py_MEMORYVIEW_FORTRAN 0x004 /* Fortran contiguous layout */ |
| 55 | #define _Py_MEMORYVIEW_SCALAR 0x008 /* scalar: ndim = 0 */ |
| 56 | #define _Py_MEMORYVIEW_PIL 0x010 /* PIL-style layout */ |
| 57 | |
| 58 | typedef struct { |
| 59 | PyObject_VAR_HEAD |
| 60 | _PyManagedBufferObject *mbuf; /* managed buffer */ |
| 61 | Py_hash_t hash; /* hash value for read-only views */ |
| 62 | int flags; /* state flags */ |
| 63 | Py_ssize_t exports; /* number of buffer re-exports */ |
| 64 | Py_buffer view; /* private copy of the exporter's view */ |
| 65 | char format[_Py_MEMORYVIEW_MAX_FORMAT]; /* used for casting */ |
| 66 | Py_ssize_t ob_array[1]; /* shape, strides, suboffsets */ |
Antoine Pitrou | ee58fa4 | 2008-08-19 18:22:14 +0000 | [diff] [blame] | 67 | } PyMemoryViewObject; |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 68 | #endif |
Antoine Pitrou | ee58fa4 | 2008-08-19 18:22:14 +0000 | [diff] [blame] | 69 | |
Travis E. Oliphant | b99f762 | 2007-08-18 11:21:56 +0000 | [diff] [blame] | 70 | #ifdef __cplusplus |
| 71 | } |
| 72 | #endif |
| 73 | #endif /* !Py_MEMORYOBJECT_H */ |