mirror of
https://github.com/python/cpython.git
synced 2025-07-23 19:25:40 +00:00
Greg Stein: Implement the new bf_getcharbuffer function, indicating
that (as far as the data type is concerned!) this is character data.
This commit is contained in:
parent
36eef3c173
commit
1db7070217
2 changed files with 36 additions and 4 deletions
|
@ -523,7 +523,7 @@ buffer_getreadbuf(self, idx, pp)
|
||||||
{
|
{
|
||||||
if ( idx != 0 ) {
|
if ( idx != 0 ) {
|
||||||
PyErr_SetString(PyExc_SystemError,
|
PyErr_SetString(PyExc_SystemError,
|
||||||
"Accessing non-existent buffer segment");
|
"accessing non-existent buffer segment");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
*pp = self->b_ptr;
|
*pp = self->b_ptr;
|
||||||
|
@ -554,6 +554,21 @@ buffer_getsegcount(self, lenp)
|
||||||
return 1;
|
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 = {
|
static PySequenceMethods buffer_as_sequence = {
|
||||||
(inquiry)buffer_length, /*sq_length*/
|
(inquiry)buffer_length, /*sq_length*/
|
||||||
|
@ -569,6 +584,7 @@ static PyBufferProcs buffer_as_buffer = {
|
||||||
(getreadbufferproc)buffer_getreadbuf,
|
(getreadbufferproc)buffer_getreadbuf,
|
||||||
(getwritebufferproc)buffer_getwritebuf,
|
(getwritebufferproc)buffer_getwritebuf,
|
||||||
(getsegcountproc)buffer_getsegcount,
|
(getsegcountproc)buffer_getsegcount,
|
||||||
|
(getcharbufferproc)buffer_getcharbuf,
|
||||||
};
|
};
|
||||||
|
|
||||||
PyTypeObject PyBuffer_Type = {
|
PyTypeObject PyBuffer_Type = {
|
||||||
|
@ -592,7 +608,7 @@ PyTypeObject PyBuffer_Type = {
|
||||||
0, /*tp_getattro*/
|
0, /*tp_getattro*/
|
||||||
0, /*tp_setattro*/
|
0, /*tp_setattro*/
|
||||||
&buffer_as_buffer, /*tp_as_buffer*/
|
&buffer_as_buffer, /*tp_as_buffer*/
|
||||||
0, /*tp_xxx4*/
|
Py_TPFLAGS_DEFAULT, /*tp_flags*/
|
||||||
0, /*tp_doc*/
|
0, /*tp_doc*/
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -465,7 +465,7 @@ string_buffer_getreadbuf(self, index, ptr)
|
||||||
{
|
{
|
||||||
if ( index != 0 ) {
|
if ( index != 0 ) {
|
||||||
PyErr_SetString(PyExc_SystemError,
|
PyErr_SetString(PyExc_SystemError,
|
||||||
"Accessing non-existent string segment");
|
"accessing non-existent string segment");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
*ptr = (void *)self->ob_sval;
|
*ptr = (void *)self->ob_sval;
|
||||||
|
@ -493,6 +493,21 @@ string_buffer_getsegcount(self, lenp)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
string_buffer_getcharbuf(self, index, ptr)
|
||||||
|
PyStringObject *self;
|
||||||
|
int index;
|
||||||
|
const char **ptr;
|
||||||
|
{
|
||||||
|
if ( index != 0 ) {
|
||||||
|
PyErr_SetString(PyExc_SystemError,
|
||||||
|
"accessing non-existent string segment");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
*ptr = self->ob_sval;
|
||||||
|
return self->ob_size;
|
||||||
|
}
|
||||||
|
|
||||||
static PySequenceMethods string_as_sequence = {
|
static PySequenceMethods string_as_sequence = {
|
||||||
(inquiry)string_length, /*sq_length*/
|
(inquiry)string_length, /*sq_length*/
|
||||||
(binaryfunc)string_concat, /*sq_concat*/
|
(binaryfunc)string_concat, /*sq_concat*/
|
||||||
|
@ -507,6 +522,7 @@ static PyBufferProcs string_as_buffer = {
|
||||||
(getreadbufferproc)string_buffer_getreadbuf,
|
(getreadbufferproc)string_buffer_getreadbuf,
|
||||||
(getwritebufferproc)string_buffer_getwritebuf,
|
(getwritebufferproc)string_buffer_getwritebuf,
|
||||||
(getsegcountproc)string_buffer_getsegcount,
|
(getsegcountproc)string_buffer_getsegcount,
|
||||||
|
(getcharbufferproc)string_buffer_getcharbuf,
|
||||||
};
|
};
|
||||||
|
|
||||||
PyTypeObject PyString_Type = {
|
PyTypeObject PyString_Type = {
|
||||||
|
@ -530,7 +546,7 @@ PyTypeObject PyString_Type = {
|
||||||
0, /*tp_getattro*/
|
0, /*tp_getattro*/
|
||||||
0, /*tp_setattro*/
|
0, /*tp_setattro*/
|
||||||
&string_as_buffer, /*tp_as_buffer*/
|
&string_as_buffer, /*tp_as_buffer*/
|
||||||
0, /*tp_xxx4*/
|
Py_TPFLAGS_DEFAULT, /*tp_flags*/
|
||||||
0, /*tp_doc*/
|
0, /*tp_doc*/
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue