diff Objects/bufferobject.c @ 9305:083efa076366 legacy-trunk

Greg Stein: Implement the new bf_getcharbuffer function, indicating that (as far as the data type is concerned!) this is character data.
author Guido van Rossum <guido@python.org>
date Thu, 08 Oct 1998 02:18:52 +0000
parents bc5150652edc
children e6799a855af7
line wrap: on
line diff
--- a/Objects/bufferobject.c	Thu Oct 08 02:10:56 1998 +0000
+++ b/Objects/bufferobject.c	Thu Oct 08 02:18:52 1998 +0000
@@ -523,7 +523,7 @@
 {
 	if ( idx != 0 ) {
 		PyErr_SetString(PyExc_SystemError,
-				"Accessing non-existent buffer segment");
+				"accessing non-existent buffer segment");
 		return -1;
 	}
 	*pp = self->b_ptr;
@@ -554,6 +554,21 @@
 	return 1;
 }
 
+static int
+buffer_getcharbuf(self, idx, pp)
+	PyBufferObject *self;
+	int idx;
+	const char ** pp;
+{
+	if ( idx != 0 ) {
+		PyErr_SetString(PyExc_SystemError,
+				"accessing non-existent buffer segment");
+		return -1;
+	}
+	*pp = (const char *)self->b_ptr;
+	return self->b_size;
+}
+
 
 static PySequenceMethods buffer_as_sequence = {
 	(inquiry)buffer_length, /*sq_length*/
@@ -569,6 +584,7 @@
 	(getreadbufferproc)buffer_getreadbuf,
 	(getwritebufferproc)buffer_getwritebuf,
 	(getsegcountproc)buffer_getsegcount,
+	(getcharbufferproc)buffer_getcharbuf,
 };
 
 PyTypeObject PyBuffer_Type = {
@@ -592,7 +608,7 @@
 	0,		/*tp_getattro*/
 	0,		/*tp_setattro*/
 	&buffer_as_buffer,	/*tp_as_buffer*/
-	0,		/*tp_xxx4*/
+	Py_TPFLAGS_DEFAULT,	/*tp_flags*/
 	0,		/*tp_doc*/
 };