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