Debian Codegraph @

src/main/c/jpy_module.h

raw symbols SCIP
1 /*
2 * Copyright 2015 Brockmann Consult GmbH
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 * This file was modified by Deephaven Data Labs.
17 *
18 */
19
20 #ifndef JPY_MODULE_H
21 #define JPY_MODULE_H
22
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26
27 #include <Python.h>
28 #include <structmember.h>
29 #include <jni.h>
30
31 #include "jpy_compat.h"
32
33 #if 1
34 #define JPy_DECREF(x) Py_DECREF(x)
35 #define JPy_INCREF(x) Py_INCREF(x)
36 #define JPy_XINCREF(x) Py_XINCREF(x)
37 #define JPy_XDECREF(x) Py_XDECREF(x)
38 #else
39 #include "jpy_diag.h"
40 #define JPy_DECREF(x) do { \
41 JPy_DiagPrint(JPy_DIAG_F_ALL, "JPy_DECREF: %s:%d %p %ld\n", __FILE__, __LINE__, x, ((PyObject *)x)->ob_refcnt);\
42 Py_DECREF(x);\
43 } while (0)
44 #define JPy_INCREF(x) do { \
45 JPy_DiagPrint(JPy_DIAG_F_ALL, "JPy_INCREF: %s:%d %p %ld\n", __FILE__, __LINE__, x, ((PyObject *)x)->ob_refcnt);\
46 Py_INCREF(x);\
47 } while (0)
48 #define JPy_XDECREF(x) do { \
49 JPy_DiagPrint(JPy_DIAG_F_ALL, "JPy_XDECREF: %s:%d %p %ld\n", __FILE__, __LINE__, x, x == NULL ? -1 : ((PyObject *)x)->ob_refcnt);\
50 Py_XDECREF(x);\
51 } while (0)
52 #endif
53
54 #define JPY_JNI_VERSION JNI_VERSION_1_6
55
56 extern PyObject* JPy_Module;
57 extern PyObject* JPy_Types;
58 extern PyObject* JPy_Type_Callbacks;
59 extern PyObject* JPy_Type_Translations;
60 extern PyObject* JException_Type;
61
62 extern JavaVM* JPy_JVM;
63 extern jboolean JPy_MustDestroyJVM;
64
65
66 #define JPy_JTYPE_ATTR_NAME_JINIT "__jinit__"
67
68 #define JPy_MODULE_ATTR_NAME_TYPES "types"
69 #define JPy_MODULE_ATTR_NAME_TYPE_CALLBACKS "type_callbacks"
70 #define JPy_MODULE_ATTR_NAME_TYPE_TRANSLATIONS "type_translations"
71
72
73 /**
74 * Gets the current JNI environment pointer.
75 * Returns NULL, if the JVM is down.
76 *
77 * General jpy design guideline: Use the JPy_GetJNIEnv function only in entry points from Python calls into C.
78 * Add a JNIEnv* as first parameter to all functions that require it.
79 */
80 JNIEnv* JPy_GetJNIEnv(void);
81
82 int JPy_InitGlobalVars(JNIEnv* jenv);
83 void JPy_ClearGlobalVars(JNIEnv* jenv);
84
85 void JPy_free();
86
87 /**
88 * Gets the current JNI environment pointer JENV. If this is NULL, it returns the given RET_VALUE.
89 * Warning: This method may immediately return, so make sure there will be no memory leaks in this case.
90 *
91 * General jpy design guideline: Use the JPy_GET_JNI_ENV_OR_RETURN macro only in entry points from Python calls into C.
92 * Add a JNIEnv* as first parameter to all functions that require it.
93 */
94 #define JPy_GET_JNI_ENV_OR_RETURN(JENV, RET_VALUE) \
95 if ((JENV = JPy_GetJNIEnv()) == NULL) { \
96 return (RET_VALUE); \
97 } else { \
98 }
99
100
101 /**
102 * Fetches the last Java exception occurred and raises a new Python exception.
103 */
104 void JPy_HandleJavaException(JNIEnv* jenv);
105
106 #define JPy_DELETE_LOCAL_REF(VALUE) \
107 (*jenv)->DeleteLocalRef(jenv, VALUE); \
108 VALUE = NULL;
109
110 #define JPy_ON_JAVA_EXCEPTION_GOTO(LABEL) \
111 if ((*jenv)->ExceptionCheck(jenv)) { \
112 JPy_HandleJavaException(jenv); \
113 goto LABEL; \
114 }
115
116 #define JPy_ON_JAVA_EXCEPTION_RETURN(VALUE) \
117 if ((*jenv)->ExceptionCheck(jenv)) { \
118 JPy_HandleJavaException(jenv); \
119 return VALUE; \
120 }
121
122 #define JPy_FRAME(TYPE, ON_ERROR, FUNCTION, FRAME_SIZE) \
123 JNIEnv* jenv; \
124 TYPE result; \
125 if ((jenv = JPy_GetJNIEnv()) == NULL) { \
126 return ON_ERROR; \
127 } \
128 if ((*jenv)->PushLocalFrame(jenv, FRAME_SIZE) < 0) { \
129 JPy_HandleJavaException(jenv); \
130 return ON_ERROR; \
131 } \
132 result = FUNCTION; \
133 (*jenv)->PopLocalFrame(jenv, NULL); \
134 return result;
135
136 struct JPy_JType;
137
138 extern struct JPy_JType* JPy_JBoolean;
139 extern struct JPy_JType* JPy_JChar;
140 extern struct JPy_JType* JPy_JByte;
141 extern struct JPy_JType* JPy_JShort;
142 extern struct JPy_JType* JPy_JInt;
143 extern struct JPy_JType* JPy_JLong;
144 extern struct JPy_JType* JPy_JFloat;
145 extern struct JPy_JType* JPy_JDouble;
146 extern struct JPy_JType* JPy_JVoid;
147 extern struct JPy_JType* JPy_JBooleanObj;
148 extern struct JPy_JType* JPy_JCharacterObj;
149 extern struct JPy_JType* JPy_JByteObj;
150 extern struct JPy_JType* JPy_JShortObj;
151 extern struct JPy_JType* JPy_JIntegerObj;
152 extern struct JPy_JType* JPy_JLongObj;
153 extern struct JPy_JType* JPy_JFloatObj;
154 extern struct JPy_JType* JPy_JDoubleObj;
155 extern struct JPy_JType* JPy_JObject;
156 extern struct JPy_JType* JPy_JClass;
157 extern struct JPy_JType* JPy_JString;
158 extern struct JPy_JType* JPy_JPyObject;
159 extern struct JPy_JType* JPy_JPyModule;
160 extern struct JPy_JType* JPy_JByteBuffer;
161
162 // java.lang.Comparable
163 extern jclass JPy_Comparable_JClass;
164 extern jmethodID JPy_Comparable_CompareTo_MID;
165 // java.lang.Object
166 extern jclass JPy_Object_JClass;
167 extern jmethodID JPy_Object_ToString_MID;
168 extern jmethodID JPy_Object_HashCode_MID;
169 extern jmethodID JPy_Object_Equals_MID;
170 // java.lang.Class
171 extern jclass JPy_Class_JClass;
172 extern jmethodID JPy_Class_GetName_MID;
173 extern jmethodID JPy_Class_GetDeclaredConstructors_MID;
174 extern jmethodID JPy_Class_GetDeclaredFields_MID;
175 extern jmethodID JPy_Class_GetDeclaredMethods_MID;
176 extern jmethodID JPy_Class_GetFields_MID;
177 extern jmethodID JPy_Class_GetMethods_MID;
178 extern jmethodID JPy_Class_GetComponentType_MID;
179 extern jmethodID JPy_Class_IsPrimitive_MID;
180 extern jmethodID JPy_Class_IsInterface_MID;
181 // java.lang.reflect.Constructor
182 extern jclass JPy_Constructor_JClass;
183 extern jmethodID JPy_Constructor_GetModifiers_MID;
184 extern jmethodID JPy_Constructor_GetParameterTypes_MID;
185 // java.lang.reflect.Method
186 extern jclass JPy_Method_JClass;
187 extern jmethodID JPy_Method_GetName_MID;
188 extern jmethodID JPy_Method_GetModifiers_MID;
189 extern jmethodID JPy_Method_GetParameterTypes_MID;
190 extern jmethodID JPy_Method_GetReturnType_MID;
191 // java.lang.reflect.Field
192 extern jclass JPy_Field_JClass;
193 extern jmethodID JPy_Field_GetName_MID;
194 extern jmethodID JPy_Field_GetModifiers_MID;
195 extern jmethodID JPy_Field_GetType_MID;
196 // java.util.Map
197 extern jclass JPy_Map_JClass;
198 extern jclass JPy_Map_Entry_JClass;
199 extern jmethodID JPy_Map_entrySet_MID;
200 extern jmethodID JPy_Map_put_MID;
201 extern jmethodID JPy_Map_clear_MID;
202 extern jmethodID JPy_Map_Entry_getKey_MID;
203 extern jmethodID JPy_Map_Entry_getValue_MID;
204 // java.util.Set
205 extern jclass JPy_Set_JClass;
206 extern jmethodID JPy_Set_Iterator_MID;
207 // java.util.Iterator
208 extern jclass JPy_Iterator_JClass;
209 extern jmethodID JPy_Iterator_next_MID;
210 extern jmethodID JPy_Iterator_hasNext_MID;
211
212 extern jclass JPy_RuntimeException_JClass;
213 extern jclass JPy_OutOfMemoryError_JClass;
214 extern jclass JPy_FileNotFoundException_JClass;
215 extern jclass JPy_UnsupportedOperationException_JClass;
216 extern jclass JPy_KeyError_JClass;
217 extern jclass JPy_StopIteration_JClass;
218
219 extern jclass JPy_Boolean_JClass;
220 extern jmethodID JPy_Boolean_ValueOf_SMID;
221 extern jmethodID JPy_Boolean_BooleanValue_MID;
222
223 extern jclass JPy_Character_JClass;
224 extern jmethodID JPy_Character_ValueOf_SMID;
225 extern jmethodID JPy_Character_CharValue_MID;
226
227 extern jclass JPy_Number_JClass;
228
229 extern jclass JPy_Byte_JClass;
230 extern jmethodID JPy_Byte_ValueOf_SMID;
231
232 extern jclass JPy_Short_JClass;
233 extern jmethodID JPy_Short_ValueOf_SMID;
234
235 extern jclass JPy_Integer_JClass;
236 extern jmethodID JPy_Integer_ValueOf_SMID;
237
238 extern jclass JPy_Long_JClass;
239 extern jmethodID JPy_Long_ValueOf_SMID;
240
241 extern jclass JPy_Float_JClass;
242 extern jmethodID JPy_Float_ValueOf_SMID;
243
244 extern jclass JPy_Double_JClass;
245 extern jmethodID JPy_Double_ValueOf_SMID;
246
247 extern jclass JPy_Number_JClass;
248 extern jmethodID JPy_Number_IntValue_MID;
249 extern jmethodID JPy_Number_LongValue_MID;
250 extern jmethodID JPy_Number_DoubleValue_MID;
251
252 extern jclass JPy_String_JClass;
253 extern jclass JPy_Void_JClass;
254
255 extern jclass JPy_ByteBuffer_JClass;
256 extern jmethodID JPy_ByteBuffer_AsReadOnlyBuffer_MID;
257
258 extern jclass JPy_PyObject_JClass;
259 extern jmethodID JPy_PyObject_GetPointer_MID;
260 extern jmethodID JPy_PyObject_UnwrapProxy_SMID;
261 extern jmethodID JPy_PyObject_Init_MID;
262
263 extern jclass JPy_PyDictWrapper_JClass;
264 extern jmethodID JPy_PyDictWrapper_GetPointer_MID;
265
266 extern jclass JPy_Supplier_JClass;
267 extern jmethodID JPy_Supplier_get_MID;
268
269 #ifdef __cplusplus
270 } /* extern "C" */
271 #endif
272 #endif /* !JPY_MODULE_H */