diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2008-08-19 18:22:14 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2008-08-19 18:22:14 (GMT) |
commit | ee58fa484ed535ec6d7f2b93cb3ef2addeb337e1 (patch) | |
tree | 9398d06f962ab532ad8bc80407630069491c1871 /Include/memoryobject.h | |
parent | fd036451bf0e0ade8783e21df801abf7be96d020 (diff) | |
download | cpython-ee58fa484ed535ec6d7f2b93cb3ef2addeb337e1.zip cpython-ee58fa484ed535ec6d7f2b93cb3ef2addeb337e1.tar.gz cpython-ee58fa484ed535ec6d7f2b93cb3ef2addeb337e1.tar.bz2 |
#3560: cleanup C memoryview API
Diffstat (limited to 'Include/memoryobject.h')
-rw-r--r-- | Include/memoryobject.h | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/Include/memoryobject.h b/Include/memoryobject.h index ad2e8e7..3888259 100644 --- a/Include/memoryobject.h +++ b/Include/memoryobject.h @@ -1,5 +1,4 @@ - -/* Memory object interface */ +/* Memory view object. In Python this is available as "memoryview". */ #ifndef Py_MEMORYOBJECT_H #define Py_MEMORYOBJECT_H @@ -7,19 +6,15 @@ extern "C" { #endif -typedef struct { - PyObject_HEAD - PyObject *base; - Py_buffer view; -} PyMemoryViewObject; - - PyAPI_DATA(PyTypeObject) PyMemoryView_Type; -#define PyMemory_Check(op) (Py_TYPE(op) == &PyMemoryView_Type) -#define PyMemoryView(op) (((PyMemoryViewObject *)(op))->view) +#define PyMemoryView_Check(op) (Py_TYPE(op) == &PyMemoryView_Type) + +/* Get a pointer to the underlying Py_buffer of a memoryview object. */ +#define PyMemoryView_GET_BUFFER(op) (&((PyMemoryViewObject *)(op))->view) +/* Get a pointer to the PyObject from which originates a memoryview object. */ +#define PyMemoryView_GET_BASE(op) (((PyMemoryViewObject *)(op))->view.obj) -#define Py_END_OF_MEMORY (-1) PyAPI_FUNC(PyObject *) PyMemoryView_GetContiguous(PyObject *base, int buffertype, @@ -58,10 +53,21 @@ PyAPI_FUNC(PyObject *) PyMemoryView_GetContiguous(PyObject *base, PyAPI_FUNC(PyObject *) PyMemoryView_FromObject(PyObject *base); -PyAPI_FUNC(PyObject *) PyMemoryView_FromMemory(Py_buffer *info); +PyAPI_FUNC(PyObject *) PyMemoryView_FromBuffer(Py_buffer *info); /* create new if bufptr is NULL will be a new bytesobject in base */ + +/* The struct is declared here so that macros can work, but it shouldn't + be considered public. Don't access those fields directly, use the macros + and functions instead! */ +typedef struct { + PyObject_HEAD + PyObject *base; + Py_buffer view; +} PyMemoryViewObject; + + #ifdef __cplusplus } #endif |