mirror of
https://github.com/python/cpython.git
synced 2025-07-23 03:05:38 +00:00
Merged in py3k-buffer branch to main line. All objects now use the buffer protocol in PEP 3118.
This commit is contained in:
parent
3de862df45
commit
b99f762f10
22 changed files with 1732 additions and 688 deletions
|
@ -1171,44 +1171,10 @@ string_subscript(PyStringObject* self, PyObject* item)
|
|||
}
|
||||
}
|
||||
|
||||
static Py_ssize_t
|
||||
string_buffer_getreadbuf(PyStringObject *self, Py_ssize_t index, const void **ptr)
|
||||
static int
|
||||
string_buffer_getbuffer(PyStringObject *self, PyBuffer *view, int flags)
|
||||
{
|
||||
if ( index != 0 ) {
|
||||
PyErr_SetString(PyExc_SystemError,
|
||||
"accessing non-existent string segment");
|
||||
return -1;
|
||||
}
|
||||
*ptr = (void *)self->ob_sval;
|
||||
return Py_Size(self);
|
||||
}
|
||||
|
||||
static Py_ssize_t
|
||||
string_buffer_getwritebuf(PyStringObject *self, Py_ssize_t index, const void **ptr)
|
||||
{
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"Cannot use string as modifiable buffer");
|
||||
return -1;
|
||||
}
|
||||
|
||||
static Py_ssize_t
|
||||
string_buffer_getsegcount(PyStringObject *self, Py_ssize_t *lenp)
|
||||
{
|
||||
if ( lenp )
|
||||
*lenp = Py_Size(self);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static Py_ssize_t
|
||||
string_buffer_getcharbuf(PyStringObject *self, Py_ssize_t index, const char **ptr)
|
||||
{
|
||||
if ( index != 0 ) {
|
||||
PyErr_SetString(PyExc_SystemError,
|
||||
"accessing non-existent string segment");
|
||||
return -1;
|
||||
}
|
||||
*ptr = self->ob_sval;
|
||||
return Py_Size(self);
|
||||
return PyBuffer_FillInfo(view, (void *)self->ob_sval, Py_Size(self), 0, flags);
|
||||
}
|
||||
|
||||
static PySequenceMethods string_as_sequence = {
|
||||
|
@ -1229,14 +1195,11 @@ static PyMappingMethods string_as_mapping = {
|
|||
};
|
||||
|
||||
static PyBufferProcs string_as_buffer = {
|
||||
(readbufferproc)string_buffer_getreadbuf,
|
||||
(writebufferproc)string_buffer_getwritebuf,
|
||||
(segcountproc)string_buffer_getsegcount,
|
||||
(charbufferproc)string_buffer_getcharbuf,
|
||||
(getbufferproc)string_buffer_getbuffer,
|
||||
NULL,
|
||||
};
|
||||
|
||||
|
||||
|
||||
#define LEFTSTRIP 0
|
||||
#define RIGHTSTRIP 1
|
||||
#define BOTHSTRIP 2
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue