diff options
author | Guido van Rossum <guido@python.org> | 1997-05-05 22:15:02 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1997-05-05 22:15:02 (GMT) |
commit | fdf95dd525840559d77637802ff117969db19031 (patch) | |
tree | ac06e548154ef068d134401a08f66c17d681628b /Objects/stringobject.c | |
parent | 8290e075096ac985c564b738a35307fac0992149 (diff) | |
download | cpython-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 'Objects/stringobject.c')
-rw-r--r-- | Objects/stringobject.c | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/Objects/stringobject.c b/Objects/stringobject.c index 1f95aa1..dbcb1a9 100644 --- a/Objects/stringobject.c +++ b/Objects/stringobject.c @@ -456,6 +456,40 @@ string_hash(a) return x; } +static int +string_buffer_getreadbuf(self, index, ptr) + PyStringObject *self; + int index; + const void **ptr; +{ + if ( index != 0 ) { + PyErr_SetString(PyExc_SystemError, "Accessing non-existent string segment"); + return -1; + } + *ptr = (void *)self->ob_sval; + return self->ob_size; +} + +static int +string_buffer_getwritebuf(self, index, ptr) + PyStringObject *self; + int index; + const void **ptr; +{ + PyErr_SetString(PyExc_TypeError, "Cannot use string as modifyable buffer"); + return -1; +} + +static int +string_buffer_getsegcount(self, lenp) + PyStringObject *self; + int *lenp; +{ + if ( lenp ) + *lenp = self->ob_size; + return 1; +} + static PySequenceMethods string_as_sequence = { (inquiry)string_length, /*sq_length*/ (binaryfunc)string_concat, /*sq_concat*/ @@ -466,6 +500,12 @@ static PySequenceMethods string_as_sequence = { 0, /*sq_ass_slice*/ }; +static PyBufferProcs string_as_buffer = { + (getreadbufferproc)string_buffer_getreadbuf, + (getwritebufferproc)string_buffer_getwritebuf, + (getsegcountproc)string_buffer_getsegcount, +}; + PyTypeObject PyString_Type = { PyObject_HEAD_INIT(&PyType_Type) 0, @@ -486,7 +526,7 @@ PyTypeObject PyString_Type = { 0, /*tp_str*/ 0, /*tp_getattro*/ 0, /*tp_setattro*/ - 0, /*tp_xxx3*/ + &string_as_buffer, /*tp_as_buffer*/ 0, /*tp_xxx4*/ 0, /*tp_doc*/ }; |