summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1997-05-05 22:15:02 (GMT)
committerGuido van Rossum <guido@python.org>1997-05-05 22:15:02 (GMT)
commitfdf95dd525840559d77637802ff117969db19031 (patch)
treeac06e548154ef068d134401a08f66c17d681628b /Modules
parent8290e075096ac985c564b738a35307fac0992149 (diff)
downloadcpython-fdf95dd525840559d77637802ff117969db19031.zip
cpython-fdf95dd525840559d77637802ff117969db19031.tar.gz
cpython-fdf95dd525840559d77637802ff117969db19031.tar.bz2
Checkin of Jack's buffer mods.
Not really checked, but didn't fail any tests either...
Diffstat (limited to 'Modules')
-rw-r--r--Modules/arraymodule.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c
index e732f39..50cadd0 100644
--- a/Modules/arraymodule.c
+++ b/Modules/arraymodule.c
@@ -1169,6 +1169,44 @@ array_repr(a)
return s;
}
+static int
+array_buffer_getreadbuf(self, index, ptr)
+ arrayobject *self;
+ int index;
+ const void **ptr;
+{
+ if ( index != 0 ) {
+ PyErr_SetString(PyExc_SystemError, "Accessing non-existent array segment");
+ return -1;
+ }
+ *ptr = (void *)self->ob_item;
+ return self->ob_size*self->ob_descr->itemsize;
+}
+
+static int
+array_buffer_getwritebuf(self, index, ptr)
+ arrayobject *self;
+ int index;
+ const void **ptr;
+{
+ if ( index != 0 ) {
+ PyErr_SetString(PyExc_SystemError, "Accessing non-existent array segment");
+ return -1;
+ }
+ *ptr = (void *)self->ob_item;
+ return self->ob_size*self->ob_descr->itemsize;
+}
+
+static int
+array_buffer_getsegcount(self, lenp)
+ arrayobject *self;
+ int *lenp;
+{
+ if ( lenp )
+ *lenp = self->ob_size*self->ob_descr->itemsize;
+ return 1;
+}
+
static PySequenceMethods array_as_sequence = {
(inquiry)array_length, /*sq_length*/
(binaryfunc)array_concat, /*sq_concat*/
@@ -1179,6 +1217,13 @@ static PySequenceMethods array_as_sequence = {
(intintobjargproc)array_ass_slice, /*sq_ass_slice*/
};
+static PyBufferProcs array_as_buffer = {
+ (getreadbufferproc)array_buffer_getreadbuf,
+ (getwritebufferproc)array_buffer_getwritebuf,
+ (getsegcountproc)array_buffer_getsegcount,
+};
+
+
statichere PyTypeObject Arraytype = {
PyObject_HEAD_INIT(&PyType_Type)
0,
@@ -1194,6 +1239,14 @@ statichere PyTypeObject Arraytype = {
0, /*tp_as_number*/
&array_as_sequence, /*tp_as_sequence*/
0, /*tp_as_mapping*/
+ 0, /*tp_hash*/
+ 0, /*tp_call*/
+ 0, /*tp_str*/
+ 0, /*tp_getattro*/
+ 0, /*tp_setattro*/
+ &array_as_buffer, /*tp_as_buffer*/
+ 0, /*tp_xxx4*/
+ 0, /*tp_doc*/
};