diff Modules/arraymodule.c @ 5410:3b2fda31bf1b legacy-trunk

Checkin of Jack's buffer mods. Not really checked, but didn't fail any tests either...
author Guido van Rossum <guido@python.org>
date Mon, 05 May 1997 22:15:02 +0000
parents 2c4b802a3b5d
children cfc13f3f3876
line wrap: on
line diff
--- a/Modules/arraymodule.c	Mon May 05 22:14:19 1997 +0000
+++ b/Modules/arraymodule.c	Mon May 05 22:15:02 1997 +0000
@@ -1169,6 +1169,44 @@
 	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 @@
 	(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 @@
 	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*/
 };