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 | |
Dong-hee Na | d905df7 | 2020-02-14 02:37:17 +0900 | [diff] [blame] | 14 | #define PyMemoryView_Check(op) Py_IS_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); |
Serhiy Storchaka | 34d0ac8 | 2016-12-27 14:57:39 +0200 | [diff] [blame] | 24 | #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000 |
Stefan Krah | 9a2d99e | 2012-02-25 12:24:21 +0100 | [diff] [blame] | 25 | PyAPI_FUNC(PyObject *) PyMemoryView_FromMemory(char *mem, Py_ssize_t size, |
| 26 | int flags); |
Serhiy Storchaka | 34d0ac8 | 2016-12-27 14:57:39 +0200 | [diff] [blame] | 27 | #endif |
Martin v. Löwis | c83bc3c | 2011-01-06 19:15:47 +0000 | [diff] [blame] | 28 | #ifndef Py_LIMITED_API |
Antoine Pitrou | ee58fa4 | 2008-08-19 18:22:14 +0000 | [diff] [blame] | 29 | PyAPI_FUNC(PyObject *) PyMemoryView_FromBuffer(Py_buffer *info); |
Martin v. Löwis | c83bc3c | 2011-01-06 19:15:47 +0000 | [diff] [blame] | 30 | #endif |
Stefan Krah | 9a2d99e | 2012-02-25 12:24:21 +0100 | [diff] [blame] | 31 | PyAPI_FUNC(PyObject *) PyMemoryView_GetContiguous(PyObject *base, |
| 32 | int buffertype, |
| 33 | char order); |
Travis E. Oliphant | b99f762 | 2007-08-18 11:21:56 +0000 | [diff] [blame] | 34 | |
Antoine Pitrou | 35b7e83 | 2009-01-03 19:20:36 +0000 | [diff] [blame] | 35 | |
Stefan Krah | 9a2d99e | 2012-02-25 12:24:21 +0100 | [diff] [blame] | 36 | /* The structs are declared here so that macros can work, but they shouldn't |
| 37 | be considered public. Don't access their fields directly, use the macros |
Antoine Pitrou | ee58fa4 | 2008-08-19 18:22:14 +0000 | [diff] [blame] | 38 | and functions instead! */ |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 39 | #ifndef Py_LIMITED_API |
Stefan Krah | 9a2d99e | 2012-02-25 12:24:21 +0100 | [diff] [blame] | 40 | #define _Py_MANAGED_BUFFER_RELEASED 0x001 /* access to exporter blocked */ |
| 41 | #define _Py_MANAGED_BUFFER_FREE_FORMAT 0x002 /* free format */ |
Antoine Pitrou | ee58fa4 | 2008-08-19 18:22:14 +0000 | [diff] [blame] | 42 | typedef struct { |
Antoine Pitrou | 35b7e83 | 2009-01-03 19:20:36 +0000 | [diff] [blame] | 43 | PyObject_HEAD |
Stefan Krah | 9a2d99e | 2012-02-25 12:24:21 +0100 | [diff] [blame] | 44 | int flags; /* state flags */ |
| 45 | Py_ssize_t exports; /* number of direct memoryview exports */ |
| 46 | Py_buffer master; /* snapshot buffer obtained from the original exporter */ |
| 47 | } _PyManagedBufferObject; |
| 48 | |
| 49 | |
Stefan Krah | 9a2d99e | 2012-02-25 12:24:21 +0100 | [diff] [blame] | 50 | /* memoryview state flags */ |
| 51 | #define _Py_MEMORYVIEW_RELEASED 0x001 /* access to master buffer blocked */ |
| 52 | #define _Py_MEMORYVIEW_C 0x002 /* C-contiguous layout */ |
| 53 | #define _Py_MEMORYVIEW_FORTRAN 0x004 /* Fortran contiguous layout */ |
| 54 | #define _Py_MEMORYVIEW_SCALAR 0x008 /* scalar: ndim = 0 */ |
| 55 | #define _Py_MEMORYVIEW_PIL 0x010 /* PIL-style layout */ |
| 56 | |
| 57 | typedef struct { |
| 58 | PyObject_VAR_HEAD |
| 59 | _PyManagedBufferObject *mbuf; /* managed buffer */ |
| 60 | Py_hash_t hash; /* hash value for read-only views */ |
| 61 | int flags; /* state flags */ |
| 62 | Py_ssize_t exports; /* number of buffer re-exports */ |
| 63 | Py_buffer view; /* private copy of the exporter's view */ |
Richard Oudkerk | 3e0a1eb | 2012-05-28 21:35:09 +0100 | [diff] [blame] | 64 | PyObject *weakreflist; |
Stefan Krah | 9a2d99e | 2012-02-25 12:24:21 +0100 | [diff] [blame] | 65 | Py_ssize_t ob_array[1]; /* shape, strides, suboffsets */ |
Antoine Pitrou | ee58fa4 | 2008-08-19 18:22:14 +0000 | [diff] [blame] | 66 | } PyMemoryViewObject; |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 67 | #endif |
Antoine Pitrou | ee58fa4 | 2008-08-19 18:22:14 +0000 | [diff] [blame] | 68 | |
Travis E. Oliphant | b99f762 | 2007-08-18 11:21:56 +0000 | [diff] [blame] | 69 | #ifdef __cplusplus |
| 70 | } |
| 71 | #endif |
| 72 | #endif /* !Py_MEMORYOBJECT_H */ |