diff -r 3a21d223dc91 Include/memoryobject.h --- a/Include/memoryobject.h Fri Aug 15 20:43:03 2008 +0200 +++ b/Include/memoryobject.h Fri Aug 15 22:15:05 2008 +0200 @@ -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" { 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) -#define Py_END_OF_MEMORY (-1) +/* 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) + PyAPI_FUNC(PyObject *) PyMemoryView_GetContiguous(PyObject *base, int buffertype, @@ -58,9 +53,20 @@ PyAPI_FUNC(PyObject *) PyMemoryView_GetC 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 } diff -r 3a21d223dc91 Modules/_json.c --- a/Modules/_json.c Fri Aug 15 20:43:03 2008 +0200 +++ b/Modules/_json.c Fri Aug 15 22:15:05 2008 +0200 @@ -264,7 +264,7 @@ scanstring_str(PyObject *pystr, Py_ssize if (PyBuffer_FillInfo(&info, NULL, &buf[end], next - end, 1, 0) < 0) { goto bail; } - strchunk = PyMemoryView_FromMemory(&info); + strchunk = PyMemoryView_FromBuffer(&info); if (strchunk == NULL) { goto bail; } diff -r 3a21d223dc91 Objects/memoryobject.c --- a/Objects/memoryobject.c Fri Aug 15 20:43:03 2008 +0200 +++ b/Objects/memoryobject.c Fri Aug 15 22:15:05 2008 +0200 @@ -29,7 +29,7 @@ Create a new memoryview object which ref Create a new memoryview object which references the given object."); PyObject * -PyMemoryView_FromMemory(Py_buffer *info) +PyMemoryView_FromBuffer(Py_buffer *info) { PyMemoryViewObject *mview; @@ -231,7 +231,7 @@ PyMemoryView_GetContiguous(PyObject *obj mem = PyObject_New(PyMemoryViewObject, &PyMemoryView_Type); if (mem == NULL) return NULL; - view = &PyMemoryView(mem); + view = &mem->view; flags = PyBUF_FULL_RO; switch(buffertype) { case PyBUF_WRITE: @@ -534,7 +534,7 @@ memory_subscript(PyMemoryViewObject *sel /* XXX: This needs to be fixed so it actually returns a sub-view */ - return PyMemoryView_FromMemory(&newview); + return PyMemoryView_FromBuffer(&newview); } } diff -r 3a21d223dc91 Objects/unicodeobject.c --- a/Objects/unicodeobject.c Fri Aug 15 20:43:03 2008 +0200 +++ b/Objects/unicodeobject.c Fri Aug 15 22:15:05 2008 +0200 @@ -1200,7 +1200,7 @@ PyObject *PyUnicode_Decode(const char *s buffer = NULL; if (PyBuffer_FillInfo(&info, NULL, (void *)s, size, 1, PyBUF_SIMPLE) < 0) goto onError; - buffer = PyMemoryView_FromMemory(&info); + buffer = PyMemoryView_FromBuffer(&info); if (buffer == NULL) goto onError; unicode = PyCodec_Decode(buffer, encoding, errors);