|
29
|
1 |
/* |
|
|
2 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
3 |
* you may not use this file except in compliance with the License. |
|
|
4 |
* You may obtain a copy of the License at |
|
|
5 |
* |
|
|
6 |
* http://www.apache.org/licenses/LICENSE-2.0 |
|
|
7 |
* |
|
|
8 |
* Unless required by applicable law or agreed to in writing, software |
|
|
9 |
* distributed under the License is distributed on an "AS IS" BASIS, |
|
|
10 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
|
11 |
* See the License for the specific language governing permissions and |
|
|
12 |
* limitations under the License. |
|
|
13 |
*/ |
|
|
14 |
|
|
|
15 |
#ifndef _functions_h |
|
|
16 |
#define _functions_h |
|
|
17 |
|
|
|
18 |
#include "java/util/Iterator.h" |
|
|
19 |
#include "java/util/Enumeration.h" |
|
|
20 |
#include "java/lang/String.h" |
|
|
21 |
#include "java/lang/Object.h" |
|
|
22 |
#include "macros.h" |
|
|
23 |
|
|
|
24 |
#if PY_VERSION_HEX < 0x02050000 |
|
|
25 |
typedef int Py_ssize_t; |
|
|
26 |
typedef inquiry lenfunc; |
|
|
27 |
typedef intargfunc ssizeargfunc; |
|
|
28 |
typedef intintargfunc ssizessizeargfunc; |
|
|
29 |
typedef intobjargproc ssizeobjargproc; |
|
|
30 |
typedef intintobjargproc ssizessizeobjargproc; |
|
|
31 |
#endif |
|
|
32 |
|
|
|
33 |
typedef jclass (*getclassfn)(void); |
|
|
34 |
typedef PyTypeObject **(*getparametersfn)(void *); |
|
|
35 |
|
|
|
36 |
PyObject *PyErr_SetArgsError(char *name, PyObject *args); |
|
|
37 |
PyObject *PyErr_SetArgsError(PyObject *self, char *name, PyObject *args); |
|
|
38 |
PyObject *PyErr_SetArgsError(PyTypeObject *type, char *name, PyObject *args); |
|
|
39 |
PyObject *PyErr_SetJavaError(jthrowable throwable); |
|
|
40 |
|
|
|
41 |
extern PyObject *PyExc_JavaError; |
|
|
42 |
extern PyObject *PyExc_InvalidArgsError; |
|
|
43 |
|
|
|
44 |
|
|
|
45 |
void throwPythonError(void); |
|
|
46 |
void throwTypeError(const char *name, PyObject *object); |
|
|
47 |
|
|
|
48 |
#if defined(_MSC_VER) || defined(__SUNPRO_CC) |
|
|
49 |
|
|
|
50 |
#define parseArgs __parseArgs |
|
|
51 |
#define parseArg __parseArg |
|
|
52 |
|
|
|
53 |
int __parseArgs(PyObject *args, char *types, ...); |
|
|
54 |
int __parseArg(PyObject *arg, char *types, ...); |
|
|
55 |
|
|
|
56 |
int _parseArgs(PyObject **args, unsigned int count, char *types, |
|
|
57 |
va_list list, va_list check); |
|
|
58 |
|
|
|
59 |
#else |
|
|
60 |
|
|
|
61 |
#define parseArgs(args, types, rest...) \ |
|
|
62 |
_parseArgs(((PyTupleObject *)(args))->ob_item, \ |
|
|
63 |
((PyTupleObject *)(args))->ob_size, types, ##rest) |
|
|
64 |
|
|
|
65 |
#define parseArg(arg, types, rest...) \ |
|
|
66 |
_parseArgs(&(arg), 1, types, ##rest) |
|
|
67 |
|
|
|
68 |
int _parseArgs(PyObject **args, unsigned int count, char *types, ...); |
|
|
69 |
|
|
|
70 |
#endif |
|
|
71 |
|
|
|
72 |
int abstract_init(PyObject *self, PyObject *args, PyObject *kwds); |
|
|
73 |
PyObject *wrapType(PyTypeObject *type, const jobject& obj); |
|
|
74 |
|
|
|
75 |
PyObject *j2p(const java::lang::String& js); |
|
|
76 |
java::lang::String p2j(PyObject *object); |
|
|
77 |
|
|
|
78 |
PyObject *make_descriptor(PyTypeObject *value); |
|
|
79 |
PyObject *make_descriptor(getclassfn initializeClass); |
|
|
80 |
PyObject *make_descriptor(getclassfn initializeClass, int generics); |
|
|
81 |
PyObject *make_descriptor(PyObject *value); |
|
|
82 |
PyObject *make_descriptor(PyObject *(*wrapfn)(const jobject &)); |
|
|
83 |
PyObject *make_descriptor(jboolean value); |
|
|
84 |
PyObject *make_descriptor(jbyte value); |
|
|
85 |
PyObject *make_descriptor(jchar value); |
|
|
86 |
PyObject *make_descriptor(jdouble value); |
|
|
87 |
PyObject *make_descriptor(jfloat value); |
|
|
88 |
PyObject *make_descriptor(jint value); |
|
|
89 |
PyObject *make_descriptor(jlong value); |
|
|
90 |
PyObject *make_descriptor(jshort value); |
|
|
91 |
|
|
|
92 |
jobjectArray make_array(jclass cls, PyObject *sequence); |
|
|
93 |
|
|
|
94 |
PyObject *callSuper(PyTypeObject *type, |
|
|
95 |
const char *name, PyObject *args, int cardinality); |
|
|
96 |
PyObject *callSuper(PyTypeObject *type, PyObject *self, |
|
|
97 |
const char *name, PyObject *args, int cardinality); |
|
|
98 |
|
|
|
99 |
template<class T> PyObject *get_iterator(T *self) |
|
|
100 |
{ |
|
|
101 |
java::util::Iterator iterator((jobject) NULL); |
|
|
102 |
|
|
|
103 |
OBJ_CALL(iterator = self->object.iterator()); |
|
|
104 |
return java::util::t_Iterator::wrap_Object(iterator); |
|
|
105 |
} |
|
|
106 |
|
|
|
107 |
#ifdef _java_generics |
|
|
108 |
template<class T> PyObject *get_generic_iterator(T *self) |
|
|
109 |
{ |
|
|
110 |
java::util::Iterator iterator((jobject) NULL); |
|
|
111 |
PyTypeObject *param = self->parameters ? self->parameters[0] : NULL; |
|
|
112 |
|
|
|
113 |
OBJ_CALL(iterator = self->object.iterator()); |
|
|
114 |
return java::util::t_Iterator::wrap_Object(iterator, param); |
|
|
115 |
} |
|
|
116 |
#endif |
|
|
117 |
|
|
|
118 |
template<class T, class U> PyObject *get_iterator_next(T *self) |
|
|
119 |
{ |
|
|
120 |
jboolean hasNext; |
|
|
121 |
OBJ_CALL(hasNext = self->object.hasNext()); |
|
|
122 |
if (!hasNext) |
|
|
123 |
{ |
|
|
124 |
PyErr_SetNone(PyExc_StopIteration); |
|
|
125 |
return NULL; |
|
|
126 |
} |
|
|
127 |
|
|
|
128 |
jobject next; |
|
|
129 |
OBJ_CALL(next = env->iteratorNext(self->object.this$)); |
|
|
130 |
|
|
|
131 |
jclass cls = java::lang::String::initializeClass(); |
|
|
132 |
if (env->get_vm_env()->IsInstanceOf(next, cls)) |
|
|
133 |
return env->fromJString((jstring) next, 1); |
|
|
134 |
|
|
|
135 |
return U::wrap_jobject(next); |
|
|
136 |
} |
|
|
137 |
|
|
|
138 |
#ifdef _java_generics |
|
|
139 |
template<class T, class U> PyObject *get_generic_iterator_next(T *self) |
|
|
140 |
{ |
|
|
141 |
jboolean hasNext; |
|
|
142 |
OBJ_CALL(hasNext = self->object.hasNext()); |
|
|
143 |
if (!hasNext) |
|
|
144 |
{ |
|
|
145 |
PyErr_SetNone(PyExc_StopIteration); |
|
|
146 |
return NULL; |
|
|
147 |
} |
|
|
148 |
|
|
|
149 |
jobject next; |
|
|
150 |
OBJ_CALL(next = env->iteratorNext(self->object.this$)); |
|
|
151 |
|
|
|
152 |
jclass cls = java::lang::String::initializeClass(); |
|
|
153 |
if (env->get_vm_env()->IsInstanceOf(next, cls)) |
|
|
154 |
return env->fromJString((jstring) next, 1); |
|
|
155 |
|
|
|
156 |
PyTypeObject *param = self->parameters ? self->parameters[0] : NULL; |
|
|
157 |
if (param != NULL) |
|
|
158 |
return wrapType(param, next); |
|
|
159 |
|
|
|
160 |
return U::wrap_jobject(next); |
|
|
161 |
} |
|
|
162 |
#endif |
|
|
163 |
|
|
|
164 |
template<class T, class U> PyObject *get_enumeration_next(T *self) |
|
|
165 |
{ |
|
|
166 |
jboolean hasMoreElements; |
|
|
167 |
OBJ_CALL(hasMoreElements = self->object.hasMoreElements()); |
|
|
168 |
if (!hasMoreElements) |
|
|
169 |
{ |
|
|
170 |
PyErr_SetNone(PyExc_StopIteration); |
|
|
171 |
return NULL; |
|
|
172 |
} |
|
|
173 |
|
|
|
174 |
jobject next; |
|
|
175 |
OBJ_CALL(next = env->enumerationNext(self->object.this$)); |
|
|
176 |
|
|
|
177 |
jclass cls = java::lang::String::initializeClass(); |
|
|
178 |
if (env->get_vm_env()->IsInstanceOf(next, cls)) |
|
|
179 |
return env->fromJString((jstring) next, 1); |
|
|
180 |
|
|
|
181 |
return U::wrap_jobject(next); |
|
|
182 |
} |
|
|
183 |
|
|
|
184 |
#ifdef _java_generics |
|
|
185 |
template<class T, class U> PyObject *get_generic_enumeration_next(T *self) |
|
|
186 |
{ |
|
|
187 |
jboolean hasMoreElements; |
|
|
188 |
OBJ_CALL(hasMoreElements = self->object.hasMoreElements()); |
|
|
189 |
if (!hasMoreElements) |
|
|
190 |
{ |
|
|
191 |
PyErr_SetNone(PyExc_StopIteration); |
|
|
192 |
return NULL; |
|
|
193 |
} |
|
|
194 |
|
|
|
195 |
jobject next; |
|
|
196 |
OBJ_CALL(next = env->enumerationNext(self->object.this$)); |
|
|
197 |
|
|
|
198 |
jclass cls = java::lang::String::initializeClass(); |
|
|
199 |
if (env->get_vm_env()->IsInstanceOf(next, cls)) |
|
|
200 |
return env->fromJString((jstring) next, 1); |
|
|
201 |
|
|
|
202 |
PyTypeObject *param = self->parameters ? self->parameters[0] : NULL; |
|
|
203 |
if (param != NULL) |
|
|
204 |
return wrapType(param, next); |
|
|
205 |
|
|
|
206 |
return U::wrap_jobject(next); |
|
|
207 |
} |
|
|
208 |
#endif |
|
|
209 |
|
|
|
210 |
template<class T, class U, class V> PyObject *get_next(T *self) |
|
|
211 |
{ |
|
|
212 |
V next((jobject) NULL); |
|
|
213 |
OBJ_CALL(next = self->object.next()); |
|
|
214 |
if (!next) |
|
|
215 |
{ |
|
|
216 |
PyErr_SetNone(PyExc_StopIteration); |
|
|
217 |
return NULL; |
|
|
218 |
} |
|
|
219 |
|
|
|
220 |
jclass cls = java::lang::String::initializeClass(); |
|
|
221 |
if (env->get_vm_env()->IsInstanceOf(next.this$, cls)) |
|
|
222 |
return env->fromJString((jstring) next.this$, 0); |
|
|
223 |
|
|
|
224 |
return U::wrap_Object(next); |
|
|
225 |
} |
|
|
226 |
|
|
|
227 |
#ifdef _java_generics |
|
|
228 |
template<class T, class U, class V> PyObject *get_generic_next(T *self) |
|
|
229 |
{ |
|
|
230 |
V next((jobject) NULL); |
|
|
231 |
OBJ_CALL(next = self->object.next()); |
|
|
232 |
if (!next) |
|
|
233 |
{ |
|
|
234 |
PyErr_SetNone(PyExc_StopIteration); |
|
|
235 |
return NULL; |
|
|
236 |
} |
|
|
237 |
|
|
|
238 |
jclass cls = java::lang::String::initializeClass(); |
|
|
239 |
if (env->get_vm_env()->IsInstanceOf(next.this$, cls)) |
|
|
240 |
return env->fromJString((jstring) next.this$, 0); |
|
|
241 |
|
|
|
242 |
PyTypeObject *param = self->parameters ? self->parameters[0] : NULL; |
|
|
243 |
if (param != NULL) |
|
|
244 |
return wrapType(param, next.this$); |
|
|
245 |
|
|
|
246 |
return U::wrap_Object(next); |
|
|
247 |
} |
|
|
248 |
#endif |
|
|
249 |
|
|
|
250 |
PyObject *get_extension_iterator(PyObject *self); |
|
|
251 |
PyObject *get_extension_next(PyObject *self); |
|
|
252 |
PyObject *get_extension_nextElement(PyObject *self); |
|
|
253 |
|
|
|
254 |
jobjectArray fromPySequence(jclass cls, PyObject *sequence); |
|
|
255 |
PyObject *castCheck(PyObject *obj, getclassfn initializeClass, |
|
|
256 |
int reportError); |
|
|
257 |
void installType(PyTypeObject *type, PyObject *module, char *name, |
|
|
258 |
int isExtension); |
|
|
259 |
|
|
|
260 |
#ifdef _java_generics |
|
|
261 |
PyObject *typeParameters(PyTypeObject *types[], size_t size); |
|
|
262 |
#endif |
|
|
263 |
|
|
|
264 |
extern PyTypeObject FinalizerClass$$Type; |
|
|
265 |
extern PyTypeObject FinalizerProxy$$Type; |
|
|
266 |
|
|
|
267 |
typedef struct { |
|
|
268 |
PyObject_HEAD |
|
|
269 |
PyObject *object; |
|
|
270 |
} t_fp; |
|
|
271 |
|
|
|
272 |
#endif /* _functions_h */ |