Skip to content

Commit 8b78eea

Browse files
author
travis.oliphant
committed
Change PyBuffer to Py_buffer to be consistent with other non-object structures like Py_complex. Add some more functionality to the memoryview object.
git-svn-id: http://svn.python.org/projects/python/branches/py3k@58236 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent 156647a commit 8b78eea

16 files changed

Lines changed: 145 additions & 85 deletions

Include/abstract.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
542542
/* Return 1 if the getbuffer function is available, otherwise
543543
return 0 */
544544

545-
PyAPI_FUNC(int) PyObject_GetBuffer(PyObject *obj, PyBuffer *view,
545+
PyAPI_FUNC(int) PyObject_GetBuffer(PyObject *obj, Py_buffer *view,
546546
int flags);
547547

548548
/* This is a C-API version of the getbuffer function call. It checks
@@ -552,7 +552,7 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
552552
*/
553553

554554

555-
PyAPI_FUNC(void) PyObject_ReleaseBuffer(PyObject *obj, PyBuffer *view);
555+
PyAPI_FUNC(void) PyObject_ReleaseBuffer(PyObject *obj, Py_buffer *view);
556556

557557

558558
/* C-API version of the releasebuffer function call. It
@@ -570,7 +570,7 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
570570
buffer
571571
*/
572572

573-
PyAPI_FUNC(void *) PyBuffer_GetPointer(PyBuffer *view, Py_ssize_t *indices);
573+
PyAPI_FUNC(void *) PyBuffer_GetPointer(Py_buffer *view, Py_ssize_t *indices);
574574

575575
/* Get the memory area pointed to by the indices for the buffer given.
576576
Note that view->ndim is the assumed size of indices
@@ -583,10 +583,10 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
583583

584584

585585

586-
PyAPI_FUNC(int) PyBuffer_ToContiguous(void *buf, PyBuffer *view,
586+
PyAPI_FUNC(int) PyBuffer_ToContiguous(void *buf, Py_buffer *view,
587587
Py_ssize_t len, char fort);
588588

589-
PyAPI_FUNC(int) PyBuffer_FromContiguous(PyBuffer *view, void *buf,
589+
PyAPI_FUNC(int) PyBuffer_FromContiguous(Py_buffer *view, void *buf,
590590
Py_ssize_t len, char fort);
591591

592592

@@ -611,7 +611,7 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
611611
/* Copy the data from the src buffer to the buffer of destination
612612
*/
613613

614-
PyAPI_FUNC(int) PyBuffer_IsContiguous(PyBuffer *view, char fortran);
614+
PyAPI_FUNC(int) PyBuffer_IsContiguous(Py_buffer *view, char fortran);
615615

616616

617617
PyAPI_FUNC(void) PyBuffer_FillContiguousStrides(int ndims,
@@ -626,7 +626,7 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
626626
per element.
627627
*/
628628

629-
PyAPI_FUNC(int) PyBuffer_FillInfo(PyBuffer *view, void *buf,
629+
PyAPI_FUNC(int) PyBuffer_FillInfo(Py_buffer *view, void *buf,
630630
Py_ssize_t len, int readonly,
631631
int flags);
632632

Include/memoryobject.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ extern "C" {
1010
typedef struct {
1111
PyObject_HEAD
1212
PyObject *base;
13-
PyBuffer view;
13+
Py_buffer view;
1414
} PyMemoryViewObject;
1515

1616

@@ -57,7 +57,7 @@ PyAPI_FUNC(PyObject *) PyMemoryView_GetContiguous(PyObject *base, int buffertype
5757

5858
PyAPI_FUNC(PyObject *) PyMemoryView_FromObject(PyObject *base);
5959

60-
PyAPI_FUNC(PyObject *) PyMemoryView_FromMemory(PyBuffer *info);
60+
PyAPI_FUNC(PyObject *) PyMemoryView_FromMemory(Py_buffer *info);
6161
/* create new if bufptr is NULL
6262
will be a new bytesobject in base */
6363

Include/object.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,10 @@ typedef struct bufferinfo {
153153
Py_ssize_t *strides;
154154
Py_ssize_t *suboffsets;
155155
void *internal;
156-
} PyBuffer;
156+
} Py_buffer;
157157

158-
typedef int (*getbufferproc)(PyObject *, PyBuffer *, int);
159-
typedef void (*releasebufferproc)(PyObject *, PyBuffer *);
158+
typedef int (*getbufferproc)(PyObject *, Py_buffer *, int);
159+
typedef void (*releasebufferproc)(PyObject *, Py_buffer *);
160160

161161
/* Flags for getting buffers */
162162
#define PyBUF_SIMPLE 0

Modules/_ctypes/_ctypes.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,7 @@ CharArray_set_raw(CDataObject *self, PyObject *value)
740740
char *ptr;
741741
Py_ssize_t size;
742742
int rel = 0;
743-
PyBuffer view;
743+
Py_buffer view;
744744

745745
if (PyBuffer_Check(value)) {
746746
if (PyObject_GetBuffer(value, &view, PyBUF_SIMPLE) < 0)
@@ -2083,7 +2083,7 @@ static PyMemberDef CData_members[] = {
20832083
{ NULL },
20842084
};
20852085

2086-
static int CData_GetBuffer(PyObject *_self, PyBuffer *view, int flags)
2086+
static int CData_GetBuffer(PyObject *_self, Py_buffer *view, int flags)
20872087
{
20882088
CDataObject *self = (CDataObject *)_self;
20892089
return PyBuffer_FillInfo(view, self->b_ptr, self->b_size, 0, flags);

Modules/_hashopenssl.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ static PyObject *
176176
EVP_update(EVPobject *self, PyObject *args)
177177
{
178178
PyObject *obj;
179-
PyBuffer view;
179+
Py_buffer view;
180180

181181
if (!PyArg_ParseTuple(args, "O:update", &obj))
182182
return NULL;
@@ -252,7 +252,7 @@ EVP_tp_init(EVPobject *self, PyObject *args, PyObject *kwds)
252252
static char *kwlist[] = {"name", "string", NULL};
253253
PyObject *name_obj = NULL;
254254
PyObject *data_obj = NULL;
255-
PyBuffer view;
255+
Py_buffer view;
256256
char *nameStr;
257257
const EVP_MD *digest;
258258

@@ -397,7 +397,7 @@ EVP_new(PyObject *self, PyObject *args, PyObject *kwdict)
397397
static char *kwlist[] = {"name", "string", NULL};
398398
PyObject *name_obj = NULL;
399399
PyObject *data_obj = NULL;
400-
PyBuffer view = { 0 };
400+
Py_buffer view = { 0 };
401401
PyObject *ret_obj;
402402
char *name;
403403
const EVP_MD *digest;
@@ -437,7 +437,7 @@ EVP_new(PyObject *self, PyObject *args, PyObject *kwdict)
437437
EVP_new_ ## NAME (PyObject *self, PyObject *args) \
438438
{ \
439439
PyObject *data_obj = NULL; \
440-
PyBuffer view = { 0 }; \
440+
Py_buffer view = { 0 }; \
441441
PyObject *ret_obj; \
442442
\
443443
if (!PyArg_ParseTuple(args, "|O:" #NAME , &data_obj)) { \

Modules/_sre.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1672,7 +1672,7 @@ getstring(PyObject* string, Py_ssize_t* p_length, int* p_charsize)
16721672
Py_ssize_t size, bytes;
16731673
int charsize;
16741674
void* ptr;
1675-
PyBuffer view;
1675+
Py_buffer view;
16761676

16771677
/* get pointer to string buffer */
16781678
view.len = -1;

Modules/arraymodule.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1784,7 +1784,7 @@ static const void *emptybuf = "";
17841784

17851785

17861786
static int
1787-
array_buffer_getbuf(arrayobject *self, PyBuffer *view, int flags)
1787+
array_buffer_getbuf(arrayobject *self, Py_buffer *view, int flags)
17881788
{
17891789
if ((flags & PyBUF_CHARACTER)) {
17901790
PyErr_SetString(PyExc_TypeError,
@@ -1825,7 +1825,7 @@ array_buffer_getbuf(arrayobject *self, PyBuffer *view, int flags)
18251825
}
18261826

18271827
static void
1828-
array_buffer_relbuf(arrayobject *self, PyBuffer *view)
1828+
array_buffer_relbuf(arrayobject *self, Py_buffer *view)
18291829
{
18301830
self->ob_exports--;
18311831
}

Modules/mmapmodule.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ static struct PyMethodDef mmap_object_methods[] = {
601601
/* Functions for treating an mmap'ed file as a buffer */
602602

603603
static int
604-
mmap_buffer_getbuf(mmap_object *self, PyBuffer *view, int flags)
604+
mmap_buffer_getbuf(mmap_object *self, Py_buffer *view, int flags)
605605
{
606606
CHECK_VALID(-1);
607607
if (PyBuffer_FillInfo(view, self->data, self->size,
@@ -612,7 +612,7 @@ mmap_buffer_getbuf(mmap_object *self, PyBuffer *view, int flags)
612612
}
613613

614614
static void
615-
mmap_buffer_releasebuf(mmap_object *self, PyBuffer *view)
615+
mmap_buffer_releasebuf(mmap_object *self, Py_buffer *view)
616616
{
617617
self->exports--;
618618
}

Objects/abstract.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ PyObject_AsCharBuffer(PyObject *obj,
224224
Py_ssize_t *buffer_len)
225225
{
226226
PyBufferProcs *pb;
227-
PyBuffer view;
227+
Py_buffer view;
228228

229229
if (obj == NULL || buffer == NULL || buffer_len == NULL) {
230230
null_error();
@@ -267,7 +267,7 @@ int PyObject_AsReadBuffer(PyObject *obj,
267267
Py_ssize_t *buffer_len)
268268
{
269269
PyBufferProcs *pb;
270-
PyBuffer view;
270+
Py_buffer view;
271271

272272
if (obj == NULL || buffer == NULL || buffer_len == NULL) {
273273
null_error();
@@ -295,7 +295,7 @@ int PyObject_AsWriteBuffer(PyObject *obj,
295295
Py_ssize_t *buffer_len)
296296
{
297297
PyBufferProcs *pb;
298-
PyBuffer view;
298+
Py_buffer view;
299299

300300
if (obj == NULL || buffer == NULL || buffer_len == NULL) {
301301
null_error();
@@ -320,7 +320,7 @@ int PyObject_AsWriteBuffer(PyObject *obj,
320320
/* Buffer C-API for Python 3.0 */
321321

322322
int
323-
PyObject_GetBuffer(PyObject *obj, PyBuffer *view, int flags)
323+
PyObject_GetBuffer(PyObject *obj, Py_buffer *view, int flags)
324324
{
325325
if (!PyObject_CheckBuffer(obj)) {
326326
PyErr_SetString(PyExc_TypeError,
@@ -331,7 +331,7 @@ PyObject_GetBuffer(PyObject *obj, PyBuffer *view, int flags)
331331
}
332332

333333
void
334-
PyObject_ReleaseBuffer(PyObject *obj, PyBuffer *view)
334+
PyObject_ReleaseBuffer(PyObject *obj, Py_buffer *view)
335335
{
336336
if (obj->ob_type->tp_as_buffer != NULL &&
337337
obj->ob_type->tp_as_buffer->bf_releasebuffer != NULL) {
@@ -341,7 +341,7 @@ PyObject_ReleaseBuffer(PyObject *obj, PyBuffer *view)
341341

342342

343343
static int
344-
_IsFortranContiguous(PyBuffer *view)
344+
_IsFortranContiguous(Py_buffer *view)
345345
{
346346
Py_ssize_t sd, dim;
347347
int i;
@@ -362,7 +362,7 @@ _IsFortranContiguous(PyBuffer *view)
362362
}
363363

364364
static int
365-
_IsCContiguous(PyBuffer *view)
365+
_IsCContiguous(Py_buffer *view)
366366
{
367367
Py_ssize_t sd, dim;
368368
int i;
@@ -383,7 +383,7 @@ _IsCContiguous(PyBuffer *view)
383383
}
384384

385385
int
386-
PyBuffer_IsContiguous(PyBuffer *view, char fort)
386+
PyBuffer_IsContiguous(Py_buffer *view, char fort)
387387
{
388388

389389
if (view->suboffsets != NULL) return 0;
@@ -399,7 +399,7 @@ PyBuffer_IsContiguous(PyBuffer *view, char fort)
399399

400400

401401
void*
402-
PyBuffer_GetPointer(PyBuffer *view, Py_ssize_t *indices)
402+
PyBuffer_GetPointer(Py_buffer *view, Py_ssize_t *indices)
403403
{
404404
char* pointer;
405405
int i;
@@ -452,7 +452,7 @@ _add_one_to_index_C(int nd, Py_ssize_t *index, Py_ssize_t *shape)
452452
*/
453453

454454
int
455-
PyBuffer_ToContiguous(void *buf, PyBuffer *view, Py_ssize_t len, char fort)
455+
PyBuffer_ToContiguous(void *buf, Py_buffer *view, Py_ssize_t len, char fort)
456456
{
457457
int k;
458458
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)
503503
}
504504

505505
int
506-
PyBuffer_FromContiguous(PyBuffer *view, void *buf, Py_ssize_t len, char fort)
506+
PyBuffer_FromContiguous(Py_buffer *view, void *buf, Py_ssize_t len, char fort)
507507
{
508508
int k;
509509
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)
556556

557557
int PyObject_CopyData(PyObject *dest, PyObject *src)
558558
{
559-
PyBuffer view_dest, view_src;
559+
Py_buffer view_dest, view_src;
560560
int k;
561561
Py_ssize_t *indices, elements;
562562
char *dptr, *sptr;
@@ -649,7 +649,7 @@ PyBuffer_FillContiguousStrides(int nd, Py_ssize_t *shape,
649649
}
650650

651651
int
652-
PyBuffer_FillInfo(PyBuffer *view, void *buf, Py_ssize_t len,
652+
PyBuffer_FillInfo(Py_buffer *view, void *buf, Py_ssize_t len,
653653
int readonly, int flags)
654654
{
655655
if (view == NULL) return 0;

0 commit comments

Comments
 (0)