annotate src/bufferproxy.c @ 3194:9fcb7abf3185 default tip

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