]>
Commit | Line | Data |
---|---|---|
c8042e10 DM |
1 | /* Memory view object. In Python this is available as "memoryview". */\r |
2 | \r | |
3 | #ifndef Py_MEMORYOBJECT_H\r | |
4 | #define Py_MEMORYOBJECT_H\r | |
5 | #ifdef __cplusplus\r | |
6 | extern "C" {\r | |
7 | #endif\r | |
8 | \r | |
9 | PyAPI_DATA(PyTypeObject) PyMemoryView_Type;\r | |
10 | \r | |
11 | #define PyMemoryView_Check(op) (Py_TYPE(op) == &PyMemoryView_Type)\r | |
12 | \r | |
13 | /* Get a pointer to the underlying Py_buffer of a memoryview object. */\r | |
14 | #define PyMemoryView_GET_BUFFER(op) (&((PyMemoryViewObject *)(op))->view)\r | |
15 | /* Get a pointer to the PyObject from which originates a memoryview object. */\r | |
16 | #define PyMemoryView_GET_BASE(op) (((PyMemoryViewObject *)(op))->view.obj)\r | |
17 | \r | |
18 | \r | |
19 | PyAPI_FUNC(PyObject *) PyMemoryView_GetContiguous(PyObject *base, \r | |
20 | int buffertype, \r | |
21 | char fort);\r | |
22 | \r | |
23 | /* Return a contiguous chunk of memory representing the buffer\r | |
24 | from an object in a memory view object. If a copy is made then the\r | |
25 | base object for the memory view will be a *new* bytes object. \r | |
26 | \r | |
27 | Otherwise, the base-object will be the object itself and no \r | |
28 | data-copying will be done. \r | |
29 | \r | |
30 | The buffertype argument can be PyBUF_READ, PyBUF_WRITE,\r | |
31 | PyBUF_SHADOW to determine whether the returned buffer\r | |
32 | should be READONLY, WRITABLE, or set to update the\r | |
33 | original buffer if a copy must be made. If buffertype is\r | |
34 | PyBUF_WRITE and the buffer is not contiguous an error will\r | |
35 | be raised. In this circumstance, the user can use\r | |
36 | PyBUF_SHADOW to ensure that a a writable temporary\r | |
37 | contiguous buffer is returned. The contents of this\r | |
38 | contiguous buffer will be copied back into the original\r | |
39 | object after the memoryview object is deleted as long as\r | |
40 | the original object is writable and allows setting an\r | |
41 | exclusive write lock. If this is not allowed by the\r | |
42 | original object, then a BufferError is raised.\r | |
43 | \r | |
44 | If the object is multi-dimensional and if fortran is 'F',\r | |
45 | the first dimension of the underlying array will vary the\r | |
46 | fastest in the buffer. If fortran is 'C', then the last\r | |
47 | dimension will vary the fastest (C-style contiguous). If\r | |
48 | fortran is 'A', then it does not matter and you will get\r | |
49 | whatever the object decides is more efficient. \r | |
50 | \r | |
51 | A new reference is returned that must be DECREF'd when finished.\r | |
52 | */\r | |
53 | \r | |
54 | PyAPI_FUNC(PyObject *) PyMemoryView_FromObject(PyObject *base);\r | |
55 | \r | |
56 | PyAPI_FUNC(PyObject *) PyMemoryView_FromBuffer(Py_buffer *info);\r | |
57 | /* create new if bufptr is NULL \r | |
58 | will be a new bytesobject in base */\r | |
59 | \r | |
60 | \r | |
61 | /* The struct is declared here so that macros can work, but it shouldn't\r | |
62 | be considered public. Don't access those fields directly, use the macros\r | |
63 | and functions instead! */\r | |
64 | typedef struct {\r | |
65 | PyObject_HEAD\r | |
66 | PyObject *base;\r | |
67 | Py_buffer view;\r | |
68 | } PyMemoryViewObject;\r | |
69 | \r | |
70 | \r | |
71 | #ifdef __cplusplus\r | |
72 | }\r | |
73 | #endif\r | |
74 | #endif /* !Py_MEMORYOBJECT_H */\r |