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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
860
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
1 /*
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
2 pygame - Python Game Library
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
3 Copyright (C) 2007 Marcus von Appen
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
4
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
6 modify it under the terms of the GNU Library General Public
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
8 version 2 of the License, or (at your option) any later version.
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
9
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
13 Library General Public License for more details.
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
14
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
15 You should have received a copy of the GNU Library General Public
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
16 License along with this library; if not, write to the Free
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
18
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
19 */
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
20
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
21 #define PYGAMEAPI_BUFFERPROXY_INTERNAL
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
22
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
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
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
25
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
26 static PyObject* _bufferproxy_new (PyTypeObject *type, PyObject *args,
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
27 PyObject *kwds);
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
28 static void _bufferproxy_dealloc (PyBufferProxy *self);
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
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
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
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
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
34
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
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
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
41 static Py_ssize_t _bufferproxy_getreadbuf (PyBufferProxy *buffer,
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
42 Py_ssize_t _index,
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
43 const void **ptr);
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
44 static Py_ssize_t _bufferproxy_getwritebuf (PyBufferProxy *buffer,
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
45 Py_ssize_t _index,
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
46 const void **ptr);
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
47 static Py_ssize_t _bufferproxy_getsegcount (PyBufferProxy *buffer,
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
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
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
50
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
51 /* C API interfaces */
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
52 static PyObject* PyBufferProxy_New (PyObject *parent, void *buffer,
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
53 Py_ssize_t length, PyObject *lock);
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
54
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
55 /**
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
56 * Methods, which are bound to the PyBufferProxy type.
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
57 */
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
58 static PyMethodDef _bufferproxy_methods[] =
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
59 {
870
31fa129efd0f Fixed Mask documentation. Added write() method to BufferProxy.
marcus
parents: 867
diff changeset
60 { "write", (PyCFunction) _bufferproxy_write, METH_VARARGS,
906
d971d169536c Improved BufferProxy docs.
marcus
parents: 898
diff changeset
61 "B.write (bufferproxy, buffer, offset) -> None\n\n" \
d971d169536c Improved BufferProxy docs.
marcus
parents: 898
diff changeset
62 "Writes raw data to the bufferproxy.\n\n" \
d971d169536c Improved BufferProxy docs.
marcus
parents: 898
diff changeset
63 "Writes the raw data from buffer to the BufferProxy object, starting\n" \
d971d169536c Improved BufferProxy docs.
marcus
parents: 898
diff changeset
64 "at the specified offset within the BufferProxy.\n" \
d971d169536c Improved BufferProxy docs.
marcus
parents: 898
diff changeset
65 "If the length of the passed buffer exceeds the length of the\n" \
d971d169536c Improved BufferProxy docs.
marcus
parents: 898
diff changeset
66 "BufferProxy (reduced by the offset), an IndexError will be raised." },
860
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
67 { NULL, NULL, 0, NULL }
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
68 };
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
69
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
70 /**
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
71 * Getters and setters for the PyBufferProxy.
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
72 */
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
73 static PyGetSetDef _bufferproxy_getsets[] =
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
74 {
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
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
d971d169536c Improved BufferProxy docs.
marcus
parents: 898
diff changeset
77 "The raw buffer data as string. The string may contain NUL bytes.",
d971d169536c Improved BufferProxy docs.
marcus
parents: 898
diff changeset
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
d971d169536c Improved BufferProxy docs.
marcus
parents: 898
diff changeset
80 "The size of the buffer data in bytes.", NULL },
860
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
81 { NULL, NULL, NULL, NULL, NULL }
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
82 };
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
83
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
84
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
85 /**
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
86 * Buffer interface support for the PyBufferProxy.
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
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
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
95 static PyBufferProcs _bufferproxy_as_buffer =
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
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
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
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
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
107
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
108 static PyTypeObject PyBufferProxy_Type =
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
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
d971d169536c Improved BufferProxy docs.
marcus
parents: 898
diff changeset
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
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
113 0, /* tp_itemsize */
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
114 (destructor) _bufferproxy_dealloc, /* tp_dealloc */
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
115 0, /* tp_print */
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
116 0, /* tp_getattr */
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
117 0, /* tp_setattr */
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
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
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
120 0, /* tp_as_number */
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
121 0, /* tp_as_sequence */
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
122 0, /* tp_as_mapping */
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
123 0, /* tp_hash */
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
124 0, /* tp_call */
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
125 0, /* tp_str */
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
126 0, /* tp_getattro */
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
127 0, /* tp_setattro */
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
128 &_bufferproxy_as_buffer, /* tp_as_buffer */
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
129 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_WEAKREFS,
906
d971d169536c Improved BufferProxy docs.
marcus
parents: 898
diff changeset
130 "BufferProxy () -> BufferProxy\n\n" \
d971d169536c Improved BufferProxy docs.
marcus
parents: 898
diff changeset
131 "Creates a new, empty BufferProxy.\n\n" \
d971d169536c Improved BufferProxy docs.
marcus
parents: 898
diff changeset
132 "A BufferProxy usually should be constructed from C code, not Python.",
860
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
133 0, /* tp_traverse */
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
134 0, /* tp_clear */
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
135 0, /* tp_richcompare */
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
136 offsetof (PyBufferProxy, weakrefs), /* tp_weaklistoffset */
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
137 0, /* tp_iter */
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
138 0, /* tp_iternext */
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
139 _bufferproxy_methods, /* tp_methods */
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
140 0, /* tp_members */
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
141 _bufferproxy_getsets, /* tp_getset */
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
142 0, /* tp_base */
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
143 0, /* tp_dict */
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
144 0, /* tp_descr_get */
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
145 0, /* tp_descr_set */
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
146 offsetof (PyBufferProxy, dict), /* tp_dictoffset */
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
147 0, /* tp_init */
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
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
fb9540cdf5e5 symbian branch merging
Rene Dudfield <renesd@gmail.com>
parents: 1578
diff changeset
150 #ifndef __SYMBIAN32__
860
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
151 0, /* tp_free */
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
152 0, /* tp_is_gc */
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
153 0, /* tp_bases */
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
154 0, /* tp_mro */
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
155 0, /* tp_cache */
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
156 0, /* tp_subclasses */
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
157 0, /* tp_weaklist */
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
158 0 /* tp_del */
1593
fb9540cdf5e5 symbian branch merging
Rene Dudfield <renesd@gmail.com>
parents: 1578
diff changeset
159 #endif
860
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
160 };
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
161
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
162 /**
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
163 * Creates a new PyBufferProxy.
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
164 */
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
165 static PyObject*
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
166 _bufferproxy_new (PyTypeObject *type, PyObject *args, PyObject *kwds)
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
167 {
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
168 PyBufferProxy *self = (PyBufferProxy *) type->tp_alloc (type, 0);
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
169 if (!self)
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
170 return NULL;
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
171
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
172 self->weakrefs = NULL;
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
173 self->dict = NULL;
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
174 self->parent = NULL;
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
175 self->buffer = NULL;
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
176 self->lock = NULL;
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
177 return (PyObject *) self;
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
178 }
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
179
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
180 /**
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
181 * Deallocates the PyBufferProxy and its members.
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
182 */
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
183 static void
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
184 _bufferproxy_dealloc (PyBufferProxy *self)
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
185 {
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
186 if (self->weakrefs)
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
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
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
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
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
192 }
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
193
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
194 /**** Getter and setter access ****/
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
195
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
196 /**
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
197 * Getter for PyBufferProxy.__dict__.
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
198 */
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
199 static PyObject*
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
200 _bufferproxy_get_dict (PyBufferProxy *self, void *closure)
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
201 {
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
202 if (!self->dict)
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
203 {
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
204 self->dict = PyDict_New ();
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
205 if (!self->dict)
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
206 return NULL;
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
207 }
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
208
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
209 Py_INCREF (self->dict);
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
210 return self->dict;
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
211 }
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
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
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
236 static PyObject*
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
237 _bufferproxy_repr (PyBufferProxy *self)
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
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
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
240 #if PY_VERSION_HEX < 0x02050000
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
241 return PyString_FromFormat("<BufferProxy(%d)>", self->length);
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
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
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
244 #endif
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
245 }
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
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
3cc4c037f5ef visual studio doesn't like arithmetic on a void*
brian
parents: 906
diff changeset
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
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
270 /**** Buffer interfaces ****/
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
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
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
289 static Py_ssize_t
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
290 _bufferproxy_getreadbuf (PyBufferProxy *buffer, Py_ssize_t _index,
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
291 const void **ptr)
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
292 {
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
293 if (_index != 0)
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
294 {
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
295 PyErr_SetString (PyExc_SystemError,
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
296 "Accessing non-existent buffer segment");
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
297 return -1;
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
298 }
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
299
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
300 if (!buffer->parent)
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
301 {
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
302 *ptr = NULL;
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
303 return 0;
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
304 }
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
305
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
306 *ptr = buffer->buffer;
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
307 return buffer->length;
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
308 }
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
309
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
310 static Py_ssize_t
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
311 _bufferproxy_getwritebuf (PyBufferProxy *buffer, Py_ssize_t _index,
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
312 const void **ptr)
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
313 {
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
314 if (_index != 0)
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
315 {
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
316 PyErr_SetString (PyExc_SystemError,
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
317 "Accessing non-existent array segment");
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
318 return -1;
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
319 }
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
320
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
321 if (!buffer->parent)
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
322 {
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
323 *ptr = NULL;
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
324 return 0;
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
325 }
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
326
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
327 *ptr = buffer->buffer;
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
328 return buffer->length;
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
329 }
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
330
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
331 static Py_ssize_t
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
332 _bufferproxy_getsegcount (PyBufferProxy *buffer, Py_ssize_t *lenp)
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
333 {
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
334 if (!buffer->parent)
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
335 {
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
336 *lenp = 0;
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
337 return 0;
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
338 }
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
339
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
340 if (lenp)
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
341 *lenp = buffer->length;
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
342 return 1;
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
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
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
345
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
346 static PyObject*
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
347 PyBufferProxy_New (PyObject *parent, void *buffer, Py_ssize_t length,
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
348 PyObject *lock)
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
349 {
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
350 PyBufferProxy *buf;
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
351
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
352 buf = (PyBufferProxy *) _bufferproxy_new (&PyBufferProxy_Type, NULL, NULL);
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
353
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
354 if (!buf)
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
355 return NULL;
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
356 buf->buffer = buffer;
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
357 buf->length = length;
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
358 buf->lock = lock;
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
359 buf->parent = parent;
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
360 return (PyObject *) buf;
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
361 }
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
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
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
368 {
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
369 PyObject *module;
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
370 PyObject *dict;
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
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
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
373 static void* c_api[PYGAMEAPI_BUFFERPROXY_NUMSLOTS];
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
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
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
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
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
388
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
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
fb9540cdf5e5 symbian branch merging
Rene Dudfield <renesd@gmail.com>
parents: 1578
diff changeset
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
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
395 PyBufferProxy_Type.tp_getattro = PyObject_GenericGetAttr;
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
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
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
403 dict = PyModule_GetDict (module);
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
404
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
405 c_api[0] = &PyBufferProxy_Type;
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
406 c_api[1] = PyBufferProxy_New;
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
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
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
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
41b22371307e Changes from Marcus.
Rene Dudfield <renesd@gmail.com>
parents:
diff changeset
419 }