blob: 1713e8f81cb669bcb563281c31af1b0cf3ae662c [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 {
11 PyObject_HEAD
12 PyObject *base;
13 PyBuffer view;
14} PyMemoryViewObject;
15
16
17PyAPI_DATA(PyTypeObject) PyMemoryView_Type;
18
19#define PyMemory_Check(op) (Py_Type(op) == &PyMemoryView_Type)
20#define PyMemoryView(op) (((PyMemoryViewObject *)(op))->view)
21
22#define Py_END_OF_MEMORY (-1)
23
24PyAPI_FUNC(PyObject *) PyMemoryView_GetContiguous(PyObject *base, int buffertype,
25 char fort);
26
27 /* Return a contiguous chunk of memory representing the buffer
28 from an object in a memory view object. If a copy is made then the
29 base object for the memory view will be a *new* bytes object.
30
31 Otherwise, the base-object will be the object itself and no
32 data-copying will be done.
33
34 The buffertype argument can be PyBUF_READ, PyBUF_WRITE,
35 PyBUF_UPDATEIFCOPY to determine whether the returned buffer
Sean Reifscheider54cf12b2007-09-17 17:55:36 +000036 should be READONLY, WRITABLE, or set to update the
Travis E. Oliphantb99f7622007-08-18 11:21:56 +000037 original buffer if a copy must be made. If buffertype is
38 PyBUF_WRITE and the buffer is not contiguous an error will
39 be raised. In this circumstance, the user can use
Sean Reifscheider54cf12b2007-09-17 17:55:36 +000040 PyBUF_UPDATEIFCOPY to ensure that a a writable temporary
Travis E. Oliphantb99f7622007-08-18 11:21:56 +000041 contiguous buffer is returned. The contents of this
42 contiguous buffer will be copied back into the original
43 object after the memoryview object is deleted as long as
Sean Reifscheider54cf12b2007-09-17 17:55:36 +000044 the original object is writable and allows setting its
Travis E. Oliphantb99f7622007-08-18 11:21:56 +000045 memory to "readonly". If this is not allowed by the
46 original object, then a BufferError is raised.
47
48 If the object is multi-dimensional and if fortran is 'F',
49 the first dimension of the underlying array will vary the
50 fastest in the buffer. If fortran is 'C', then the last
51 dimension will vary the fastest (C-style contiguous). If
52 fortran is 'A', then it does not matter and you will get
53 whatever the object decides is more efficient.
54
55 A new reference is returned that must be DECREF'd when finished.
56 */
57
58PyAPI_FUNC(PyObject *) PyMemoryView_FromObject(PyObject *base);
59
60PyAPI_FUNC(PyObject *) PyMemoryView_FromMemory(PyBuffer *info);
61 /* create new if bufptr is NULL
62 will be a new bytesobject in base */
63
64#ifdef __cplusplus
65}
66#endif
67#endif /* !Py_MEMORYOBJECT_H */