mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
Checkin of Jack's buffer mods.
Not really checked, but didn't fail any tests either...
This commit is contained in:
parent
8290e07509
commit
fdf95dd525
5 changed files with 232 additions and 27 deletions
|
@ -1169,6 +1169,44 @@ array_repr(a)
|
|||
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 @@ static PySequenceMethods array_as_sequence = {
|
|||
(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 @@ statichere PyTypeObject Arraytype = {
|
|||
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*/
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue