summaryrefslogtreecommitdiffstats
path: root/Objects/memoryobject.c
diff options
context:
space:
mode:
authorTravis E. Oliphant <oliphant@enthought.com>2007-10-12 23:27:53 (GMT)
committerTravis E. Oliphant <oliphant@enthought.com>2007-10-12 23:27:53 (GMT)
commitfe9bed02e430613f95849fa49aaa4f823a762738 (patch)
treef26a61380fcfda85caaaf70f55e74c75c5a0b90f /Objects/memoryobject.c
parent9b30784ab2867bcb7335add7306bbd71e2de2151 (diff)
downloadcpython-fe9bed02e430613f95849fa49aaa4f823a762738.zip
cpython-fe9bed02e430613f95849fa49aaa4f823a762738.tar.gz
cpython-fe9bed02e430613f95849fa49aaa4f823a762738.tar.bz2
Fix problems with memoryview object. There is still more to do to finish PEP 3118. The memory-view object needs to be fleshed out and the struct module needs to be modified.
Diffstat (limited to 'Objects/memoryobject.c')
-rw-r--r--Objects/memoryobject.c26
1 files changed, 19 insertions, 7 deletions
diff --git a/Objects/memoryobject.c b/Objects/memoryobject.c
index f2f7505..02f21ce 100644
--- a/Objects/memoryobject.c
+++ b/Objects/memoryobject.c
@@ -196,7 +196,9 @@ _indirect_copy_nd(char *dest, Py_buffer *view, char fort)
a contiguous buffer if it is not. The view will point to
the shadow buffer which can be written to and then
will be copied back into the other buffer when the memory
- view is de-allocated.
+ view is de-allocated. While the shadow buffer is
+ being used, it will have an exclusive write lock on
+ the original buffer.
*/
PyObject *
@@ -224,7 +226,7 @@ PyMemoryView_GetContiguous(PyObject *obj, int buffertype, char fort)
flags = PyBUF_FULL;
break;
case PyBUF_SHADOW:
- flags = PyBUF_FULL_LCK;
+ flags = PyBUF_FULL_XLCK;
break;
}
@@ -431,11 +433,7 @@ memory_dealloc(PyMemoryViewObject *self)
static PyObject *
memory_repr(PyMemoryViewObject *self)
{
- /* XXX(nnorwitz): the code should be different or remove condition. */
- if (self->base == NULL)
- return PyUnicode_FromFormat("<memory at %p>", self);
- else
- return PyUnicode_FromFormat("<memory at %p>", self);
+ return PyUnicode_FromFormat("<memory at %p>", self);
}
@@ -502,6 +500,14 @@ memory_subscript(PyMemoryViewObject *self, PyObject *key)
/* Return a bytes object */
char *ptr;
ptr = (char *)view->buf;
+ if (result < 0) {
+ result += view->shape[0];
+ }
+ if ((result < 0) || (result > view->shape[0])) {
+ PyErr_SetString(PyExc_IndexError,
+ "index out of bounds");
+ return NULL;
+ }
if (view->strides == NULL)
ptr += view->itemsize * result;
else
@@ -517,14 +523,20 @@ memory_subscript(PyMemoryViewObject *self, PyObject *key)
/* Return a new memory-view object */
Py_buffer newview;
memset(&newview, 0, sizeof(newview));
+ /* XXX: This needs to be fixed so it
+ actually returns a sub-view
+ */
return PyMemoryView_FromMemory(&newview);
}
}
+ /* Need to support getting a sliced view */
Py_INCREF(Py_NotImplemented);
return Py_NotImplemented;
}
+
+/* Need to support assigning memory if we can */
static int
memory_ass_sub(PyMemoryViewObject *self, PyObject *key, PyObject *value)
{