33
34
static PyObject* _bufferproxy_write (PyBufferProxy *buffer, PyObject *args);
35
36
/* Buffer methods */
38
static int _bufferproxy_getbuffer (PyBufferProxy *self, Py_buffer *view,
40
static void _bufferproxy_releasebuffer (PyBufferProxy *self, Py_buffer *view);
36
42
static Py_ssize_t _bufferproxy_getreadbuf (PyBufferProxy *buffer,
80
87
* Buffer interface support for the PyBufferProxy.
82
static PyBufferProcs _bufferproxy_as_buffer =
84
(readbufferproc) _bufferproxy_getreadbuf,
85
(writebufferproc) _bufferproxy_getwritebuf,
86
(segcountproc) _bufferproxy_getsegcount,
90
static PyBufferProcs _bufferproxy_as_buffer =
92
(getbufferproc) _bufferproxy_getbuffer,
93
(releasebufferproc) _bufferproxy_releasebuffer
96
static PyBufferProcs _bufferproxy_as_buffer =
98
(readbufferproc) _bufferproxy_getreadbuf,
99
(writebufferproc) _bufferproxy_getwritebuf,
100
(segcountproc) _bufferproxy_getsegcount,
102
#if PY_VERSION_HEX >= 0x02060000
90
109
static PyTypeObject PyBufferProxy_Type =
92
PyObject_HEAD_INIT(NULL)
94
112
"pygame.bufferproxy.BufferProxy", /* tp_name */
95
113
sizeof (PyBufferProxy), /* tp_basicsize */
96
114
0, /* tp_itemsize */
198
218
_bufferproxy_get_raw (PyBufferProxy *self, void *closure)
200
return PyString_FromStringAndSize (self->buffer, self->length);
220
return Bytes_FromStringAndSize (self->buffer, self->length);
221
241
#if PY_VERSION_HEX < 0x02050000
222
242
return PyString_FromFormat("<BufferProxy(%d)>", self->length);
224
return PyString_FromFormat("<BufferProxy(%zd)>", self->length);
244
return Text_FromFormat("<BufferProxy(%zd)>", self->length);
251
271
/**** Buffer interfaces ****/
275
_bufferproxy_getbuffer (PyBufferProxy *self, Py_buffer *view, int flags)
279
Py_INCREF (self); /* Guarantee that the object does not get destroyed */
280
return PyBuffer_FillInfo (view, (PyObject*)self, self->buffer,
281
self->length, 0, flags);
285
_bufferproxy_releasebuffer (PyBufferProxy *self, Py_buffer *view)
253
290
static Py_ssize_t
254
291
_bufferproxy_getreadbuf (PyBufferProxy *buffer, Py_ssize_t _index,
255
292
const void **ptr)
323
361
return (PyObject *) buf;
327
void initbufferproxy (void)
364
/*DOC*/ static char _bufferproxy_doc[] =
365
/*DOC*/ "A generic proxy module that can spend arbitrary " \
366
/*DOC*/ "objects a buffer interface";
368
MODINIT_DEFINE (bufferproxy)
329
370
PyObject *module;
331
372
PyObject *apiobj;
332
374
static void* c_api[PYGAMEAPI_BUFFERPROXY_NUMSLOTS];
377
static struct PyModuleDef _module = {
378
PyModuleDef_HEAD_INIT,
382
_bufferproxy_methods,
383
NULL, NULL, NULL, NULL
334
387
if (PyType_Ready (&PyBufferProxy_Type) < 0)
337
390
/* create the module */
338
module = Py_InitModule3 ("bufferproxy", NULL,
339
"A generic proxy module that can spend arbitrary " \
340
"objects a buffer interface");
392
module = PyModule_Create (&_module);
394
module = Py_InitModule3 (MODPREFIX "bufferproxy", NULL, _bufferproxy_doc);
341
396
PyBufferProxy_Type.tp_getattro = PyObject_GenericGetAttr;
342
397
Py_INCREF (&PyBufferProxy_Type);
343
PyModule_AddObject (module, "BufferProxy", (PyObject *)&PyBufferProxy_Type);
398
if (PyModule_AddObject (module, "BufferProxy",
399
(PyObject *)&PyBufferProxy_Type) == -1) {
400
Py_DECREF ((PyObject *)&PyBufferProxy_Type);
344
404
dict = PyModule_GetDict (module);
346
406
c_api[0] = &PyBufferProxy_Type;
347
407
c_api[1] = PyBufferProxy_New;
348
408
apiobj = PyCObject_FromVoidPtr (c_api, NULL);
349
PyDict_SetItemString (dict, PYGAMEAPI_LOCAL_ENTRY, apiobj);
409
if (apiobj == NULL) {
413
ecode = PyDict_SetItemString (dict, PYGAMEAPI_LOCAL_ENTRY, apiobj);
350
414
Py_DECREF (apiobj);
419
MODINIT_RETURN (module);