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 | PyAPI_FUNC(PyObject *) PyMemoryView_FromMemory(char *mem, Py_ssize_t size, |
25 | int flags); |
26 | #ifndef Py_LIMITED_API |
27 | PyAPI_FUNC(PyObject *) PyMemoryView_FromBuffer(Py_buffer *info); |
28 | #endif |
29 | PyAPI_FUNC(PyObject *) PyMemoryView_GetContiguous(PyObject *base, |
30 | int buffertype, |
31 | char order); |
32 | |
33 | |
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 |
36 | and functions instead! */ |
37 | #ifndef Py_LIMITED_API |
38 | #define _Py_MANAGED_BUFFER_RELEASED 0x001 /* access to exporter blocked */ |
39 | #define _Py_MANAGED_BUFFER_FREE_FORMAT 0x002 /* free format */ |
40 | typedef struct { |
41 | PyObject_HEAD |
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 | /* memoryview state flags */ |
49 | #define _Py_MEMORYVIEW_RELEASED 0x001 /* access to master buffer blocked */ |
50 | #define _Py_MEMORYVIEW_C 0x002 /* C-contiguous layout */ |
51 | #define _Py_MEMORYVIEW_FORTRAN 0x004 /* Fortran contiguous layout */ |
52 | #define _Py_MEMORYVIEW_SCALAR 0x008 /* scalar: ndim = 0 */ |
53 | #define _Py_MEMORYVIEW_PIL 0x010 /* PIL-style layout */ |
54 | |
55 | typedef struct { |
56 | PyObject_VAR_HEAD |
57 | _PyManagedBufferObject *mbuf; /* managed buffer */ |
58 | Py_hash_t hash; /* hash value for read-only views */ |
59 | int flags; /* state flags */ |
60 | Py_ssize_t exports; /* number of buffer re-exports */ |
61 | Py_buffer view; /* private copy of the exporter's view */ |
62 | PyObject *weakreflist; |
63 | Py_ssize_t ob_array[1]; /* shape, strides, suboffsets */ |
64 | } PyMemoryViewObject; |
65 | #endif |
66 | |
67 | #ifdef __cplusplus |
68 | } |
69 | #endif |
70 | #endif /* !Py_MEMORYOBJECT_H */ |
71 | |