mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Change PyBuffer to Py_buffer to be consistent with other non-object structures like Py_complex. Add some more functionality to the memoryview object.
This commit is contained in:
parent
3f993c3b52
commit
8ae62b6094
16 changed files with 145 additions and 85 deletions
|
@ -542,7 +542,7 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
|
||||||
/* Return 1 if the getbuffer function is available, otherwise
|
/* Return 1 if the getbuffer function is available, otherwise
|
||||||
return 0 */
|
return 0 */
|
||||||
|
|
||||||
PyAPI_FUNC(int) PyObject_GetBuffer(PyObject *obj, PyBuffer *view,
|
PyAPI_FUNC(int) PyObject_GetBuffer(PyObject *obj, Py_buffer *view,
|
||||||
int flags);
|
int flags);
|
||||||
|
|
||||||
/* This is a C-API version of the getbuffer function call. It checks
|
/* This is a C-API version of the getbuffer function call. It checks
|
||||||
|
@ -552,7 +552,7 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
PyAPI_FUNC(void) PyObject_ReleaseBuffer(PyObject *obj, PyBuffer *view);
|
PyAPI_FUNC(void) PyObject_ReleaseBuffer(PyObject *obj, Py_buffer *view);
|
||||||
|
|
||||||
|
|
||||||
/* C-API version of the releasebuffer function call. It
|
/* C-API version of the releasebuffer function call. It
|
||||||
|
@ -570,7 +570,7 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
|
||||||
buffer
|
buffer
|
||||||
*/
|
*/
|
||||||
|
|
||||||
PyAPI_FUNC(void *) PyBuffer_GetPointer(PyBuffer *view, Py_ssize_t *indices);
|
PyAPI_FUNC(void *) PyBuffer_GetPointer(Py_buffer *view, Py_ssize_t *indices);
|
||||||
|
|
||||||
/* Get the memory area pointed to by the indices for the buffer given.
|
/* Get the memory area pointed to by the indices for the buffer given.
|
||||||
Note that view->ndim is the assumed size of indices
|
Note that view->ndim is the assumed size of indices
|
||||||
|
@ -583,10 +583,10 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
PyAPI_FUNC(int) PyBuffer_ToContiguous(void *buf, PyBuffer *view,
|
PyAPI_FUNC(int) PyBuffer_ToContiguous(void *buf, Py_buffer *view,
|
||||||
Py_ssize_t len, char fort);
|
Py_ssize_t len, char fort);
|
||||||
|
|
||||||
PyAPI_FUNC(int) PyBuffer_FromContiguous(PyBuffer *view, void *buf,
|
PyAPI_FUNC(int) PyBuffer_FromContiguous(Py_buffer *view, void *buf,
|
||||||
Py_ssize_t len, char fort);
|
Py_ssize_t len, char fort);
|
||||||
|
|
||||||
|
|
||||||
|
@ -611,7 +611,7 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
|
||||||
/* Copy the data from the src buffer to the buffer of destination
|
/* Copy the data from the src buffer to the buffer of destination
|
||||||
*/
|
*/
|
||||||
|
|
||||||
PyAPI_FUNC(int) PyBuffer_IsContiguous(PyBuffer *view, char fortran);
|
PyAPI_FUNC(int) PyBuffer_IsContiguous(Py_buffer *view, char fortran);
|
||||||
|
|
||||||
|
|
||||||
PyAPI_FUNC(void) PyBuffer_FillContiguousStrides(int ndims,
|
PyAPI_FUNC(void) PyBuffer_FillContiguousStrides(int ndims,
|
||||||
|
@ -626,7 +626,7 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
|
||||||
per element.
|
per element.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
PyAPI_FUNC(int) PyBuffer_FillInfo(PyBuffer *view, void *buf,
|
PyAPI_FUNC(int) PyBuffer_FillInfo(Py_buffer *view, void *buf,
|
||||||
Py_ssize_t len, int readonly,
|
Py_ssize_t len, int readonly,
|
||||||
int flags);
|
int flags);
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ extern "C" {
|
||||||
typedef struct {
|
typedef struct {
|
||||||
PyObject_HEAD
|
PyObject_HEAD
|
||||||
PyObject *base;
|
PyObject *base;
|
||||||
PyBuffer view;
|
Py_buffer view;
|
||||||
} PyMemoryViewObject;
|
} PyMemoryViewObject;
|
||||||
|
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ PyAPI_FUNC(PyObject *) PyMemoryView_GetContiguous(PyObject *base, int buffertype
|
||||||
|
|
||||||
PyAPI_FUNC(PyObject *) PyMemoryView_FromObject(PyObject *base);
|
PyAPI_FUNC(PyObject *) PyMemoryView_FromObject(PyObject *base);
|
||||||
|
|
||||||
PyAPI_FUNC(PyObject *) PyMemoryView_FromMemory(PyBuffer *info);
|
PyAPI_FUNC(PyObject *) PyMemoryView_FromMemory(Py_buffer *info);
|
||||||
/* create new if bufptr is NULL
|
/* create new if bufptr is NULL
|
||||||
will be a new bytesobject in base */
|
will be a new bytesobject in base */
|
||||||
|
|
||||||
|
|
|
@ -153,10 +153,10 @@ typedef struct bufferinfo {
|
||||||
Py_ssize_t *strides;
|
Py_ssize_t *strides;
|
||||||
Py_ssize_t *suboffsets;
|
Py_ssize_t *suboffsets;
|
||||||
void *internal;
|
void *internal;
|
||||||
} PyBuffer;
|
} Py_buffer;
|
||||||
|
|
||||||
typedef int (*getbufferproc)(PyObject *, PyBuffer *, int);
|
typedef int (*getbufferproc)(PyObject *, Py_buffer *, int);
|
||||||
typedef void (*releasebufferproc)(PyObject *, PyBuffer *);
|
typedef void (*releasebufferproc)(PyObject *, Py_buffer *);
|
||||||
|
|
||||||
/* Flags for getting buffers */
|
/* Flags for getting buffers */
|
||||||
#define PyBUF_SIMPLE 0
|
#define PyBUF_SIMPLE 0
|
||||||
|
|
|
@ -740,7 +740,7 @@ CharArray_set_raw(CDataObject *self, PyObject *value)
|
||||||
char *ptr;
|
char *ptr;
|
||||||
Py_ssize_t size;
|
Py_ssize_t size;
|
||||||
int rel = 0;
|
int rel = 0;
|
||||||
PyBuffer view;
|
Py_buffer view;
|
||||||
|
|
||||||
if (PyBuffer_Check(value)) {
|
if (PyBuffer_Check(value)) {
|
||||||
if (PyObject_GetBuffer(value, &view, PyBUF_SIMPLE) < 0)
|
if (PyObject_GetBuffer(value, &view, PyBUF_SIMPLE) < 0)
|
||||||
|
@ -2083,7 +2083,7 @@ static PyMemberDef CData_members[] = {
|
||||||
{ NULL },
|
{ NULL },
|
||||||
};
|
};
|
||||||
|
|
||||||
static int CData_GetBuffer(PyObject *_self, PyBuffer *view, int flags)
|
static int CData_GetBuffer(PyObject *_self, Py_buffer *view, int flags)
|
||||||
{
|
{
|
||||||
CDataObject *self = (CDataObject *)_self;
|
CDataObject *self = (CDataObject *)_self;
|
||||||
return PyBuffer_FillInfo(view, self->b_ptr, self->b_size, 0, flags);
|
return PyBuffer_FillInfo(view, self->b_ptr, self->b_size, 0, flags);
|
||||||
|
|
|
@ -176,7 +176,7 @@ static PyObject *
|
||||||
EVP_update(EVPobject *self, PyObject *args)
|
EVP_update(EVPobject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
PyObject *obj;
|
PyObject *obj;
|
||||||
PyBuffer view;
|
Py_buffer view;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "O:update", &obj))
|
if (!PyArg_ParseTuple(args, "O:update", &obj))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -252,7 +252,7 @@ EVP_tp_init(EVPobject *self, PyObject *args, PyObject *kwds)
|
||||||
static char *kwlist[] = {"name", "string", NULL};
|
static char *kwlist[] = {"name", "string", NULL};
|
||||||
PyObject *name_obj = NULL;
|
PyObject *name_obj = NULL;
|
||||||
PyObject *data_obj = NULL;
|
PyObject *data_obj = NULL;
|
||||||
PyBuffer view;
|
Py_buffer view;
|
||||||
char *nameStr;
|
char *nameStr;
|
||||||
const EVP_MD *digest;
|
const EVP_MD *digest;
|
||||||
|
|
||||||
|
@ -397,7 +397,7 @@ EVP_new(PyObject *self, PyObject *args, PyObject *kwdict)
|
||||||
static char *kwlist[] = {"name", "string", NULL};
|
static char *kwlist[] = {"name", "string", NULL};
|
||||||
PyObject *name_obj = NULL;
|
PyObject *name_obj = NULL;
|
||||||
PyObject *data_obj = NULL;
|
PyObject *data_obj = NULL;
|
||||||
PyBuffer view = { 0 };
|
Py_buffer view = { 0 };
|
||||||
PyObject *ret_obj;
|
PyObject *ret_obj;
|
||||||
char *name;
|
char *name;
|
||||||
const EVP_MD *digest;
|
const EVP_MD *digest;
|
||||||
|
@ -437,7 +437,7 @@ EVP_new(PyObject *self, PyObject *args, PyObject *kwdict)
|
||||||
EVP_new_ ## NAME (PyObject *self, PyObject *args) \
|
EVP_new_ ## NAME (PyObject *self, PyObject *args) \
|
||||||
{ \
|
{ \
|
||||||
PyObject *data_obj = NULL; \
|
PyObject *data_obj = NULL; \
|
||||||
PyBuffer view = { 0 }; \
|
Py_buffer view = { 0 }; \
|
||||||
PyObject *ret_obj; \
|
PyObject *ret_obj; \
|
||||||
\
|
\
|
||||||
if (!PyArg_ParseTuple(args, "|O:" #NAME , &data_obj)) { \
|
if (!PyArg_ParseTuple(args, "|O:" #NAME , &data_obj)) { \
|
||||||
|
|
|
@ -1672,7 +1672,7 @@ getstring(PyObject* string, Py_ssize_t* p_length, int* p_charsize)
|
||||||
Py_ssize_t size, bytes;
|
Py_ssize_t size, bytes;
|
||||||
int charsize;
|
int charsize;
|
||||||
void* ptr;
|
void* ptr;
|
||||||
PyBuffer view;
|
Py_buffer view;
|
||||||
|
|
||||||
/* get pointer to string buffer */
|
/* get pointer to string buffer */
|
||||||
view.len = -1;
|
view.len = -1;
|
||||||
|
|
|
@ -1784,7 +1784,7 @@ static const void *emptybuf = "";
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
array_buffer_getbuf(arrayobject *self, PyBuffer *view, int flags)
|
array_buffer_getbuf(arrayobject *self, Py_buffer *view, int flags)
|
||||||
{
|
{
|
||||||
if ((flags & PyBUF_CHARACTER)) {
|
if ((flags & PyBUF_CHARACTER)) {
|
||||||
PyErr_SetString(PyExc_TypeError,
|
PyErr_SetString(PyExc_TypeError,
|
||||||
|
@ -1825,7 +1825,7 @@ array_buffer_getbuf(arrayobject *self, PyBuffer *view, int flags)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
array_buffer_relbuf(arrayobject *self, PyBuffer *view)
|
array_buffer_relbuf(arrayobject *self, Py_buffer *view)
|
||||||
{
|
{
|
||||||
self->ob_exports--;
|
self->ob_exports--;
|
||||||
}
|
}
|
||||||
|
|
|
@ -601,7 +601,7 @@ static struct PyMethodDef mmap_object_methods[] = {
|
||||||
/* Functions for treating an mmap'ed file as a buffer */
|
/* Functions for treating an mmap'ed file as a buffer */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
mmap_buffer_getbuf(mmap_object *self, PyBuffer *view, int flags)
|
mmap_buffer_getbuf(mmap_object *self, Py_buffer *view, int flags)
|
||||||
{
|
{
|
||||||
CHECK_VALID(-1);
|
CHECK_VALID(-1);
|
||||||
if (PyBuffer_FillInfo(view, self->data, self->size,
|
if (PyBuffer_FillInfo(view, self->data, self->size,
|
||||||
|
@ -612,7 +612,7 @@ mmap_buffer_getbuf(mmap_object *self, PyBuffer *view, int flags)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
mmap_buffer_releasebuf(mmap_object *self, PyBuffer *view)
|
mmap_buffer_releasebuf(mmap_object *self, Py_buffer *view)
|
||||||
{
|
{
|
||||||
self->exports--;
|
self->exports--;
|
||||||
}
|
}
|
||||||
|
|
|
@ -224,7 +224,7 @@ PyObject_AsCharBuffer(PyObject *obj,
|
||||||
Py_ssize_t *buffer_len)
|
Py_ssize_t *buffer_len)
|
||||||
{
|
{
|
||||||
PyBufferProcs *pb;
|
PyBufferProcs *pb;
|
||||||
PyBuffer view;
|
Py_buffer view;
|
||||||
|
|
||||||
if (obj == NULL || buffer == NULL || buffer_len == NULL) {
|
if (obj == NULL || buffer == NULL || buffer_len == NULL) {
|
||||||
null_error();
|
null_error();
|
||||||
|
@ -267,7 +267,7 @@ int PyObject_AsReadBuffer(PyObject *obj,
|
||||||
Py_ssize_t *buffer_len)
|
Py_ssize_t *buffer_len)
|
||||||
{
|
{
|
||||||
PyBufferProcs *pb;
|
PyBufferProcs *pb;
|
||||||
PyBuffer view;
|
Py_buffer view;
|
||||||
|
|
||||||
if (obj == NULL || buffer == NULL || buffer_len == NULL) {
|
if (obj == NULL || buffer == NULL || buffer_len == NULL) {
|
||||||
null_error();
|
null_error();
|
||||||
|
@ -295,7 +295,7 @@ int PyObject_AsWriteBuffer(PyObject *obj,
|
||||||
Py_ssize_t *buffer_len)
|
Py_ssize_t *buffer_len)
|
||||||
{
|
{
|
||||||
PyBufferProcs *pb;
|
PyBufferProcs *pb;
|
||||||
PyBuffer view;
|
Py_buffer view;
|
||||||
|
|
||||||
if (obj == NULL || buffer == NULL || buffer_len == NULL) {
|
if (obj == NULL || buffer == NULL || buffer_len == NULL) {
|
||||||
null_error();
|
null_error();
|
||||||
|
@ -320,7 +320,7 @@ int PyObject_AsWriteBuffer(PyObject *obj,
|
||||||
/* Buffer C-API for Python 3.0 */
|
/* Buffer C-API for Python 3.0 */
|
||||||
|
|
||||||
int
|
int
|
||||||
PyObject_GetBuffer(PyObject *obj, PyBuffer *view, int flags)
|
PyObject_GetBuffer(PyObject *obj, Py_buffer *view, int flags)
|
||||||
{
|
{
|
||||||
if (!PyObject_CheckBuffer(obj)) {
|
if (!PyObject_CheckBuffer(obj)) {
|
||||||
PyErr_SetString(PyExc_TypeError,
|
PyErr_SetString(PyExc_TypeError,
|
||||||
|
@ -331,7 +331,7 @@ PyObject_GetBuffer(PyObject *obj, PyBuffer *view, int flags)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
PyObject_ReleaseBuffer(PyObject *obj, PyBuffer *view)
|
PyObject_ReleaseBuffer(PyObject *obj, Py_buffer *view)
|
||||||
{
|
{
|
||||||
if (obj->ob_type->tp_as_buffer != NULL &&
|
if (obj->ob_type->tp_as_buffer != NULL &&
|
||||||
obj->ob_type->tp_as_buffer->bf_releasebuffer != NULL) {
|
obj->ob_type->tp_as_buffer->bf_releasebuffer != NULL) {
|
||||||
|
@ -341,7 +341,7 @@ PyObject_ReleaseBuffer(PyObject *obj, PyBuffer *view)
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
_IsFortranContiguous(PyBuffer *view)
|
_IsFortranContiguous(Py_buffer *view)
|
||||||
{
|
{
|
||||||
Py_ssize_t sd, dim;
|
Py_ssize_t sd, dim;
|
||||||
int i;
|
int i;
|
||||||
|
@ -362,7 +362,7 @@ _IsFortranContiguous(PyBuffer *view)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
_IsCContiguous(PyBuffer *view)
|
_IsCContiguous(Py_buffer *view)
|
||||||
{
|
{
|
||||||
Py_ssize_t sd, dim;
|
Py_ssize_t sd, dim;
|
||||||
int i;
|
int i;
|
||||||
|
@ -383,7 +383,7 @@ _IsCContiguous(PyBuffer *view)
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
PyBuffer_IsContiguous(PyBuffer *view, char fort)
|
PyBuffer_IsContiguous(Py_buffer *view, char fort)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (view->suboffsets != NULL) return 0;
|
if (view->suboffsets != NULL) return 0;
|
||||||
|
@ -399,7 +399,7 @@ PyBuffer_IsContiguous(PyBuffer *view, char fort)
|
||||||
|
|
||||||
|
|
||||||
void*
|
void*
|
||||||
PyBuffer_GetPointer(PyBuffer *view, Py_ssize_t *indices)
|
PyBuffer_GetPointer(Py_buffer *view, Py_ssize_t *indices)
|
||||||
{
|
{
|
||||||
char* pointer;
|
char* pointer;
|
||||||
int i;
|
int i;
|
||||||
|
@ -452,7 +452,7 @@ _add_one_to_index_C(int nd, Py_ssize_t *index, Py_ssize_t *shape)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int
|
int
|
||||||
PyBuffer_ToContiguous(void *buf, PyBuffer *view, Py_ssize_t len, char fort)
|
PyBuffer_ToContiguous(void *buf, Py_buffer *view, Py_ssize_t len, char fort)
|
||||||
{
|
{
|
||||||
int k;
|
int k;
|
||||||
void (*addone)(int, Py_ssize_t *, Py_ssize_t *);
|
void (*addone)(int, Py_ssize_t *, Py_ssize_t *);
|
||||||
|
@ -503,7 +503,7 @@ PyBuffer_ToContiguous(void *buf, PyBuffer *view, Py_ssize_t len, char fort)
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
PyBuffer_FromContiguous(PyBuffer *view, void *buf, Py_ssize_t len, char fort)
|
PyBuffer_FromContiguous(Py_buffer *view, void *buf, Py_ssize_t len, char fort)
|
||||||
{
|
{
|
||||||
int k;
|
int k;
|
||||||
void (*addone)(int, Py_ssize_t *, Py_ssize_t *);
|
void (*addone)(int, Py_ssize_t *, Py_ssize_t *);
|
||||||
|
@ -556,7 +556,7 @@ PyBuffer_FromContiguous(PyBuffer *view, void *buf, Py_ssize_t len, char fort)
|
||||||
|
|
||||||
int PyObject_CopyData(PyObject *dest, PyObject *src)
|
int PyObject_CopyData(PyObject *dest, PyObject *src)
|
||||||
{
|
{
|
||||||
PyBuffer view_dest, view_src;
|
Py_buffer view_dest, view_src;
|
||||||
int k;
|
int k;
|
||||||
Py_ssize_t *indices, elements;
|
Py_ssize_t *indices, elements;
|
||||||
char *dptr, *sptr;
|
char *dptr, *sptr;
|
||||||
|
@ -649,7 +649,7 @@ PyBuffer_FillContiguousStrides(int nd, Py_ssize_t *shape,
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
PyBuffer_FillInfo(PyBuffer *view, void *buf, Py_ssize_t len,
|
PyBuffer_FillInfo(Py_buffer *view, void *buf, Py_ssize_t len,
|
||||||
int readonly, int flags)
|
int readonly, int flags)
|
||||||
{
|
{
|
||||||
if (view == NULL) return 0;
|
if (view == NULL) return 0;
|
||||||
|
|
|
@ -16,11 +16,12 @@ typedef struct {
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
get_buf(PyBufferObject *self, PyBuffer *view, int flags)
|
get_buf(PyBufferObject *self, Py_buffer *view, int flags)
|
||||||
{
|
{
|
||||||
if (self->b_base == NULL) {
|
if (self->b_base == NULL) {
|
||||||
view->buf = self->b_ptr;
|
view->buf = self->b_ptr;
|
||||||
view->len = self->b_size;
|
view->len = self->b_size;
|
||||||
|
view->readonly = 0;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Py_ssize_t count, offset;
|
Py_ssize_t count, offset;
|
||||||
|
@ -46,7 +47,7 @@ get_buf(PyBufferObject *self, PyBuffer *view, int flags)
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
buffer_getbuf(PyBufferObject *self, PyBuffer *view, int flags)
|
buffer_getbuf(PyBufferObject *self, Py_buffer *view, int flags)
|
||||||
{
|
{
|
||||||
if (view == NULL) return 0;
|
if (view == NULL) return 0;
|
||||||
if (!get_buf(self, view, flags))
|
if (!get_buf(self, view, flags))
|
||||||
|
@ -57,7 +58,7 @@ buffer_getbuf(PyBufferObject *self, PyBuffer *view, int flags)
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
buffer_releasebuf(PyBufferObject *self, PyBuffer *view)
|
buffer_releasebuf(PyBufferObject *self, Py_buffer *view)
|
||||||
{
|
{
|
||||||
/* No-op if there is no self->b_base */
|
/* No-op if there is no self->b_base */
|
||||||
if (self->b_base != NULL) {
|
if (self->b_base != NULL) {
|
||||||
|
@ -229,7 +230,7 @@ buffer_dealloc(PyBufferObject *self)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
get_bufx(PyObject *obj, PyBuffer *view, int flags)
|
get_bufx(PyObject *obj, Py_buffer *view, int flags)
|
||||||
{
|
{
|
||||||
PyBufferProcs *bp;
|
PyBufferProcs *bp;
|
||||||
|
|
||||||
|
@ -256,7 +257,7 @@ buffer_richcompare(PyObject *self, PyObject *other, int op)
|
||||||
void *p1, *p2;
|
void *p1, *p2;
|
||||||
Py_ssize_t len1, len2, min_len;
|
Py_ssize_t len1, len2, min_len;
|
||||||
int cmp, ok;
|
int cmp, ok;
|
||||||
PyBuffer v1, v2;
|
Py_buffer v1, v2;
|
||||||
|
|
||||||
ok = 1;
|
ok = 1;
|
||||||
if (!get_bufx(self, &v1, PyBUF_SIMPLE))
|
if (!get_bufx(self, &v1, PyBUF_SIMPLE))
|
||||||
|
@ -318,7 +319,7 @@ buffer_repr(PyBufferObject *self)
|
||||||
static long
|
static long
|
||||||
buffer_hash(PyBufferObject *self)
|
buffer_hash(PyBufferObject *self)
|
||||||
{
|
{
|
||||||
PyBuffer view;
|
Py_buffer view;
|
||||||
register Py_ssize_t len;
|
register Py_ssize_t len;
|
||||||
register unsigned char *p;
|
register unsigned char *p;
|
||||||
register long x;
|
register long x;
|
||||||
|
@ -351,7 +352,7 @@ buffer_hash(PyBufferObject *self)
|
||||||
static PyObject *
|
static PyObject *
|
||||||
buffer_str(PyBufferObject *self)
|
buffer_str(PyBufferObject *self)
|
||||||
{
|
{
|
||||||
PyBuffer view;
|
Py_buffer view;
|
||||||
PyObject *res;
|
PyObject *res;
|
||||||
|
|
||||||
if (!get_buf(self, &view, PyBUF_SIMPLE))
|
if (!get_buf(self, &view, PyBUF_SIMPLE))
|
||||||
|
@ -366,7 +367,7 @@ buffer_str(PyBufferObject *self)
|
||||||
static Py_ssize_t
|
static Py_ssize_t
|
||||||
buffer_length(PyBufferObject *self)
|
buffer_length(PyBufferObject *self)
|
||||||
{
|
{
|
||||||
PyBuffer view;
|
Py_buffer view;
|
||||||
|
|
||||||
if (!get_buf(self, &view, PyBUF_SIMPLE))
|
if (!get_buf(self, &view, PyBUF_SIMPLE))
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -380,7 +381,7 @@ buffer_concat(PyBufferObject *self, PyObject *other)
|
||||||
PyBufferProcs *pb = other->ob_type->tp_as_buffer;
|
PyBufferProcs *pb = other->ob_type->tp_as_buffer;
|
||||||
char *p;
|
char *p;
|
||||||
PyObject *ob;
|
PyObject *ob;
|
||||||
PyBuffer view, view2;
|
Py_buffer view, view2;
|
||||||
|
|
||||||
if (pb == NULL ||
|
if (pb == NULL ||
|
||||||
pb->bf_getbuffer == NULL)
|
pb->bf_getbuffer == NULL)
|
||||||
|
@ -426,7 +427,7 @@ buffer_repeat(PyBufferObject *self, Py_ssize_t count)
|
||||||
{
|
{
|
||||||
PyObject *ob;
|
PyObject *ob;
|
||||||
register char *p;
|
register char *p;
|
||||||
PyBuffer view;
|
Py_buffer view;
|
||||||
|
|
||||||
if (count < 0)
|
if (count < 0)
|
||||||
count = 0;
|
count = 0;
|
||||||
|
@ -450,7 +451,7 @@ buffer_repeat(PyBufferObject *self, Py_ssize_t count)
|
||||||
static PyObject *
|
static PyObject *
|
||||||
buffer_item(PyBufferObject *self, Py_ssize_t idx)
|
buffer_item(PyBufferObject *self, Py_ssize_t idx)
|
||||||
{
|
{
|
||||||
PyBuffer view;
|
Py_buffer view;
|
||||||
PyObject *ob;
|
PyObject *ob;
|
||||||
|
|
||||||
if (!get_buf(self, &view, PyBUF_SIMPLE))
|
if (!get_buf(self, &view, PyBUF_SIMPLE))
|
||||||
|
@ -467,7 +468,7 @@ buffer_item(PyBufferObject *self, Py_ssize_t idx)
|
||||||
static PyObject *
|
static PyObject *
|
||||||
buffer_subscript(PyBufferObject *self, PyObject *item)
|
buffer_subscript(PyBufferObject *self, PyObject *item)
|
||||||
{
|
{
|
||||||
PyBuffer view;
|
Py_buffer view;
|
||||||
PyObject *ob;
|
PyObject *ob;
|
||||||
|
|
||||||
if (!get_buf(self, &view, PyBUF_SIMPLE))
|
if (!get_buf(self, &view, PyBUF_SIMPLE))
|
||||||
|
@ -537,7 +538,7 @@ static int
|
||||||
buffer_ass_item(PyBufferObject *self, Py_ssize_t idx, PyObject *other)
|
buffer_ass_item(PyBufferObject *self, Py_ssize_t idx, PyObject *other)
|
||||||
{
|
{
|
||||||
PyBufferProcs *pb;
|
PyBufferProcs *pb;
|
||||||
PyBuffer view, view2;
|
Py_buffer view, view2;
|
||||||
|
|
||||||
if (!get_buf(self, &view, PyBUF_SIMPLE))
|
if (!get_buf(self, &view, PyBUF_SIMPLE))
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -585,7 +586,7 @@ buffer_ass_item(PyBufferObject *self, Py_ssize_t idx, PyObject *other)
|
||||||
static int
|
static int
|
||||||
buffer_ass_subscript(PyBufferObject *self, PyObject *item, PyObject *value)
|
buffer_ass_subscript(PyBufferObject *self, PyObject *item, PyObject *value)
|
||||||
{
|
{
|
||||||
PyBuffer v1;
|
Py_buffer v1;
|
||||||
|
|
||||||
if (!get_buf(self, &v1, PyBUF_SIMPLE))
|
if (!get_buf(self, &v1, PyBUF_SIMPLE))
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -606,7 +607,7 @@ buffer_ass_subscript(PyBufferObject *self, PyObject *item, PyObject *value)
|
||||||
}
|
}
|
||||||
else if (PySlice_Check(item)) {
|
else if (PySlice_Check(item)) {
|
||||||
Py_ssize_t start, stop, step, slicelength;
|
Py_ssize_t start, stop, step, slicelength;
|
||||||
PyBuffer v2;
|
Py_buffer v2;
|
||||||
PyBufferProcs *pb;
|
PyBufferProcs *pb;
|
||||||
|
|
||||||
if (PySlice_GetIndicesEx((PySliceObject *)item, v1.len,
|
if (PySlice_GetIndicesEx((PySliceObject *)item, v1.len,
|
||||||
|
|
|
@ -50,7 +50,7 @@ _getbytevalue(PyObject* arg, int *value)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
bytes_getbuffer(PyBytesObject *obj, PyBuffer *view, int flags)
|
bytes_getbuffer(PyBytesObject *obj, Py_buffer *view, int flags)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
void *ptr;
|
void *ptr;
|
||||||
|
@ -70,13 +70,13 @@ bytes_getbuffer(PyBytesObject *obj, PyBuffer *view, int flags)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
bytes_releasebuffer(PyBytesObject *obj, PyBuffer *view)
|
bytes_releasebuffer(PyBytesObject *obj, Py_buffer *view)
|
||||||
{
|
{
|
||||||
obj->ob_exports--;
|
obj->ob_exports--;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Py_ssize_t
|
static Py_ssize_t
|
||||||
_getbuffer(PyObject *obj, PyBuffer *view)
|
_getbuffer(PyObject *obj, Py_buffer *view)
|
||||||
{
|
{
|
||||||
PyBufferProcs *buffer = Py_Type(obj)->tp_as_buffer;
|
PyBufferProcs *buffer = Py_Type(obj)->tp_as_buffer;
|
||||||
|
|
||||||
|
@ -213,7 +213,7 @@ PyObject *
|
||||||
PyBytes_Concat(PyObject *a, PyObject *b)
|
PyBytes_Concat(PyObject *a, PyObject *b)
|
||||||
{
|
{
|
||||||
Py_ssize_t size;
|
Py_ssize_t size;
|
||||||
PyBuffer va, vb;
|
Py_buffer va, vb;
|
||||||
PyBytesObject *result;
|
PyBytesObject *result;
|
||||||
|
|
||||||
va.len = -1;
|
va.len = -1;
|
||||||
|
@ -266,7 +266,7 @@ bytes_iconcat(PyBytesObject *self, PyObject *other)
|
||||||
{
|
{
|
||||||
Py_ssize_t mysize;
|
Py_ssize_t mysize;
|
||||||
Py_ssize_t size;
|
Py_ssize_t size;
|
||||||
PyBuffer vo;
|
Py_buffer vo;
|
||||||
|
|
||||||
if (_getbuffer(other, &vo) < 0) {
|
if (_getbuffer(other, &vo) < 0) {
|
||||||
PyErr_Format(PyExc_TypeError, "can't concat bytes to %.100s",
|
PyErr_Format(PyExc_TypeError, "can't concat bytes to %.100s",
|
||||||
|
@ -462,7 +462,7 @@ bytes_setslice(PyBytesObject *self, Py_ssize_t lo, Py_ssize_t hi,
|
||||||
{
|
{
|
||||||
Py_ssize_t avail, needed;
|
Py_ssize_t avail, needed;
|
||||||
void *bytes;
|
void *bytes;
|
||||||
PyBuffer vbytes;
|
Py_buffer vbytes;
|
||||||
int res = 0;
|
int res = 0;
|
||||||
|
|
||||||
vbytes.len = -1;
|
vbytes.len = -1;
|
||||||
|
@ -814,7 +814,7 @@ bytes_init(PyBytesObject *self, PyObject *args, PyObject *kwds)
|
||||||
/* Use the modern buffer interface */
|
/* Use the modern buffer interface */
|
||||||
if (PyObject_CheckBuffer(arg)) {
|
if (PyObject_CheckBuffer(arg)) {
|
||||||
Py_ssize_t size;
|
Py_ssize_t size;
|
||||||
PyBuffer view;
|
Py_buffer view;
|
||||||
if (PyObject_GetBuffer(arg, &view, PyBUF_FULL_RO) < 0)
|
if (PyObject_GetBuffer(arg, &view, PyBUF_FULL_RO) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
size = view.len;
|
size = view.len;
|
||||||
|
@ -954,7 +954,7 @@ static PyObject *
|
||||||
bytes_richcompare(PyObject *self, PyObject *other, int op)
|
bytes_richcompare(PyObject *self, PyObject *other, int op)
|
||||||
{
|
{
|
||||||
Py_ssize_t self_size, other_size;
|
Py_ssize_t self_size, other_size;
|
||||||
PyBuffer self_bytes, other_bytes;
|
Py_buffer self_bytes, other_bytes;
|
||||||
PyObject *res;
|
PyObject *res;
|
||||||
Py_ssize_t minsize;
|
Py_ssize_t minsize;
|
||||||
int cmp;
|
int cmp;
|
||||||
|
@ -1067,7 +1067,7 @@ Py_LOCAL_INLINE(Py_ssize_t)
|
||||||
bytes_find_internal(PyBytesObject *self, PyObject *args, int dir)
|
bytes_find_internal(PyBytesObject *self, PyObject *args, int dir)
|
||||||
{
|
{
|
||||||
PyObject *subobj;
|
PyObject *subobj;
|
||||||
PyBuffer subbuf;
|
Py_buffer subbuf;
|
||||||
Py_ssize_t start=0, end=PY_SSIZE_T_MAX;
|
Py_ssize_t start=0, end=PY_SSIZE_T_MAX;
|
||||||
Py_ssize_t res;
|
Py_ssize_t res;
|
||||||
|
|
||||||
|
@ -2033,7 +2033,7 @@ bytes_replace(PyBytesObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
Py_ssize_t count = -1;
|
Py_ssize_t count = -1;
|
||||||
PyObject *from, *to, *res;
|
PyObject *from, *to, *res;
|
||||||
PyBuffer vfrom, vto;
|
Py_buffer vfrom, vto;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "OO|n:replace", &from, &to, &count))
|
if (!PyArg_ParseTuple(args, "OO|n:replace", &from, &to, &count))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -2187,7 +2187,7 @@ bytes_split(PyBytesObject *self, PyObject *args)
|
||||||
Py_ssize_t maxsplit = -1, count = 0;
|
Py_ssize_t maxsplit = -1, count = 0;
|
||||||
const char *s = PyBytes_AS_STRING(self), *sub;
|
const char *s = PyBytes_AS_STRING(self), *sub;
|
||||||
PyObject *list, *str, *subobj = Py_None;
|
PyObject *list, *str, *subobj = Py_None;
|
||||||
PyBuffer vsub;
|
Py_buffer vsub;
|
||||||
#ifdef USE_FAST
|
#ifdef USE_FAST
|
||||||
Py_ssize_t pos;
|
Py_ssize_t pos;
|
||||||
#endif
|
#endif
|
||||||
|
@ -2396,7 +2396,7 @@ bytes_rsplit(PyBytesObject *self, PyObject *args)
|
||||||
Py_ssize_t maxsplit = -1, count = 0;
|
Py_ssize_t maxsplit = -1, count = 0;
|
||||||
const char *s = PyBytes_AS_STRING(self), *sub;
|
const char *s = PyBytes_AS_STRING(self), *sub;
|
||||||
PyObject *list, *str, *subobj = Py_None;
|
PyObject *list, *str, *subobj = Py_None;
|
||||||
PyBuffer vsub;
|
Py_buffer vsub;
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "|On:rsplit", &subobj, &maxsplit))
|
if (!PyArg_ParseTuple(args, "|On:rsplit", &subobj, &maxsplit))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -2647,7 +2647,7 @@ bytes_strip(PyBytesObject *self, PyObject *args)
|
||||||
Py_ssize_t left, right, mysize, argsize;
|
Py_ssize_t left, right, mysize, argsize;
|
||||||
void *myptr, *argptr;
|
void *myptr, *argptr;
|
||||||
PyObject *arg = Py_None;
|
PyObject *arg = Py_None;
|
||||||
PyBuffer varg;
|
Py_buffer varg;
|
||||||
if (!PyArg_ParseTuple(args, "|O:strip", &arg))
|
if (!PyArg_ParseTuple(args, "|O:strip", &arg))
|
||||||
return NULL;
|
return NULL;
|
||||||
if (arg == Py_None) {
|
if (arg == Py_None) {
|
||||||
|
@ -2683,7 +2683,7 @@ bytes_lstrip(PyBytesObject *self, PyObject *args)
|
||||||
Py_ssize_t left, right, mysize, argsize;
|
Py_ssize_t left, right, mysize, argsize;
|
||||||
void *myptr, *argptr;
|
void *myptr, *argptr;
|
||||||
PyObject *arg = Py_None;
|
PyObject *arg = Py_None;
|
||||||
PyBuffer varg;
|
Py_buffer varg;
|
||||||
if (!PyArg_ParseTuple(args, "|O:lstrip", &arg))
|
if (!PyArg_ParseTuple(args, "|O:lstrip", &arg))
|
||||||
return NULL;
|
return NULL;
|
||||||
if (arg == Py_None) {
|
if (arg == Py_None) {
|
||||||
|
@ -2716,7 +2716,7 @@ bytes_rstrip(PyBytesObject *self, PyObject *args)
|
||||||
Py_ssize_t left, right, mysize, argsize;
|
Py_ssize_t left, right, mysize, argsize;
|
||||||
void *myptr, *argptr;
|
void *myptr, *argptr;
|
||||||
PyObject *arg = Py_None;
|
PyObject *arg = Py_None;
|
||||||
PyBuffer varg;
|
Py_buffer varg;
|
||||||
if (!PyArg_ParseTuple(args, "|O:rstrip", &arg))
|
if (!PyArg_ParseTuple(args, "|O:rstrip", &arg))
|
||||||
return NULL;
|
return NULL;
|
||||||
if (arg == Py_None) {
|
if (arg == Py_None) {
|
||||||
|
|
|
@ -4,16 +4,16 @@
|
||||||
#include "Python.h"
|
#include "Python.h"
|
||||||
|
|
||||||
static int
|
static int
|
||||||
memory_getbuf(PyMemoryViewObject *self, PyBuffer *view, int flags)
|
memory_getbuf(PyMemoryViewObject *self, Py_buffer *view, int flags)
|
||||||
{
|
{
|
||||||
if (view != NULL)
|
if (view != NULL)
|
||||||
memcpy(view, &(self->view), sizeof(PyBuffer));
|
*view = self->view;
|
||||||
return self->base->ob_type->tp_as_buffer->bf_getbuffer(self->base,
|
return self->base->ob_type->tp_as_buffer->bf_getbuffer(self->base,
|
||||||
NULL, PyBUF_FULL);
|
NULL, PyBUF_FULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
memory_releasebuf(PyMemoryViewObject *self, PyBuffer *view)
|
memory_releasebuf(PyMemoryViewObject *self, Py_buffer *view)
|
||||||
{
|
{
|
||||||
PyObject_ReleaseBuffer(self->base, NULL);
|
PyObject_ReleaseBuffer(self->base, NULL);
|
||||||
}
|
}
|
||||||
|
@ -24,11 +24,16 @@ PyDoc_STRVAR(memory_doc,
|
||||||
Create a new memoryview object which references the given object.");
|
Create a new memoryview object which references the given object.");
|
||||||
|
|
||||||
PyObject *
|
PyObject *
|
||||||
PyMemoryView_FromMemory(PyBuffer *info)
|
PyMemoryView_FromMemory(Py_buffer *info)
|
||||||
{
|
{
|
||||||
/* XXX(nnorwitz): need to implement something here? */
|
PyMemoryViewObject *mview;
|
||||||
PyErr_SetString(PyExc_NotImplementedError, "need to implement");
|
|
||||||
return NULL;
|
mview = (PyMemoryViewObject *)PyObject_New(PyMemoryViewObject,
|
||||||
|
&PyMemoryView_Type);
|
||||||
|
if (mview == NULL) return NULL;
|
||||||
|
mview->base = NULL;
|
||||||
|
mview->view = *info;
|
||||||
|
return (PyObject *)mview;
|
||||||
}
|
}
|
||||||
|
|
||||||
PyObject *
|
PyObject *
|
||||||
|
@ -130,7 +135,7 @@ void _add_one_to_index_F(int nd, Py_ssize_t *index, Py_ssize_t *shape);
|
||||||
void _add_one_to_index_C(int nd, Py_ssize_t *index, Py_ssize_t *shape);
|
void _add_one_to_index_C(int nd, Py_ssize_t *index, Py_ssize_t *shape);
|
||||||
|
|
||||||
static int
|
static int
|
||||||
_indirect_copy_nd(char *dest, PyBuffer *view, char fort)
|
_indirect_copy_nd(char *dest, Py_buffer *view, char fort)
|
||||||
{
|
{
|
||||||
Py_ssize_t *indices;
|
Py_ssize_t *indices;
|
||||||
int k;
|
int k;
|
||||||
|
@ -196,7 +201,7 @@ PyMemoryView_GetContiguous(PyObject *obj, int buffertype, char fort)
|
||||||
{
|
{
|
||||||
PyMemoryViewObject *mem;
|
PyMemoryViewObject *mem;
|
||||||
PyObject *bytes;
|
PyObject *bytes;
|
||||||
PyBuffer *view;
|
Py_buffer *view;
|
||||||
int flags;
|
int flags;
|
||||||
char *dest;
|
char *dest;
|
||||||
|
|
||||||
|
@ -264,8 +269,11 @@ PyMemoryView_GetContiguous(PyObject *obj, int buffertype, char fort)
|
||||||
/* return a shadowed memory-view object */
|
/* return a shadowed memory-view object */
|
||||||
view->buf = dest;
|
view->buf = dest;
|
||||||
mem->base = PyTuple_Pack(2, obj, bytes);
|
mem->base = PyTuple_Pack(2, obj, bytes);
|
||||||
/* XXX(nnorwitz): need to verify alloc was successful. */
|
|
||||||
Py_DECREF(bytes);
|
Py_DECREF(bytes);
|
||||||
|
if (mem->base == NULL) {
|
||||||
|
PyObject_ReleaseBuffer(obj, view);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
PyObject_ReleaseBuffer(obj, view);
|
PyObject_ReleaseBuffer(obj, view);
|
||||||
|
@ -364,13 +372,15 @@ static PyGetSetDef memory_getsetlist[] ={
|
||||||
static PyObject *
|
static PyObject *
|
||||||
memory_tobytes(PyMemoryViewObject *mem, PyObject *noargs)
|
memory_tobytes(PyMemoryViewObject *mem, PyObject *noargs)
|
||||||
{
|
{
|
||||||
/* Create new Bytes object for data */
|
|
||||||
return PyBytes_FromObject((PyObject *)mem);
|
return PyBytes_FromObject((PyObject *)mem);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
memory_tolist(PyMemoryViewObject *mem, PyObject *noargs)
|
memory_tolist(PyMemoryViewObject *mem, PyObject *noargs)
|
||||||
{
|
{
|
||||||
|
/* This should construct a (nested) list of unpacked objects
|
||||||
|
possibly using the struct module.
|
||||||
|
*/
|
||||||
Py_INCREF(Py_NotImplemented);
|
Py_INCREF(Py_NotImplemented);
|
||||||
return Py_NotImplemented;
|
return Py_NotImplemented;
|
||||||
}
|
}
|
||||||
|
@ -429,7 +439,7 @@ memory_repr(PyMemoryViewObject *self)
|
||||||
static PyObject *
|
static PyObject *
|
||||||
memory_str(PyMemoryViewObject *self)
|
memory_str(PyMemoryViewObject *self)
|
||||||
{
|
{
|
||||||
PyBuffer view;
|
Py_buffer view;
|
||||||
PyObject *res;
|
PyObject *res;
|
||||||
|
|
||||||
if (PyObject_GetBuffer((PyObject *)self, &view, PyBUF_FULL) < 0)
|
if (PyObject_GetBuffer((PyObject *)self, &view, PyBUF_FULL) < 0)
|
||||||
|
@ -446,7 +456,7 @@ memory_str(PyMemoryViewObject *self)
|
||||||
static Py_ssize_t
|
static Py_ssize_t
|
||||||
memory_length(PyMemoryViewObject *self)
|
memory_length(PyMemoryViewObject *self)
|
||||||
{
|
{
|
||||||
PyBuffer view;
|
Py_buffer view;
|
||||||
|
|
||||||
if (PyObject_GetBuffer((PyObject *)self, &view, PyBUF_FULL) < 0)
|
if (PyObject_GetBuffer((PyObject *)self, &view, PyBUF_FULL) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -454,9 +464,58 @@ memory_length(PyMemoryViewObject *self)
|
||||||
return view.len;
|
return view.len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
mem[obj] returns a bytes object holding the data for one element if
|
||||||
|
obj fully indexes the memory view or another memory-view object
|
||||||
|
if it does not.
|
||||||
|
|
||||||
|
0-d memory-view objects can be referenced using ... or () but
|
||||||
|
not with anything else.
|
||||||
|
*/
|
||||||
static PyObject *
|
static PyObject *
|
||||||
memory_subscript(PyMemoryViewObject *self, PyObject *key)
|
memory_subscript(PyMemoryViewObject *self, PyObject *key)
|
||||||
{
|
{
|
||||||
|
Py_buffer *view;
|
||||||
|
view = &(self->view);
|
||||||
|
|
||||||
|
if (view->ndim == 0) {
|
||||||
|
if (key == Py_Ellipsis ||
|
||||||
|
(PyTuple_Check(key) && PyTuple_GET_SIZE(key)==0)) {
|
||||||
|
Py_INCREF(self);
|
||||||
|
return (PyObject *)self;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
PyErr_SetString(PyExc_IndexError, "invalid indexing of 0-dim memory");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (PyIndex_Check(key)) {
|
||||||
|
Py_ssize_t result;
|
||||||
|
result = PyNumber_AsSsize_t(key, NULL);
|
||||||
|
if (result == -1 && PyErr_Occurred())
|
||||||
|
return NULL;
|
||||||
|
if (view->ndim == 1) {
|
||||||
|
/* Return a bytes object */
|
||||||
|
char *ptr;
|
||||||
|
ptr = (char *)view->buf;
|
||||||
|
if (view->strides == NULL)
|
||||||
|
ptr += view->itemsize * result;
|
||||||
|
else
|
||||||
|
ptr += view->strides[0] * result;
|
||||||
|
if (view->suboffsets != NULL && view->suboffsets[0] >= 0) {
|
||||||
|
ptr = *((char **)ptr) + view->suboffsets[0];
|
||||||
|
}
|
||||||
|
return PyBytes_FromStringAndSize(ptr, view->itemsize);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
/* Return a new memory-view object */
|
||||||
|
Py_buffer newview;
|
||||||
|
PyMemoryView_FromMemory(&newview);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Py_INCREF(Py_NotImplemented);
|
Py_INCREF(Py_NotImplemented);
|
||||||
return Py_NotImplemented;
|
return Py_NotImplemented;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1160,7 +1160,7 @@ string_subscript(PyStringObject* self, PyObject* item)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
string_buffer_getbuffer(PyStringObject *self, PyBuffer *view, int flags)
|
string_buffer_getbuffer(PyStringObject *self, Py_buffer *view, int flags)
|
||||||
{
|
{
|
||||||
return PyBuffer_FillInfo(view, (void *)self->ob_sval, Py_Size(self), 0, flags);
|
return PyBuffer_FillInfo(view, (void *)self->ob_sval, Py_Size(self), 0, flags);
|
||||||
}
|
}
|
||||||
|
|
|
@ -8104,7 +8104,7 @@ static PyMappingMethods unicode_as_mapping = {
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
unicode_buffer_getbuffer(PyUnicodeObject *self, PyBuffer *view, int flags)
|
unicode_buffer_getbuffer(PyUnicodeObject *self, Py_buffer *view, int flags)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (flags & PyBUF_CHARACTER) {
|
if (flags & PyBUF_CHARACTER) {
|
||||||
|
|
|
@ -1211,7 +1211,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
|
||||||
PyBufferProcs *pb = arg->ob_type->tp_as_buffer;
|
PyBufferProcs *pb = arg->ob_type->tp_as_buffer;
|
||||||
int count;
|
int count;
|
||||||
int temp=-1;
|
int temp=-1;
|
||||||
PyBuffer view;
|
Py_buffer view;
|
||||||
|
|
||||||
if (pb == NULL ||
|
if (pb == NULL ||
|
||||||
pb->bf_getbuffer == NULL ||
|
pb->bf_getbuffer == NULL ||
|
||||||
|
@ -1242,7 +1242,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
|
||||||
char **p = va_arg(*p_va, char **);
|
char **p = va_arg(*p_va, char **);
|
||||||
PyBufferProcs *pb = arg->ob_type->tp_as_buffer;
|
PyBufferProcs *pb = arg->ob_type->tp_as_buffer;
|
||||||
int count;
|
int count;
|
||||||
PyBuffer view;
|
Py_buffer view;
|
||||||
|
|
||||||
if (*format++ != '#')
|
if (*format++ != '#')
|
||||||
return converterr(
|
return converterr(
|
||||||
|
@ -1286,7 +1286,7 @@ convertbuffer(PyObject *arg, void **p, char **errmsg)
|
||||||
{
|
{
|
||||||
PyBufferProcs *pb = arg->ob_type->tp_as_buffer;
|
PyBufferProcs *pb = arg->ob_type->tp_as_buffer;
|
||||||
Py_ssize_t count;
|
Py_ssize_t count;
|
||||||
PyBuffer view;
|
Py_buffer view;
|
||||||
|
|
||||||
*errmsg = NULL;
|
*errmsg = NULL;
|
||||||
*p = NULL;
|
*p = NULL;
|
||||||
|
|
|
@ -367,7 +367,7 @@ w_object(PyObject *v, WFILE *p)
|
||||||
/* Write unknown buffer-style objects as a string */
|
/* Write unknown buffer-style objects as a string */
|
||||||
char *s;
|
char *s;
|
||||||
PyBufferProcs *pb = v->ob_type->tp_as_buffer;
|
PyBufferProcs *pb = v->ob_type->tp_as_buffer;
|
||||||
PyBuffer view;
|
Py_buffer view;
|
||||||
if ((*pb->bf_getbuffer)(v, &view, PyBUF_SIMPLE) != 0) {
|
if ((*pb->bf_getbuffer)(v, &view, PyBUF_SIMPLE) != 0) {
|
||||||
w_byte(TYPE_UNKNOWN, p);
|
w_byte(TYPE_UNKNOWN, p);
|
||||||
p->error = 1;
|
p->error = 1;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue