|
| 1 | +/* Memory view object. In Python this is available as "memoryview". */ |
| 2 | + |
| 3 | +#ifndef Py_MEMORYOBJECT_H |
| 4 | +#define Py_MEMORYOBJECT_H |
| 5 | +#ifdef __cplusplus |
| 6 | +extern "C" { |
| 7 | +#endif |
| 8 | + |
| 9 | +#ifndef Py_LIMITED_API |
| 10 | +PyAPI_DATA(PyTypeObject) _PyManagedBuffer_Type; |
| 11 | +#endif |
| 12 | +PyAPI_DATA(PyTypeObject) PyMemoryView_Type; |
| 13 | + |
| 14 | +#define PyMemoryView_Check(op) (Py_TYPE(op) == &PyMemoryView_Type) |
| 15 | + |
| 16 | +#ifndef Py_LIMITED_API |
| 17 | +/* Get a pointer to the memoryview's private copy of the exporter's buffer. */ |
| 18 | +#define PyMemoryView_GET_BUFFER(op) (&((PyMemoryViewObject *)(op))->view) |
| 19 | +/* Get a pointer to the exporting object (this may be NULL!). */ |
| 20 | +#define PyMemoryView_GET_BASE(op) (((PyMemoryViewObject *)(op))->view.obj) |
| 21 | +#endif |
| 22 | + |
| 23 | +PyAPI_FUNC(PyObject *) PyMemoryView_FromObject(PyObject *base); |
| 24 | +#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03030000 |
| 25 | +PyAPI_FUNC(PyObject *) PyMemoryView_FromMemory(char *mem, Py_ssize_t size, |
| 26 | + int flags); |
| 27 | +#endif |
| 28 | +#ifndef Py_LIMITED_API |
| 29 | +PyAPI_FUNC(PyObject *) PyMemoryView_FromBuffer(Py_buffer *info); |
| 30 | +#endif |
| 31 | +PyAPI_FUNC(PyObject *) PyMemoryView_GetContiguous(PyObject *base, |
| 32 | + int buffertype, |
| 33 | + char order); |
| 34 | + |
| 35 | + |
| 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 |
| 38 | + and functions instead! */ |
| 39 | +#ifndef Py_LIMITED_API |
| 40 | +#define _Py_MANAGED_BUFFER_RELEASED 0x001 /* access to exporter blocked */ |
| 41 | +#define _Py_MhANAGED_BUFFER_FREE_FORMAT 0x002 /* free format */ |
| 42 | +typedef struct { |
| 43 | + PyObject_HEAD |
| 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 | + |
| 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 */ |
| 64 | + PyObject *weakreflist; |
| 65 | + Py_ssize_t ob_array[1]; /* shape, strides, suboffsets */ |
| 66 | +} PyMemoryViewObject; |
| 67 | +#endif |
| 68 | + |
| 69 | +#ifdef __cplusplus |
| 70 | +} |
| 71 | +#endif |
| 72 | +#endif /* !Py_MEMORYOBJECT_H */ |
| 73 | + |
0 commit comments