Mercurial > pygame
annotate src/bufferproxy.c @ 3194:9fcb7abf3185 default tip
Remove some gcc 4.7.2 compiler warnings
| author | Lenard Lindstrom <len-l@telus.net> |
|---|---|
| date | Tue, 23 Apr 2013 19:53:36 -0700 |
| parents | fb1a30254d10 |
| children |
| rev | line source |
|---|---|
| 860 | 1 /* |
| 2 pygame - Python Game Library | |
| 3 Copyright (C) 2007 Marcus von Appen | |
| 4 | |
| 5 This library is free software; you can redistribute it and/or | |
| 6 modify it under the terms of the GNU Library General Public | |
| 7 License as published by the Free Software Foundation; either | |
| 8 version 2 of the License, or (at your option) any later version. | |
| 9 | |
| 10 This library is distributed in the hope that it will be useful, | |
| 11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 13 Library General Public License for more details. | |
| 14 | |
| 15 You should have received a copy of the GNU Library General Public | |
| 16 License along with this library; if not, write to the Free | |
| 17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 18 | |
| 19 */ | |
| 20 | |
| 21 #define PYGAMEAPI_BUFFERPROXY_INTERNAL | |
| 22 | |
|
3088
fb1a30254d10
Apply issue #109 suggested bug fixes.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
23 #define PY_SSIZE_T_CLEAN |
|
2071
87541598228a
remove distracting "'PyGAME_C_API' defined but not used" gcc warnings from Pygame build
Lenard Lindstrom <len-l@telus.net>
parents:
1937
diff
changeset
|
24 #define NO_PYGAME_C_API |
| 860 | 25 #include "pygame.h" |
|
1578
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
26 #include "pgcompat.h" |
| 860 | 27 |
| 28 static PyObject* _bufferproxy_new (PyTypeObject *type, PyObject *args, | |
| 29 PyObject *kwds); | |
| 30 static void _bufferproxy_dealloc (PyBufferProxy *self); | |
| 31 static PyObject* _bufferproxy_get_dict (PyBufferProxy *self, void *closure); | |
|
898
424ef30fa1ea
Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
876
diff
changeset
|
32 static PyObject* _bufferproxy_get_raw (PyBufferProxy *self, void *closure); |
|
424ef30fa1ea
Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
876
diff
changeset
|
33 static PyObject* _bufferproxy_get_length (PyBufferProxy *self, void *closure); |
| 860 | 34 static PyObject* _bufferproxy_repr (PyBufferProxy *self); |
|
870
31fa129efd0f
Fixed Mask documentation. Added write() method to BufferProxy.
marcus
parents:
867
diff
changeset
|
35 static PyObject* _bufferproxy_write (PyBufferProxy *buffer, PyObject *args); |
| 860 | 36 |
| 37 /* Buffer methods */ | |
|
1578
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
38 #if PY3 |
|
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
39 static int _bufferproxy_getbuffer (PyBufferProxy *self, Py_buffer *view, |
|
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
40 int flags); |
|
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
41 static void _bufferproxy_releasebuffer (PyBufferProxy *self, Py_buffer *view); |
|
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
42 #else |
| 860 | 43 static Py_ssize_t _bufferproxy_getreadbuf (PyBufferProxy *buffer, |
| 44 Py_ssize_t _index, | |
| 45 const void **ptr); | |
| 46 static Py_ssize_t _bufferproxy_getwritebuf (PyBufferProxy *buffer, | |
| 47 Py_ssize_t _index, | |
| 48 const void **ptr); | |
| 49 static Py_ssize_t _bufferproxy_getsegcount (PyBufferProxy *buffer, | |
| 50 Py_ssize_t *lenp); | |
|
1578
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
51 #endif |
| 860 | 52 |
| 53 /* C API interfaces */ | |
| 54 static PyObject* PyBufferProxy_New (PyObject *parent, void *buffer, | |
| 55 Py_ssize_t length, PyObject *lock); | |
| 56 | |
| 57 /** | |
| 58 * Methods, which are bound to the PyBufferProxy type. | |
| 59 */ | |
| 60 static PyMethodDef _bufferproxy_methods[] = | |
| 61 { | |
|
870
31fa129efd0f
Fixed Mask documentation. Added write() method to BufferProxy.
marcus
parents:
867
diff
changeset
|
62 { "write", (PyCFunction) _bufferproxy_write, METH_VARARGS, |
| 906 | 63 "B.write (bufferproxy, buffer, offset) -> None\n\n" \ |
| 64 "Writes raw data to the bufferproxy.\n\n" \ | |
| 65 "Writes the raw data from buffer to the BufferProxy object, starting\n" \ | |
| 66 "at the specified offset within the BufferProxy.\n" \ | |
| 67 "If the length of the passed buffer exceeds the length of the\n" \ | |
| 68 "BufferProxy (reduced by the offset), an IndexError will be raised." }, | |
| 860 | 69 { NULL, NULL, 0, NULL } |
| 70 }; | |
| 71 | |
| 72 /** | |
| 73 * Getters and setters for the PyBufferProxy. | |
| 74 */ | |
| 75 static PyGetSetDef _bufferproxy_getsets[] = | |
| 76 { | |
| 77 { "__dict__", (getter) _bufferproxy_get_dict, NULL, NULL, NULL }, | |
|
870
31fa129efd0f
Fixed Mask documentation. Added write() method to BufferProxy.
marcus
parents:
867
diff
changeset
|
78 { "raw", (getter) _bufferproxy_get_raw, NULL, |
| 906 | 79 "The raw buffer data as string. The string may contain NUL bytes.", |
| 80 NULL }, | |
|
898
424ef30fa1ea
Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
876
diff
changeset
|
81 { "length", (getter) _bufferproxy_get_length, NULL, |
| 906 | 82 "The size of the buffer data in bytes.", NULL }, |
| 860 | 83 { NULL, NULL, NULL, NULL, NULL } |
| 84 }; | |
| 85 | |
| 86 | |
| 87 /** | |
| 88 * Buffer interface support for the PyBufferProxy. | |
| 89 */ | |
|
1578
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
90 #if PY3 |
|
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
91 static PyBufferProcs _bufferproxy_as_buffer = |
|
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
92 { |
|
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
93 (getbufferproc) _bufferproxy_getbuffer, |
|
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
94 (releasebufferproc) _bufferproxy_releasebuffer |
|
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
95 }; |
|
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
96 #else |
| 860 | 97 static PyBufferProcs _bufferproxy_as_buffer = |
| 98 { | |
|
1578
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
99 (readbufferproc) _bufferproxy_getreadbuf, |
|
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
100 (writebufferproc) _bufferproxy_getwritebuf, |
|
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
101 (segcountproc) _bufferproxy_getsegcount, |
|
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
102 NULL, |
|
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
103 #if PY_VERSION_HEX >= 0x02060000 |
|
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
104 NULL, |
|
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
105 NULL |
|
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
106 #endif |
| 860 | 107 }; |
|
1578
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
108 #endif |
| 860 | 109 |
| 110 static PyTypeObject PyBufferProxy_Type = | |
| 111 { | |
|
1578
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
112 TYPE_HEAD (NULL, 0) |
| 906 | 113 "pygame.bufferproxy.BufferProxy", /* tp_name */ |
|
870
31fa129efd0f
Fixed Mask documentation. Added write() method to BufferProxy.
marcus
parents:
867
diff
changeset
|
114 sizeof (PyBufferProxy), /* tp_basicsize */ |
| 860 | 115 0, /* tp_itemsize */ |
| 116 (destructor) _bufferproxy_dealloc, /* tp_dealloc */ | |
| 117 0, /* tp_print */ | |
| 118 0, /* tp_getattr */ | |
| 119 0, /* tp_setattr */ | |
| 120 0, /* tp_compare */ | |
|
867
a249a10980f0
Fixed bufferproxy stringifcation method. Fixed PixelArray's contains() method.
marcus
parents:
860
diff
changeset
|
121 (reprfunc) &_bufferproxy_repr, /* tp_repr */ |
| 860 | 122 0, /* tp_as_number */ |
| 123 0, /* tp_as_sequence */ | |
| 124 0, /* tp_as_mapping */ | |
| 125 0, /* tp_hash */ | |
| 126 0, /* tp_call */ | |
| 127 0, /* tp_str */ | |
| 128 0, /* tp_getattro */ | |
| 129 0, /* tp_setattro */ | |
| 130 &_bufferproxy_as_buffer, /* tp_as_buffer */ | |
| 131 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_WEAKREFS, | |
| 906 | 132 "BufferProxy () -> BufferProxy\n\n" \ |
| 133 "Creates a new, empty BufferProxy.\n\n" \ | |
| 134 "A BufferProxy usually should be constructed from C code, not Python.", | |
| 860 | 135 0, /* tp_traverse */ |
| 136 0, /* tp_clear */ | |
| 137 0, /* tp_richcompare */ | |
| 138 offsetof (PyBufferProxy, weakrefs), /* tp_weaklistoffset */ | |
| 139 0, /* tp_iter */ | |
| 140 0, /* tp_iternext */ | |
| 141 _bufferproxy_methods, /* tp_methods */ | |
| 142 0, /* tp_members */ | |
| 143 _bufferproxy_getsets, /* tp_getset */ | |
| 144 0, /* tp_base */ | |
| 145 0, /* tp_dict */ | |
| 146 0, /* tp_descr_get */ | |
| 147 0, /* tp_descr_set */ | |
| 148 offsetof (PyBufferProxy, dict), /* tp_dictoffset */ | |
| 149 0, /* tp_init */ | |
| 150 0, /* tp_alloc */ | |
|
870
31fa129efd0f
Fixed Mask documentation. Added write() method to BufferProxy.
marcus
parents:
867
diff
changeset
|
151 _bufferproxy_new, /* tp_new */ |
| 1593 | 152 #ifndef __SYMBIAN32__ |
| 860 | 153 0, /* tp_free */ |
| 154 0, /* tp_is_gc */ | |
| 155 0, /* tp_bases */ | |
| 156 0, /* tp_mro */ | |
| 157 0, /* tp_cache */ | |
| 158 0, /* tp_subclasses */ | |
| 159 0, /* tp_weaklist */ | |
| 160 0 /* tp_del */ | |
| 1593 | 161 #endif |
| 860 | 162 }; |
| 163 | |
| 164 /** | |
| 165 * Creates a new PyBufferProxy. | |
| 166 */ | |
| 167 static PyObject* | |
| 168 _bufferproxy_new (PyTypeObject *type, PyObject *args, PyObject *kwds) | |
| 169 { | |
| 170 PyBufferProxy *self = (PyBufferProxy *) type->tp_alloc (type, 0); | |
| 171 if (!self) | |
| 172 return NULL; | |
| 173 | |
| 174 self->weakrefs = NULL; | |
| 175 self->dict = NULL; | |
| 176 self->parent = NULL; | |
| 177 self->buffer = NULL; | |
| 178 self->lock = NULL; | |
| 179 return (PyObject *) self; | |
| 180 } | |
| 181 | |
| 182 /** | |
| 183 * Deallocates the PyBufferProxy and its members. | |
| 184 */ | |
| 185 static void | |
| 186 _bufferproxy_dealloc (PyBufferProxy *self) | |
| 187 { | |
| 188 if (self->weakrefs) | |
| 189 PyObject_ClearWeakRefs ((PyObject *) self); | |
|
1137
ec3ced33488f
Reworked locking code to be more strict about locking.
marcus
parents:
914
diff
changeset
|
190 |
|
ec3ced33488f
Reworked locking code to be more strict about locking.
marcus
parents:
914
diff
changeset
|
191 Py_XDECREF (self->lock); |
| 860 | 192 Py_XDECREF (self->dict); |
|
1578
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
193 Py_TYPE(self)->tp_free ((PyObject *) self); |
| 860 | 194 } |
| 195 | |
| 196 /**** Getter and setter access ****/ | |
| 197 | |
| 198 /** | |
| 199 * Getter for PyBufferProxy.__dict__. | |
| 200 */ | |
| 201 static PyObject* | |
| 202 _bufferproxy_get_dict (PyBufferProxy *self, void *closure) | |
| 203 { | |
| 204 if (!self->dict) | |
| 205 { | |
| 206 self->dict = PyDict_New (); | |
| 207 if (!self->dict) | |
| 208 return NULL; | |
| 209 } | |
| 210 | |
| 211 Py_INCREF (self->dict); | |
| 212 return self->dict; | |
| 213 } | |
| 214 | |
|
870
31fa129efd0f
Fixed Mask documentation. Added write() method to BufferProxy.
marcus
parents:
867
diff
changeset
|
215 /** |
|
31fa129efd0f
Fixed Mask documentation. Added write() method to BufferProxy.
marcus
parents:
867
diff
changeset
|
216 * Getter for PyBufferProxy.raw. |
|
31fa129efd0f
Fixed Mask documentation. Added write() method to BufferProxy.
marcus
parents:
867
diff
changeset
|
217 */ |
|
31fa129efd0f
Fixed Mask documentation. Added write() method to BufferProxy.
marcus
parents:
867
diff
changeset
|
218 static PyObject* |
|
898
424ef30fa1ea
Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
876
diff
changeset
|
219 _bufferproxy_get_raw (PyBufferProxy *self, void *closure) |
|
870
31fa129efd0f
Fixed Mask documentation. Added write() method to BufferProxy.
marcus
parents:
867
diff
changeset
|
220 { |
|
1578
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
221 return Bytes_FromStringAndSize (self->buffer, self->length); |
|
898
424ef30fa1ea
Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
876
diff
changeset
|
222 } |
|
424ef30fa1ea
Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
876
diff
changeset
|
223 |
|
424ef30fa1ea
Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
876
diff
changeset
|
224 /** |
|
424ef30fa1ea
Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
876
diff
changeset
|
225 * Getter for PyBufferProxy.length |
|
424ef30fa1ea
Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
876
diff
changeset
|
226 */ |
|
424ef30fa1ea
Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
876
diff
changeset
|
227 static PyObject* |
|
424ef30fa1ea
Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
876
diff
changeset
|
228 _bufferproxy_get_length (PyBufferProxy *self, void *closure) |
|
424ef30fa1ea
Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
876
diff
changeset
|
229 { |
|
424ef30fa1ea
Added numpy support for the sndarray module. BufferProxy now contains a length property, which indicates the length of the buffer in bytes.
marcus
parents:
876
diff
changeset
|
230 return PyInt_FromLong (self->length); |
|
870
31fa129efd0f
Fixed Mask documentation. Added write() method to BufferProxy.
marcus
parents:
867
diff
changeset
|
231 } |
|
31fa129efd0f
Fixed Mask documentation. Added write() method to BufferProxy.
marcus
parents:
867
diff
changeset
|
232 |
|
31fa129efd0f
Fixed Mask documentation. Added write() method to BufferProxy.
marcus
parents:
867
diff
changeset
|
233 /**** Methods ****/ |
|
31fa129efd0f
Fixed Mask documentation. Added write() method to BufferProxy.
marcus
parents:
867
diff
changeset
|
234 |
|
31fa129efd0f
Fixed Mask documentation. Added write() method to BufferProxy.
marcus
parents:
867
diff
changeset
|
235 /** |
|
31fa129efd0f
Fixed Mask documentation. Added write() method to BufferProxy.
marcus
parents:
867
diff
changeset
|
236 * Representation method. |
|
31fa129efd0f
Fixed Mask documentation. Added write() method to BufferProxy.
marcus
parents:
867
diff
changeset
|
237 */ |
| 860 | 238 static PyObject* |
| 239 _bufferproxy_repr (PyBufferProxy *self) | |
| 240 { | |
|
870
31fa129efd0f
Fixed Mask documentation. Added write() method to BufferProxy.
marcus
parents:
867
diff
changeset
|
241 /* zd is for Py_size_t which python < 2.5 doesn't have. */ |
| 860 | 242 #if PY_VERSION_HEX < 0x02050000 |
| 243 return PyString_FromFormat("<BufferProxy(%d)>", self->length); | |
| 244 #else | |
|
1578
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
245 return Text_FromFormat("<BufferProxy(%zd)>", self->length); |
| 860 | 246 #endif |
| 247 } | |
| 248 | |
|
870
31fa129efd0f
Fixed Mask documentation. Added write() method to BufferProxy.
marcus
parents:
867
diff
changeset
|
249 /** |
|
31fa129efd0f
Fixed Mask documentation. Added write() method to BufferProxy.
marcus
parents:
867
diff
changeset
|
250 * Writes raw data to the buffer. |
|
31fa129efd0f
Fixed Mask documentation. Added write() method to BufferProxy.
marcus
parents:
867
diff
changeset
|
251 */ |
|
31fa129efd0f
Fixed Mask documentation. Added write() method to BufferProxy.
marcus
parents:
867
diff
changeset
|
252 static PyObject* |
|
31fa129efd0f
Fixed Mask documentation. Added write() method to BufferProxy.
marcus
parents:
867
diff
changeset
|
253 _bufferproxy_write (PyBufferProxy *buffer, PyObject *args) |
|
31fa129efd0f
Fixed Mask documentation. Added write() method to BufferProxy.
marcus
parents:
867
diff
changeset
|
254 { |
|
31fa129efd0f
Fixed Mask documentation. Added write() method to BufferProxy.
marcus
parents:
867
diff
changeset
|
255 Py_ssize_t offset; |
|
31fa129efd0f
Fixed Mask documentation. Added write() method to BufferProxy.
marcus
parents:
867
diff
changeset
|
256 Py_ssize_t length; |
|
31fa129efd0f
Fixed Mask documentation. Added write() method to BufferProxy.
marcus
parents:
867
diff
changeset
|
257 char *buf; |
|
31fa129efd0f
Fixed Mask documentation. Added write() method to BufferProxy.
marcus
parents:
867
diff
changeset
|
258 |
|
3088
fb1a30254d10
Apply issue #109 suggested bug fixes.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
259 #if PY_VERSION_HEX < 0x02050000 |
|
fb1a30254d10
Apply issue #109 suggested bug fixes.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
260 #define FORMAT_STRING "s#i" |
|
fb1a30254d10
Apply issue #109 suggested bug fixes.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
261 #else |
|
fb1a30254d10
Apply issue #109 suggested bug fixes.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
262 #define FORMAT_STRING "s#n" |
|
fb1a30254d10
Apply issue #109 suggested bug fixes.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
263 #endif |
|
fb1a30254d10
Apply issue #109 suggested bug fixes.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
264 |
|
fb1a30254d10
Apply issue #109 suggested bug fixes.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
265 if (!PyArg_ParseTuple (args, FORMAT_STRING, &buf, &length, &offset)) |
|
870
31fa129efd0f
Fixed Mask documentation. Added write() method to BufferProxy.
marcus
parents:
867
diff
changeset
|
266 return NULL; |
|
31fa129efd0f
Fixed Mask documentation. Added write() method to BufferProxy.
marcus
parents:
867
diff
changeset
|
267 |
|
31fa129efd0f
Fixed Mask documentation. Added write() method to BufferProxy.
marcus
parents:
867
diff
changeset
|
268 if (offset + length > buffer->length) |
|
31fa129efd0f
Fixed Mask documentation. Added write() method to BufferProxy.
marcus
parents:
867
diff
changeset
|
269 { |
|
31fa129efd0f
Fixed Mask documentation. Added write() method to BufferProxy.
marcus
parents:
867
diff
changeset
|
270 return RAISE (PyExc_IndexError, "bytes to write exceed buffer size"); |
|
31fa129efd0f
Fixed Mask documentation. Added write() method to BufferProxy.
marcus
parents:
867
diff
changeset
|
271 } |
|
31fa129efd0f
Fixed Mask documentation. Added write() method to BufferProxy.
marcus
parents:
867
diff
changeset
|
272 |
| 914 | 273 memcpy (((Uint8 *)buffer->buffer) + offset, buf, (size_t) length); |
|
870
31fa129efd0f
Fixed Mask documentation. Added write() method to BufferProxy.
marcus
parents:
867
diff
changeset
|
274 |
|
31fa129efd0f
Fixed Mask documentation. Added write() method to BufferProxy.
marcus
parents:
867
diff
changeset
|
275 Py_RETURN_NONE; |
|
3088
fb1a30254d10
Apply issue #109 suggested bug fixes.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
276 |
|
fb1a30254d10
Apply issue #109 suggested bug fixes.
Lenard Lindstrom <len-l@telus.net>
parents:
2120
diff
changeset
|
277 #undef FORMAT_STRING |
|
870
31fa129efd0f
Fixed Mask documentation. Added write() method to BufferProxy.
marcus
parents:
867
diff
changeset
|
278 } |
|
31fa129efd0f
Fixed Mask documentation. Added write() method to BufferProxy.
marcus
parents:
867
diff
changeset
|
279 |
| 860 | 280 /**** Buffer interfaces ****/ |
| 281 | |
|
1578
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
282 #if PY3 |
|
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
283 static int |
|
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
284 _bufferproxy_getbuffer (PyBufferProxy *self, Py_buffer *view, int flags) |
|
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
285 { |
|
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
286 if (!view) |
|
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
287 return 0; |
|
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
288 Py_INCREF (self); /* Guarantee that the object does not get destroyed */ |
|
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
289 return PyBuffer_FillInfo (view, (PyObject*)self, self->buffer, |
|
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
290 self->length, 0, flags); |
|
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
291 } |
|
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
292 |
|
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
293 static void |
|
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
294 _bufferproxy_releasebuffer (PyBufferProxy *self, Py_buffer *view) |
|
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
295 { |
|
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
296 Py_DECREF (self); |
|
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
297 } |
|
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
298 #else /* PY3 */ |
| 860 | 299 static Py_ssize_t |
| 300 _bufferproxy_getreadbuf (PyBufferProxy *buffer, Py_ssize_t _index, | |
| 301 const void **ptr) | |
| 302 { | |
| 303 if (_index != 0) | |
| 304 { | |
| 305 PyErr_SetString (PyExc_SystemError, | |
| 306 "Accessing non-existent buffer segment"); | |
| 307 return -1; | |
| 308 } | |
| 309 | |
| 310 if (!buffer->parent) | |
| 311 { | |
| 312 *ptr = NULL; | |
| 313 return 0; | |
| 314 } | |
| 315 | |
| 316 *ptr = buffer->buffer; | |
| 317 return buffer->length; | |
| 318 } | |
| 319 | |
| 320 static Py_ssize_t | |
| 321 _bufferproxy_getwritebuf (PyBufferProxy *buffer, Py_ssize_t _index, | |
| 322 const void **ptr) | |
| 323 { | |
| 324 if (_index != 0) | |
| 325 { | |
| 326 PyErr_SetString (PyExc_SystemError, | |
| 327 "Accessing non-existent array segment"); | |
| 328 return -1; | |
| 329 } | |
| 330 | |
| 331 if (!buffer->parent) | |
| 332 { | |
| 333 *ptr = NULL; | |
| 334 return 0; | |
| 335 } | |
| 336 | |
| 337 *ptr = buffer->buffer; | |
| 338 return buffer->length; | |
| 339 } | |
| 340 | |
| 341 static Py_ssize_t | |
| 342 _bufferproxy_getsegcount (PyBufferProxy *buffer, Py_ssize_t *lenp) | |
| 343 { | |
| 344 if (!buffer->parent) | |
| 345 { | |
| 346 *lenp = 0; | |
| 347 return 0; | |
| 348 } | |
| 349 | |
| 350 if (lenp) | |
| 351 *lenp = buffer->length; | |
| 352 return 1; | |
| 353 } | |
|
1578
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
354 #endif /* PY3 */ |
| 860 | 355 |
| 356 static PyObject* | |
| 357 PyBufferProxy_New (PyObject *parent, void *buffer, Py_ssize_t length, | |
| 358 PyObject *lock) | |
| 359 { | |
| 360 PyBufferProxy *buf; | |
| 361 | |
| 362 buf = (PyBufferProxy *) _bufferproxy_new (&PyBufferProxy_Type, NULL, NULL); | |
| 363 | |
| 364 if (!buf) | |
| 365 return NULL; | |
| 366 buf->buffer = buffer; | |
| 367 buf->length = length; | |
| 368 buf->lock = lock; | |
| 369 buf->parent = parent; | |
| 370 return (PyObject *) buf; | |
| 371 } | |
| 372 | |
|
1578
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
373 /*DOC*/ static char _bufferproxy_doc[] = |
|
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
374 /*DOC*/ "A generic proxy module that can spend arbitrary " \ |
|
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
375 /*DOC*/ "objects a buffer interface"; |
|
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
376 |
|
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
377 MODINIT_DEFINE (bufferproxy) |
| 860 | 378 { |
| 379 PyObject *module; | |
| 380 PyObject *dict; | |
| 381 PyObject *apiobj; | |
|
1578
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
382 int ecode; |
| 860 | 383 static void* c_api[PYGAMEAPI_BUFFERPROXY_NUMSLOTS]; |
| 384 | |
|
1578
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
385 #if PY3 |
|
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
386 static struct PyModuleDef _module = { |
|
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
387 PyModuleDef_HEAD_INIT, |
|
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
388 "bufferproxy", |
|
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
389 _bufferproxy_doc, |
|
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
390 -1, |
|
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
391 _bufferproxy_methods, |
|
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
392 NULL, NULL, NULL, NULL |
|
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
393 }; |
|
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
394 #endif |
|
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
395 |
| 860 | 396 if (PyType_Ready (&PyBufferProxy_Type) < 0) |
|
1578
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
397 MODINIT_ERROR; |
| 860 | 398 |
| 399 /* create the module */ | |
|
1578
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
400 #if PY3 |
|
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
401 module = PyModule_Create (&_module); |
|
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
402 #else |
| 1593 | 403 module = Py_InitModule3 (MODPREFIX "bufferproxy", NULL, _bufferproxy_doc); |
|
1578
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
404 #endif |
| 860 | 405 PyBufferProxy_Type.tp_getattro = PyObject_GenericGetAttr; |
| 406 Py_INCREF (&PyBufferProxy_Type); | |
|
1578
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
407 if (PyModule_AddObject (module, "BufferProxy", |
|
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
408 (PyObject *)&PyBufferProxy_Type) == -1) { |
|
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
409 Py_DECREF ((PyObject *)&PyBufferProxy_Type); |
|
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
410 DECREF_MOD (module); |
|
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
411 MODINIT_ERROR; |
|
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
412 } |
| 860 | 413 dict = PyModule_GetDict (module); |
| 414 | |
| 415 c_api[0] = &PyBufferProxy_Type; | |
| 416 c_api[1] = PyBufferProxy_New; | |
|
2120
42e2bde1a12c
Use capsule objects in preference to cobject objects. This allows Pygame to build an run from Python 3.2, which has to cobjects.
Lenard Lindstrom <len-l@telus.net>
parents:
2071
diff
changeset
|
417 apiobj = encapsulate_api (c_api, "bufferproxy"); |
|
1578
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
418 if (apiobj == NULL) { |
|
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
419 DECREF_MOD (module); |
|
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
420 MODINIT_ERROR; |
|
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
421 } |
|
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
422 ecode = PyDict_SetItemString (dict, PYGAMEAPI_LOCAL_ENTRY, apiobj); |
| 860 | 423 Py_DECREF (apiobj); |
|
1578
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
424 if (ecode == -1) { |
|
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
425 DECREF_MOD (module); |
|
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
426 MODINIT_ERROR; |
|
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
427 } |
|
c0d170c1e636
all standard modules build with Python 3.1. Optional movie module adapted. setup.py skips unsupported files for Python 3
Lenard Lindstrom <len-l@telus.net>
parents:
1137
diff
changeset
|
428 MODINIT_RETURN (module); |
| 860 | 429 } |
