Mercurial > pygame
annotate src/_view.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 | 841b902f3d15 |
| children |
| rev | line source |
|---|---|
|
2131
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
1 /* |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
2 pygame - Python Game Library |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
3 Module adapted from bufferproxy.c, Copyright (C) 2007 Marcus von Appen |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
4 |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
5 This library is free software; you can redistribute it and/or |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
6 modify it under the terms of the GNU Library General Public |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
7 License as published by the Free Software Foundation; either |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
8 version 2 of the License, or (at your option) any later version. |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
9 |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
10 This library is distributed in the hope that it will be useful, |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
13 Library General Public License for more details. |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
14 |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
15 You should have received a copy of the GNU Library General Public |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
16 License along with this library; if not, write to the Free |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
18 |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
19 */ |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
20 |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
21 /* |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
22 This module exports an object which provides a C level interface to |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
23 another object's buffer. For now only an array structure - |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
24 __array_struct__ - interface is exposed. When memoryview is ready it |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
25 will replace the View object. |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
26 */ |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
27 |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
28 #define NO_PYGAME_C_API |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
29 #include "pygame.h" |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
30 #include "pgcompat.h" |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
31 #include "pgview.h" |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
32 |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
33 typedef struct { |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
34 PyObject_HEAD |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
35 PyObject *capsule; /* Wrapped array struct */ |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
36 PyObject *parent; /* Object responsible for the view */ |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
37 PgView_Destructor destructor; /* Optional release callback */ |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
38 PyObject *pydestructor; /* Python callable destructor */ |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
39 PyObject *weakrefs; /* There can be reference cycles */ |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
40 } PgViewObject; |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
41 |
|
3014
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
42 static int Pg_GetArrayInterface(PyObject *, PyObject **, PyArrayInterface **); |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
43 static PyObject *Pg_ArrayStructAsDict(PyArrayInterface *); |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
44 |
|
2131
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
45 /** |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
46 * Helper functions. |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
47 */ |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
48 static void |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
49 _view_default_destructor(PyObject *view) { |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
50 PgViewObject *v = (PgViewObject *)view; |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
51 PyObject *rvalue; |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
52 |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
53 if (v->pydestructor) { |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
54 rvalue = PyObject_CallFunctionObjArgs(v->pydestructor, |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
55 v->capsule, |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
56 v->parent, |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
57 0); |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
58 PyErr_Clear(); |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
59 Py_XDECREF(rvalue); |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
60 } |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
61 } |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
62 |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
63 static PyObject * |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
64 _view_new_from_type(PyTypeObject *type, |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
65 PyObject *capsule, |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
66 PyObject *parent, |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
67 PgView_Destructor destructor, |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
68 PyObject *pydestructor) |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
69 { |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
70 PgViewObject *self = (PgViewObject *)type->tp_alloc(type, 0); |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
71 |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
72 if (!self) { |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
73 return 0; |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
74 } |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
75 self->weakrefs = 0; |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
76 Py_INCREF(capsule); |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
77 self->capsule = capsule; |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
78 if (!parent) { |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
79 parent = Py_None; |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
80 } |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
81 Py_INCREF(parent); |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
82 self->parent = parent; |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
83 self->destructor = destructor ? destructor : _view_default_destructor; |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
84 Py_XINCREF(pydestructor); |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
85 self->pydestructor = pydestructor; |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
86 return (PyObject *)self; |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
87 } |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
88 |
|
3014
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
89 static PyObject * |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
90 _shape_as_tuple(PyArrayInterface *inter_p) |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
91 { |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
92 PyObject *shapeobj = PyTuple_New((Py_ssize_t)inter_p->nd); |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
93 PyObject *lengthobj; |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
94 Py_ssize_t i; |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
95 |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
96 if (!shapeobj) { |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
97 return 0; |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
98 } |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
99 for (i = 0; i < inter_p->nd; ++i) { |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
100 lengthobj = PyInt_FromLong((long)inter_p->shape[i]); |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
101 if (!lengthobj) { |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
102 Py_DECREF(shapeobj); |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
103 return 0; |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
104 } |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
105 PyTuple_SET_ITEM(shapeobj, i, lengthobj); |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
106 } |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
107 return shapeobj; |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
108 } |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
109 |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
110 #if SDL_BYTEORDER == SDL_LIL_ENDIAN |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
111 #define MY_ENDIAN '<' |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
112 #define OTHER_ENDIAN '>' |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
113 #else |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
114 #define MY_ENDIAN '>' |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
115 #define OTHER_ENDIAN '<' |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
116 #endif |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
117 |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
118 static PyObject * |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
119 _typekind_as_str(PyArrayInterface *inter_p) |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
120 { |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
121 return Text_FromFormat("%c%c%i", |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
122 inter_p->flags & PAI_NOTSWAPPED ? |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
123 MY_ENDIAN : OTHER_ENDIAN, |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
124 inter_p->typekind, inter_p->itemsize); |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
125 } |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
126 |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
127 #undef MY_ENDIAN |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
128 #undef OTHER_ENDIAN |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
129 |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
130 static PyObject *_strides_as_tuple(PyArrayInterface *inter_p) |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
131 { |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
132 PyObject *stridesobj = PyTuple_New((Py_ssize_t)inter_p->nd); |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
133 PyObject *lengthobj; |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
134 Py_ssize_t i; |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
135 |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
136 if (!stridesobj) { |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
137 return 0; |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
138 } |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
139 for (i = 0; i < inter_p->nd; ++i) { |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
140 lengthobj = PyInt_FromLong((long)inter_p->strides[i]); |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
141 if (!lengthobj) { |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
142 Py_DECREF(stridesobj); |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
143 return 0; |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
144 } |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
145 PyTuple_SET_ITEM(stridesobj, i, lengthobj); |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
146 } |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
147 return stridesobj; |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
148 } |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
149 |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
150 static PyObject *_data_as_tuple(PyArrayInterface *inter_p) |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
151 { |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
152 long readonly = (inter_p->flags & PAI_WRITEABLE) == 0; |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
153 |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
154 return Py_BuildValue("NN", |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
155 PyLong_FromVoidPtr(inter_p->data), |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
156 PyBool_FromLong(readonly)); |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
157 } |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
158 |
|
2131
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
159 /** |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
160 * Creates a new PgViewObject. |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
161 */ |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
162 static PyObject * |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
163 _view_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
164 { |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
165 PyObject *capsule; |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
166 PyObject *parent = 0; |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
167 PyObject *pydestructor = 0; |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
168 char *keywords[] = {"capsule", "parent", "destructor", 0}; |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
169 |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
170 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|OO:View", keywords, |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
171 &capsule, &parent, &pydestructor)) { |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
172 return 0; |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
173 } |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
174 if (pydestructor == Py_None) { |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
175 pydestructor = 0; |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
176 } |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
177 return _view_new_from_type(type, |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
178 capsule, |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
179 parent, |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
180 0, |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
181 pydestructor); |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
182 } |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
183 |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
184 /** |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
185 * Deallocates the PgViewObject and its members. |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
186 */ |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
187 static void |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
188 _view_dealloc(PgViewObject *self) |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
189 { |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
190 PgView_Destructor destructor = self->destructor; |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
191 |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
192 /* Guard against recursion */ |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
193 self->destructor = 0; |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
194 if (!destructor) { |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
195 return; |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
196 } |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
197 |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
198 destructor((PyObject *)self); |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
199 Py_DECREF(self->capsule); |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
200 Py_DECREF(self->parent); |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
201 Py_XDECREF(self->pydestructor); |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
202 if (self->weakrefs) { |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
203 PyObject_ClearWeakRefs((PyObject *)self); |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
204 } |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
205 Py_TYPE(self)->tp_free(self); |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
206 } |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
207 |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
208 /**** Getter and setter access ****/ |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
209 |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
210 static PyObject * |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
211 _view_get_arraystruct(PgViewObject *self, PyObject *closure) |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
212 { |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
213 Py_INCREF(self->capsule); |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
214 return self->capsule; |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
215 } |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
216 |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
217 static PyObject * |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
218 _view_get_parent(PgViewObject *self, PyObject *closure) |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
219 { |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
220 if (!self->parent) { |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
221 Py_RETURN_NONE; |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
222 } |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
223 Py_INCREF(self->parent); |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
224 return self->parent; |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
225 } |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
226 |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
227 /**** Methods ****/ |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
228 |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
229 /** |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
230 * Representation method. |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
231 */ |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
232 static PyObject * |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
233 _view_repr (PgViewObject *self) |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
234 { |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
235 return Text_FromFormat("<%s(%p)>", Py_TYPE(self)->tp_name, self->capsule); |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
236 } |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
237 |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
238 /** |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
239 * Getters and setters for the PgViewObject. |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
240 */ |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
241 static PyGetSetDef _view_getsets[] = |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
242 { |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
243 {"__array_struct__", (getter)_view_get_arraystruct, 0, 0, 0}, |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
244 {"parent", (getter)_view_get_parent, 0, 0, 0}, |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
245 {0, 0, 0, 0, 0} |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
246 }; |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
247 |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
248 |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
249 static PyTypeObject PgView_Type = |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
250 { |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
251 TYPE_HEAD (NULL, 0) |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
252 "pygame._view.View", /* tp_name */ |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
253 sizeof (PgViewObject), /* tp_basicsize */ |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
254 0, /* tp_itemsize */ |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
255 (destructor)_view_dealloc, /* tp_dealloc */ |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
256 0, /* tp_print */ |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
257 0, /* tp_getattr */ |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
258 0, /* tp_setattr */ |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
259 0, /* tp_compare */ |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
260 (reprfunc)_view_repr, /* tp_repr */ |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
261 0, /* tp_as_number */ |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
262 0, /* tp_as_sequence */ |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
263 0, /* tp_as_mapping */ |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
264 0, /* tp_hash */ |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
265 0, /* tp_call */ |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
266 0, /* tp_str */ |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
267 0, /* tp_getattro */ |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
268 0, /* tp_setattro */ |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
269 0, /* tp_as_buffer */ |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
270 (Py_TPFLAGS_HAVE_WEAKREFS | Py_TPFLAGS_BASETYPE | |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
271 Py_TPFLAGS_HAVE_CLASS), |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
272 "Object view as an array struct\n", |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
273 0, /* tp_traverse */ |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
274 0, /* tp_clear */ |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
275 0, /* tp_richcompare */ |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
276 offsetof(PgViewObject, weakrefs), /* tp_weaklistoffset */ |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
277 0, /* tp_iter */ |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
278 0, /* tp_iternext */ |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
279 0, /* tp_methods */ |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
280 0, /* tp_members */ |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
281 _view_getsets, /* tp_getset */ |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
282 0, /* tp_base */ |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
283 0, /* tp_dict */ |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
284 0, /* tp_descr_get */ |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
285 0, /* tp_descr_set */ |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
286 0, /* tp_dictoffset */ |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
287 0, /* tp_init */ |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
288 0, /* tp_alloc */ |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
289 _view_new, /* tp_new */ |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
290 0, /* tp_free */ |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
291 #ifndef __SYMBIAN32__ |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
292 0, /* tp_is_gc */ |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
293 0, /* tp_bases */ |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
294 0, /* tp_mro */ |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
295 0, /* tp_cache */ |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
296 0, /* tp_subclasses */ |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
297 0, /* tp_weaklist */ |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
298 0 /* tp_del */ |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
299 #endif |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
300 }; |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
301 |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
302 |
|
3014
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
303 /**** Module methods ***/ |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
304 |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
305 static PyObject * |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
306 get_array_interface(PyObject *self, PyObject *arg) |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
307 { |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
308 PyObject *cobj; |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
309 PyArrayInterface *inter_p; |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
310 PyObject *dictobj; |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
311 |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
312 if (Pg_GetArrayInterface(arg, &cobj, &inter_p)) { |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
313 return 0; |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
314 } |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
315 dictobj = Pg_ArrayStructAsDict(inter_p); |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
316 Py_DECREF(cobj); |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
317 return dictobj; |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
318 } |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
319 |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
320 static PyMethodDef _view_methods[] = { |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
321 { "get_array_interface", get_array_interface, METH_O, |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
322 "return an array struct interface as an interface dictionary" }, |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
323 {0, 0, 0, 0} |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
324 }; |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
325 |
|
2131
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
326 /**** Public C api ***/ |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
327 |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
328 static PyObject * |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
329 PgView_New(PyObject *capsule, |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
330 PyObject *parent, |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
331 PgView_Destructor destructor) |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
332 { |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
333 if (!capsule) { |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
334 PyErr_SetString(PyExc_TypeError, "the capsule argument is required"); |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
335 return 0; |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
336 } |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
337 return _view_new_from_type(&PgView_Type, capsule, parent, destructor, 0); |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
338 } |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
339 |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
340 static PyObject * |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
341 PgView_GetCapsule(PyObject *view) |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
342 { |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
343 PyObject *capsule = ((PgViewObject *)view)->capsule; |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
344 |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
345 Py_INCREF(capsule); |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
346 return capsule; |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
347 } |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
348 |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
349 static PyObject * |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
350 PgView_GetParent(PyObject *view) |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
351 { |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
352 PyObject *parent = ((PgViewObject *)view)->parent; |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
353 |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
354 Py_INCREF(parent); |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
355 return parent; |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
356 } |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
357 |
|
3014
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
358 static int |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
359 Pg_GetArrayInterface(PyObject *obj, |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
360 PyObject **cobj_p, |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
361 PyArrayInterface **inter_p) |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
362 { |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
363 PyObject *cobj = PyObject_GetAttrString(obj, "__array_struct__"); |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
364 PyArrayInterface *inter = NULL; |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
365 |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
366 if (cobj == NULL) { |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
367 if (PyErr_ExceptionMatches(PyExc_AttributeError)) { |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
368 PyErr_Clear(); |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
369 PyErr_SetString(PyExc_ValueError, |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
370 "no C-struct array interface"); |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
371 } |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
372 return -1; |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
373 } |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
374 |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
375 #if PG_HAVE_COBJECT |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
376 if (PyCObject_Check(cobj)) { |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
377 inter = (PyArrayInterface *)PyCObject_AsVoidPtr(cobj); |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
378 } |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
379 #endif |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
380 #if PG_HAVE_CAPSULE |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
381 if (PyCapsule_IsValid(cobj, NULL)) { |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
382 inter = (PyArrayInterface *)PyCapsule_GetPointer(cobj, NULL); |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
383 } |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
384 #endif |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
385 if (inter == NULL || /* conditional or */ |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
386 inter->two != 2 ) { |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
387 Py_DECREF(cobj); |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
388 PyErr_SetString(PyExc_ValueError, "invalid array interface"); |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
389 return -1; |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
390 } |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
391 |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
392 *cobj_p = cobj; |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
393 *inter_p = inter; |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
394 return 0; |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
395 } |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
396 |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
397 static PyObject * |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
398 Pg_ArrayStructAsDict(PyArrayInterface *inter_p) |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
399 { |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
400 PyObject *dictobj = Py_BuildValue("{sisNsNsNsN}", |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
401 "version", (int)3, |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
402 "typestr", _typekind_as_str(inter_p), |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
403 "shape", _shape_as_tuple(inter_p), |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
404 "strides", _strides_as_tuple(inter_p), |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
405 "data", _data_as_tuple(inter_p)); |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
406 |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
407 if (!dictobj) { |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
408 return 0; |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
409 } |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
410 if (inter_p->flags & PAI_ARR_HAS_DESCR) { |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
411 if (!inter_p->descr) { |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
412 Py_DECREF(dictobj); |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
413 PyErr_SetString(PyExc_ValueError, |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
414 "Array struct has descr flag set" |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
415 " but no descriptor"); |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
416 return 0; |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
417 } |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
418 if (PyDict_SetItemString(dictobj, "descr", inter_p->descr)) { |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
419 return 0; |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
420 } |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
421 } |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
422 return dictobj; |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
423 } |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
424 |
|
2131
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
425 /*DOC*/ static char _view_doc[] = |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
426 /*DOC*/ "exports View, a generic wrapper object for an array " |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
427 /*DOC*/ "struct capsule"; |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
428 |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
429 MODINIT_DEFINE(_view) |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
430 { |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
431 PyObject *module; |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
432 PyObject *apiobj; |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
433 static void* c_api[PYGAMEAPI_VIEW_NUMSLOTS]; |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
434 |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
435 #if PY3 |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
436 static struct PyModuleDef _module = { |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
437 PyModuleDef_HEAD_INIT, |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
438 "_view", |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
439 _view_doc, |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
440 -1, |
|
3014
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
441 _view_methods, |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
442 NULL, NULL, NULL, NULL |
|
2131
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
443 }; |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
444 #endif |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
445 |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
446 if (PyType_Ready(&PgView_Type) < 0) { |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
447 MODINIT_ERROR; |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
448 } |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
449 |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
450 /* create the module */ |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
451 #if PY3 |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
452 module = PyModule_Create(&_module); |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
453 #else |
|
3014
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
454 module = Py_InitModule3(MODPREFIX "_view", _view_methods, _view_doc); |
|
2131
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
455 #endif |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
456 |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
457 Py_INCREF(&PgView_Type); |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
458 if (PyModule_AddObject(module, "View", (PyObject *)&PgView_Type)) { |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
459 Py_DECREF(&PgView_Type); |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
460 DECREF_MOD(module); |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
461 MODINIT_ERROR; |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
462 } |
|
3014
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
463 #if PYGAMEAPI_VIEW_NUMSLOTS != 6 |
|
2131
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
464 #error export slot count mismatch |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
465 #endif |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
466 c_api[0] = &PgView_Type; |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
467 c_api[1] = PgView_New; |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
468 c_api[2] = PgView_GetCapsule; |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
469 c_api[3] = PgView_GetParent; |
|
3014
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
470 c_api[4] = Pg_GetArrayInterface; |
|
841b902f3d15
Centralize common array struct interface operations in the _view module
Lenard Lindstrom <len-l@telus.net>
parents:
2131
diff
changeset
|
471 c_api[5] = Pg_ArrayStructAsDict; |
|
2131
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
472 apiobj = encapsulate_api(c_api, "_view"); |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
473 if (apiobj == NULL) { |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
474 DECREF_MOD(module); |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
475 MODINIT_ERROR; |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
476 } |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
477 if (PyModule_AddObject(module, PYGAMEAPI_LOCAL_ENTRY, apiobj)) { |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
478 Py_DECREF(apiobj); |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
479 DECREF_MOD(module); |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
480 MODINIT_ERROR; |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
481 } |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
482 MODINIT_RETURN(module); |
|
018779fb04f5
Merge the buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
diff
changeset
|
483 } |
