blob: ad2e8e781f62c2ce418bfbd318115afed2db8d51 [file] [log] [blame]
Travis E. Oliphantb99f7622007-08-18 11:21:56 +00001
2/* Memory object interface */
3
4#ifndef Py_MEMORYOBJECT_H
5#define Py_MEMORYOBJECT_H
6#ifdef __cplusplus
7extern "C" {
8#endif
9
10typedef struct {
Travis E. Oliphantfe9bed02007-10-12 23:27:53 +000011 PyObject_HEAD
12 PyObject *base;
13 Py_buffer view;
Travis E. Oliphantb99f7622007-08-18 11:21:56 +000014} PyMemoryViewObject;
15
16
17PyAPI_DATA(PyTypeObject) PyMemoryView_Type;
18
Christian Heimes90aa7642007-12-19 02:45:37 +000019#define PyMemory_Check(op) (Py_TYPE(op) == &PyMemoryView_Type)
Travis E. Oliphantb99f7622007-08-18 11:21:56 +000020#define PyMemoryView(op) (((PyMemoryViewObject *)(op))->view)
21
22#define Py_END_OF_MEMORY (-1)
23
Travis E. Oliphantfe9bed02007-10-12 23:27:53 +000024PyAPI_FUNC(PyObject *) PyMemoryView_GetContiguous(PyObject *base,
25 int buffertype,
26 char fort);
Travis E. Oliphantb99f7622007-08-18 11:21:56 +000027
28 /* Return a contiguous chunk of memory representing the buffer
29 from an object in a memory view object. If a copy is made then the
Travis E. Oliphantfe9bed02007-10-12 23:27:53 +000030 base object for the memory view will be a *new* bytes object.
Travis E. Oliphantb99f7622007-08-18 11:21:56 +000031
Travis E. Oliphantfe9bed02007-10-12 23:27:53 +000032 Otherwise, the base-object will be the object itself and no
33 data-copying will be done.
Travis E. Oliphantb99f7622007-08-18 11:21:56 +000034
Travis E. Oliphantfe9bed02007-10-12 23:27:53 +000035 The buffertype argument can be PyBUF_READ, PyBUF_WRITE,
36 PyBUF_SHADOW to determine whether the returned buffer
37 should be READONLY, WRITABLE, or set to update the
38 original buffer if a copy must be made. If buffertype is
39 PyBUF_WRITE and the buffer is not contiguous an error will
40 be raised. In this circumstance, the user can use
41 PyBUF_SHADOW to ensure that a a writable temporary
42 contiguous buffer is returned. The contents of this
43 contiguous buffer will be copied back into the original
44 object after the memoryview object is deleted as long as
45 the original object is writable and allows setting an
46 exclusive write lock. If this is not allowed by the
47 original object, then a BufferError is raised.
48
49 If the object is multi-dimensional and if fortran is 'F',
50 the first dimension of the underlying array will vary the
51 fastest in the buffer. If fortran is 'C', then the last
52 dimension will vary the fastest (C-style contiguous). If
53 fortran is 'A', then it does not matter and you will get
54 whatever the object decides is more efficient.
55
56 A new reference is returned that must be DECREF'd when finished.
57 */
Travis E. Oliphantb99f7622007-08-18 11:21:56 +000058
59PyAPI_FUNC(PyObject *) PyMemoryView_FromObject(PyObject *base);
60
Travis E. Oliphant8ae62b62007-09-23 02:00:13 +000061PyAPI_FUNC(PyObject *) PyMemoryView_FromMemory(Py_buffer *info);
Travis E. Oliphantb99f7622007-08-18 11:21:56 +000062 /* create new if bufptr is NULL
63 will be a new bytesobject in base */
64
65#ifdef __cplusplus
66}
67#endif
68#endif /* !Py_MEMORYOBJECT_H */