Mercurial > pygame
annotate src/bufferproxy.c @ 1849:301bc61643a9 math_module
merged changes from trunk
| author | lorenz |
|---|---|
| date | Mon, 16 Nov 2009 18:31:40 +0000 |
| parents | fb9540cdf5e5 |
| children | 87541598228a |
| 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 | |
| 23 #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
|
24 #include "pgcompat.h" |
| 860 | 25 |
| 26 static PyObject* _bufferproxy_new (PyTypeObject *type, PyObject *args, | |
| 27 PyObject *kwds); | |
| 28 static void _bufferproxy_dealloc (PyBufferProxy *self); | |
| 29 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
|
30 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
|
31 static PyObject* _bufferproxy_get_length (PyBufferProxy *self, void *closure); |
| 860 | 32 static PyObject* _bufferproxy_repr (PyBufferProxy *self); |
|
870
31fa129efd0f
Fixed Mask documentation. Added write() method to BufferProxy.
marcus
parents:
867
diff
changeset
|
33 static PyObject* _bufferproxy_write (PyBufferProxy *buffer, PyObject *args); |
| 860 | 34 |
| 35 /* 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
|
36 #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
|
37 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
|
38 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
|
39 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
|
40 #else |
| 860 | 41 static Py_ssize_t _bufferproxy_getreadbuf (PyBufferProxy *buffer, |
| 42 Py_ssize_t _index, | |
| 43 const void **ptr); | |
| 44 static Py_ssize_t _bufferproxy_getwritebuf (PyBufferProxy *buffer, | |
| 45 Py_ssize_t _index, | |
| 46 const void **ptr); | |
| 47 static Py_ssize_t _bufferproxy_getsegcount (PyBufferProxy *buffer, | |
| 48 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
|
49 #endif |
| 860 | 50 |
| 51 /* C API interfaces */ | |
| 52 static PyObject* PyBufferProxy_New (PyObject *parent, void *buffer, | |
| 53 Py_ssize_t length, PyObject *lock); | |
| 54 | |
| 55 /** | |
| 56 * Methods, which are bound to the PyBufferProxy type. | |
| 57 */ | |
| 58 static PyMethodDef _bufferproxy_methods[] = | |
| 59 { | |
|
870
31fa129efd0f
Fixed Mask documentation. Added write() method to BufferProxy.
marcus
parents:
867
diff
changeset
|
60 { "write", (PyCFunction) _bufferproxy_write, METH_VARARGS, |
| 906 | 61 "B.write (bufferproxy, buffer, offset) -> None\n\n" \ |
| 62 "Writes raw data to the bufferproxy.\n\n" \ | |
| 63 "Writes the raw data from buffer to the BufferProxy object, starting\n" \ | |
| 64 "at the specified offset within the BufferProxy.\n" \ | |
| 65 "If the length of the passed buffer exceeds the length of the\n" \ | |
| 66 "BufferProxy (reduced by the offset), an IndexError will be raised." }, | |
| 860 | 67 { NULL, NULL, 0, NULL } |
| 68 }; | |
| 69 | |
| 70 /** | |
| 71 * Getters and setters for the PyBufferProxy. | |
| 72 */ | |
| 73 static PyGetSetDef _bufferproxy_getsets[] = | |
| 74 { | |
| 75 { "__dict__", (getter) _bufferproxy_get_dict, NULL, NULL, NULL }, | |
|
870
31fa129efd0f
Fixed Mask documentation. Added write() method to BufferProxy.
marcus
parents:
867
diff
changeset
|
76 { "raw", (getter) _bufferproxy_get_raw, NULL, |
| 906 | 77 "The raw buffer data as string. The string may contain NUL bytes.", |
| 78 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
|
79 { "length", (getter) _bufferproxy_get_length, NULL, |
| 906 | 80 "The size of the buffer data in bytes.", NULL }, |
| 860 | 81 { NULL, NULL, NULL, NULL, NULL } |
| 82 }; | |
| 83 | |
| 84 | |
| 85 /** | |
| 86 * Buffer interface support for the PyBufferProxy. | |
| 87 */ | |
|
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
|
88 #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
|
89 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
|
90 { |
|
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 (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
|
92 (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
|
93 }; |
|
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 #else |
| 860 | 95 static PyBufferProcs _bufferproxy_as_buffer = |
| 96 { | |
|
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
|
97 (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
|
98 (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
|
99 (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
|
100 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
|
101 #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
|
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 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
|
104 #endif |
| 860 | 105 }; |
|
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
|
106 #endif |
| 860 | 107 |
| 108 static PyTypeObject PyBufferProxy_Type = | |
| 109 { | |
|
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
|
110 TYPE_HEAD (NULL, 0) |
| 906 | 111 "pygame.bufferproxy.BufferProxy", /* tp_name */ |
|
870
31fa129efd0f
Fixed Mask documentation. Added write() method to BufferProxy.
marcus
parents:
867
diff
changeset
|
112 sizeof (PyBufferProxy), /* tp_basicsize */ |
| 860 | 113 0, /* tp_itemsize */ |
| 114 (destructor) _bufferproxy_dealloc, /* tp_dealloc */ | |
| 115 0, /* tp_print */ | |
| 116 0, /* tp_getattr */ | |
| 117 0, /* tp_setattr */ | |
| 118 0, /* tp_compare */ | |
|
867
a249a10980f0
Fixed bufferproxy stringifcation method. Fixed PixelArray's contains() method.
marcus
parents:
860
diff
changeset
|
119 (reprfunc) &_bufferproxy_repr, /* tp_repr */ |
| 860 | 120 0, /* tp_as_number */ |
| 121 0, /* tp_as_sequence */ | |
| 122 0, /* tp_as_mapping */ | |
| 123 0, /* tp_hash */ | |
| 124 0, /* tp_call */ | |
| 125 0, /* tp_str */ | |
| 126 0, /* tp_getattro */ | |
| 127 0, /* tp_setattro */ | |
| 128 &_bufferproxy_as_buffer, /* tp_as_buffer */ | |
| 129 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_WEAKREFS, | |
| 906 | 130 "BufferProxy () -> BufferProxy\n\n" \ |
| 131 "Creates a new, empty BufferProxy.\n\n" \ | |
| 132 "A BufferProxy usually should be constructed from C code, not Python.", | |
| 860 | 133 0, /* tp_traverse */ |
| 134 0, /* tp_clear */ | |
| 135 0, /* tp_richcompare */ | |
| 136 offsetof (PyBufferProxy, weakrefs), /* tp_weaklistoffset */ | |
| 137 0, /* tp_iter */ | |
| 138 0, /* tp_iternext */ | |
| 139 _bufferproxy_methods, /* tp_methods */ | |
| 140 0, /* tp_members */ | |
| 141 _bufferproxy_getsets, /* tp_getset */ | |
| 142 0, /* tp_base */ | |
| 143 0, /* tp_dict */ | |
| 144 0, /* tp_descr_get */ | |
| 145 0, /* tp_descr_set */ | |
| 146 offsetof (PyBufferProxy, dict), /* tp_dictoffset */ | |
| 147 0, /* tp_init */ | |
| 148 0, /* tp_alloc */ | |
|
870
31fa129efd0f
Fixed Mask documentation. Added write() method to BufferProxy.
marcus
parents:
867
diff
changeset
|
149 _bufferproxy_new, /* tp_new */ |
| 1593 | 150 #ifndef __SYMBIAN32__ |
| 860 | 151 0, /* tp_free */ |
| 152 0, /* tp_is_gc */ | |
| 153 0, /* tp_bases */ | |
| 154 0, /* tp_mro */ | |
| 155 0, /* tp_cache */ | |
| 156 0, /* tp_subclasses */ | |
| 157 0, /* tp_weaklist */ | |
| 158 0 /* tp_del */ | |
| 1593 | 159 #endif |
| 860 | 160 }; |
| 161 | |
| 162 /** | |
| 163 * Creates a new PyBufferProxy. | |
| 164 */ | |
| 165 static PyObject* | |
| 166 _bufferproxy_new (PyTypeObject *type, PyObject *args, PyObject *kwds) | |
| 167 { | |
| 168 PyBufferProxy *self = (PyBufferProxy *) type->tp_alloc (type, 0); | |
| 169 if (!self) | |
| 170 return NULL; | |
| 171 | |
| 172 self->weakrefs = NULL; | |
| 173 self->dict = NULL; | |
| 174 self->parent = NULL; | |
| 175 self->buffer = NULL; | |
| 176 self->lock = NULL; | |
| 177 return (PyObject *) self; | |
| 178 } | |
| 179 | |
| 180 /** | |
| 181 * Deallocates the PyBufferProxy and its members. | |
| 182 */ | |
| 183 static void | |
| 184 _bufferproxy_dealloc (PyBufferProxy *self) | |
| 185 { | |
| 186 if (self->weakrefs) | |
| 187 PyObject_ClearWeakRefs ((PyObject *) self); | |
|
1137
ec3ced33488f
Reworked locking code to be more strict about locking.
marcus
parents:
914
diff
changeset
|
188 |
|
ec3ced33488f
Reworked locking code to be more strict about locking.
marcus
parents:
914
diff
changeset
|
189 Py_XDECREF (self->lock); |
| 860 | 190 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
|
191 Py_TYPE(self)->tp_free ((PyObject *) self); |
| 860 | 192 } |
| 193 | |
| 194 /**** Getter and setter access ****/ | |
| 195 | |
| 196 /** | |
| 197 * Getter for PyBufferProxy.__dict__. | |
| 198 */ | |
| 199 static PyObject* | |
| 200 _bufferproxy_get_dict (PyBufferProxy *self, void *closure) | |
| 201 { | |
| 202 if (!self->dict) | |
| 203 { | |
| 204 self->dict = PyDict_New (); | |
| 205 if (!self->dict) | |
| 206 return NULL; | |
| 207 } | |
| 208 | |
| 209 Py_INCREF (self->dict); | |
| 210 return self->dict; | |
| 211 } | |
| 212 | |
|
870
31fa129efd0f
Fixed Mask documentation. Added write() method to BufferProxy.
marcus
parents:
867
diff
changeset
|
213 /** |
|
31fa129efd0f
Fixed Mask documentation. Added write() method to BufferProxy.
marcus
parents:
867
diff
changeset
|
214 * Getter for PyBufferProxy.raw. |
|
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 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
|
217 _bufferproxy_get_raw (PyBufferProxy *self, void *closure) |
|
870
31fa129efd0f
Fixed Mask documentation. Added write() method to BufferProxy.
marcus
parents:
867
diff
changeset
|
218 { |
|
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
|
219 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
|
220 } |
|
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
|
221 |
|
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 * 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
|
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 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
|
226 _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
|
227 { |
|
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 return PyInt_FromLong (self->length); |
|
870
31fa129efd0f
Fixed Mask documentation. Added write() method to BufferProxy.
marcus
parents:
867
diff
changeset
|
229 } |
|
31fa129efd0f
Fixed Mask documentation. Added write() method to BufferProxy.
marcus
parents:
867
diff
changeset
|
230 |
|
31fa129efd0f
Fixed Mask documentation. Added write() method to BufferProxy.
marcus
parents:
867
diff
changeset
|
231 /**** Methods ****/ |
|
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 /** |
|
31fa129efd0f
Fixed Mask documentation. Added write() method to BufferProxy.
marcus
parents:
867
diff
changeset
|
234 * Representation method. |
|
31fa129efd0f
Fixed Mask documentation. Added write() method to BufferProxy.
marcus
parents:
867
diff
changeset
|
235 */ |
| 860 | 236 static PyObject* |
| 237 _bufferproxy_repr (PyBufferProxy *self) | |
| 238 { | |
|
870
31fa129efd0f
Fixed Mask documentation. Added write() method to BufferProxy.
marcus
parents:
867
diff
changeset
|
239 /* zd is for Py_size_t which python < 2.5 doesn't have. */ |
| 860 | 240 #if PY_VERSION_HEX < 0x02050000 |
| 241 return PyString_FromFormat("<BufferProxy(%d)>", self->length); | |
| 242 #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
|
243 return Text_FromFormat("<BufferProxy(%zd)>", self->length); |
| 860 | 244 #endif |
| 245 } | |
| 246 | |
|
870
31fa129efd0f
Fixed Mask documentation. Added write() method to BufferProxy.
marcus
parents:
867
diff
changeset
|
247 /** |
|
31fa129efd0f
Fixed Mask documentation. Added write() method to BufferProxy.
marcus
parents:
867
diff
changeset
|
248 * Writes raw data to the buffer. |
|
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 static PyObject* |
|
31fa129efd0f
Fixed Mask documentation. Added write() method to BufferProxy.
marcus
parents:
867
diff
changeset
|
251 _bufferproxy_write (PyBufferProxy *buffer, PyObject *args) |
|
31fa129efd0f
Fixed Mask documentation. Added write() method to BufferProxy.
marcus
parents:
867
diff
changeset
|
252 { |
|
31fa129efd0f
Fixed Mask documentation. Added write() method to BufferProxy.
marcus
parents:
867
diff
changeset
|
253 Py_ssize_t offset; |
|
31fa129efd0f
Fixed Mask documentation. Added write() method to BufferProxy.
marcus
parents:
867
diff
changeset
|
254 Py_ssize_t length; |
|
31fa129efd0f
Fixed Mask documentation. Added write() method to BufferProxy.
marcus
parents:
867
diff
changeset
|
255 char *buf; |
|
31fa129efd0f
Fixed Mask documentation. Added write() method to BufferProxy.
marcus
parents:
867
diff
changeset
|
256 |
|
31fa129efd0f
Fixed Mask documentation. Added write() method to BufferProxy.
marcus
parents:
867
diff
changeset
|
257 if (!PyArg_ParseTuple (args, "s#i", &buf, &length, &offset)) |
|
31fa129efd0f
Fixed Mask documentation. Added write() method to BufferProxy.
marcus
parents:
867
diff
changeset
|
258 return NULL; |
|
31fa129efd0f
Fixed Mask documentation. Added write() method to BufferProxy.
marcus
parents:
867
diff
changeset
|
259 |
|
31fa129efd0f
Fixed Mask documentation. Added write() method to BufferProxy.
marcus
parents:
867
diff
changeset
|
260 if (offset + length > buffer->length) |
|
31fa129efd0f
Fixed Mask documentation. Added write() method to BufferProxy.
marcus
parents:
867
diff
changeset
|
261 { |
|
31fa129efd0f
Fixed Mask documentation. Added write() method to BufferProxy.
marcus
parents:
867
diff
changeset
|
262 return RAISE (PyExc_IndexError, "bytes to write exceed buffer size"); |
|
31fa129efd0f
Fixed Mask documentation. Added write() method to BufferProxy.
marcus
parents:
867
diff
changeset
|
263 } |
|
31fa129efd0f
Fixed Mask documentation. Added write() method to BufferProxy.
marcus
parents:
867
diff
changeset
|
264 |
| 914 | 265 memcpy (((Uint8 *)buffer->buffer) + offset, buf, (size_t) length); |
|
870
31fa129efd0f
Fixed Mask documentation. Added write() method to BufferProxy.
marcus
parents:
867
diff
changeset
|
266 |
|
31fa129efd0f
Fixed Mask documentation. Added write() method to BufferProxy.
marcus
parents:
867
diff
changeset
|
267 Py_RETURN_NONE; |
|
31fa129efd0f
Fixed Mask documentation. Added write() method to BufferProxy.
marcus
parents:
867
diff
changeset
|
268 } |
|
31fa129efd0f
Fixed Mask documentation. Added write() method to BufferProxy.
marcus
parents:
867
diff
changeset
|
269 |
| 860 | 270 /**** Buffer interfaces ****/ |
| 271 | |
|
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
|
272 #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
|
273 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
|
274 _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
|
275 { |
|
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
|
276 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
|
277 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
|
278 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
|
279 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
|
280 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
|
281 } |
|
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 |
|
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 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
|
284 _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
|
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 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
|
287 } |
|
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 #else /* PY3 */ |
| 860 | 289 static Py_ssize_t |
| 290 _bufferproxy_getreadbuf (PyBufferProxy *buffer, Py_ssize_t _index, | |
| 291 const void **ptr) | |
| 292 { | |
| 293 if (_index != 0) | |
| 294 { | |
| 295 PyErr_SetString (PyExc_SystemError, | |
| 296 "Accessing non-existent buffer segment"); | |
| 297 return -1; | |
| 298 } | |
| 299 | |
| 300 if (!buffer->parent) | |
| 301 { | |
| 302 *ptr = NULL; | |
| 303 return 0; | |
| 304 } | |
| 305 | |
| 306 *ptr = buffer->buffer; | |
| 307 return buffer->length; | |
| 308 } | |
| 309 | |
| 310 static Py_ssize_t | |
| 311 _bufferproxy_getwritebuf (PyBufferProxy *buffer, Py_ssize_t _index, | |
| 312 const void **ptr) | |
| 313 { | |
| 314 if (_index != 0) | |
| 315 { | |
| 316 PyErr_SetString (PyExc_SystemError, | |
| 317 "Accessing non-existent array segment"); | |
| 318 return -1; | |
| 319 } | |
| 320 | |
| 321 if (!buffer->parent) | |
| 322 { | |
| 323 *ptr = NULL; | |
| 324 return 0; | |
| 325 } | |
| 326 | |
| 327 *ptr = buffer->buffer; | |
| 328 return buffer->length; | |
| 329 } | |
| 330 | |
| 331 static Py_ssize_t | |
| 332 _bufferproxy_getsegcount (PyBufferProxy *buffer, Py_ssize_t *lenp) | |
| 333 { | |
| 334 if (!buffer->parent) | |
| 335 { | |
| 336 *lenp = 0; | |
| 337 return 0; | |
| 338 } | |
| 339 | |
| 340 if (lenp) | |
| 341 *lenp = buffer->length; | |
| 342 return 1; | |
| 343 } | |
|
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
|
344 #endif /* PY3 */ |
| 860 | 345 |
| 346 static PyObject* | |
| 347 PyBufferProxy_New (PyObject *parent, void *buffer, Py_ssize_t length, | |
| 348 PyObject *lock) | |
| 349 { | |
| 350 PyBufferProxy *buf; | |
| 351 | |
| 352 buf = (PyBufferProxy *) _bufferproxy_new (&PyBufferProxy_Type, NULL, NULL); | |
| 353 | |
| 354 if (!buf) | |
| 355 return NULL; | |
| 356 buf->buffer = buffer; | |
| 357 buf->length = length; | |
| 358 buf->lock = lock; | |
| 359 buf->parent = parent; | |
| 360 return (PyObject *) buf; | |
| 361 } | |
| 362 | |
|
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
|
363 /*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
|
364 /*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
|
365 /*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
|
366 |
|
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
|
367 MODINIT_DEFINE (bufferproxy) |
| 860 | 368 { |
| 369 PyObject *module; | |
| 370 PyObject *dict; | |
| 371 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
|
372 int ecode; |
| 860 | 373 static void* c_api[PYGAMEAPI_BUFFERPROXY_NUMSLOTS]; |
| 374 | |
|
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
|
375 #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
|
376 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
|
377 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
|
378 "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
|
379 _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
|
380 -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
|
381 _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
|
382 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
|
383 }; |
|
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
|
384 #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
|
385 |
| 860 | 386 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
|
387 MODINIT_ERROR; |
| 860 | 388 |
| 389 /* 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
|
390 #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
|
391 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
|
392 #else |
| 1593 | 393 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
|
394 #endif |
| 860 | 395 PyBufferProxy_Type.tp_getattro = PyObject_GenericGetAttr; |
| 396 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
|
397 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
|
398 (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
|
399 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
|
400 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
|
401 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
|
402 } |
| 860 | 403 dict = PyModule_GetDict (module); |
| 404 | |
| 405 c_api[0] = &PyBufferProxy_Type; | |
| 406 c_api[1] = PyBufferProxy_New; | |
| 407 apiobj = PyCObject_FromVoidPtr (c_api, NULL); | |
|
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
|
408 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
|
409 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
|
410 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
|
411 } |
|
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 ecode = PyDict_SetItemString (dict, PYGAMEAPI_LOCAL_ENTRY, apiobj); |
| 860 | 413 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
|
414 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
|
415 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
|
416 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
|
417 } |
|
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 MODINIT_RETURN (module); |
| 860 | 419 } |
