Debian Codegraph @

src/main/c/jpy_jtype.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 *
17 * This file was modified by Deephaven Data Labs.
18 *
19 */
20
21 #ifndef JPY_JTYPE_H
22 #define JPY_JTYPE_H
23
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27
28 #include "jpy_compat.h"
29
30 /**
31 * The Python type 'JType' representing a Java type.
32 */
33 typedef struct JPy_JType
34 {
35 // Since this is a type object, inherit everything from from PyTypeObject.
36 // It is absolutely essential that this is the first struct member!
37 // typeObj.tp_name is this type's fully qualified Java name (same as 'javaName' field).
38 PyTypeObject typeObj;
39 // The Java type name.
40 char* javaName;
41 // The JNI class reference (global reference).
42 jclass classRef;
43 // The super type of this type. This will be NULL for primitive types, 'void', and 'java.lang.Object'.
44 struct JPy_JType* superType;
45 // If component type of this type if this type is an array, NULL otherwise.
46 struct JPy_JType* componentType;
47 // If TRUE, 'classRef' refers to a Java primitive type or 'void'.
48 char isPrimitive;
49 // If TRUE, 'classRef' refers to a Java interface type.
50 char isInterface;
51 // If TRUE, the type is currently being resolved.
52 char isResolving;
53 // If TRUE, all the class constructors and methods have already been resolved.
54 char isResolved;
55 }
56 JPy_JType;
57
58 #define JTYPE_AS_PYTYPE(T) ((PyTypeObject*) T)
59
60 /**
61 * The 'JType' singleton.
62 */
63 extern PyTypeObject JType_Type;
64
65 typedef void (*JPy_DisposeArg)(JNIEnv*, jvalue* value, void* data);
66
67 /**
68 * ArgDisposers are used to dispose arguments after invocation of Java methods.
69 * We need to dispose those arguments which have been created as local references,
70 * e.g. jenv->NewString(), jenv->NewObjectArray(), jenv->New<Type>Array().
71 */
72 typedef struct JPy_ArgDisposer
73 {
74 void* data;
75 JPy_DisposeArg DisposeArg;
76 }
77 JPy_ArgDisposer;
78
79
80 struct JPy_ParamDescriptor;
81
82 typedef int (*JPy_MatchPyArg)(JNIEnv*, struct JPy_ParamDescriptor*, PyObject*);
83 typedef int (*JPy_MatchVarArgPyArg)(JNIEnv*, struct JPy_ParamDescriptor*, PyObject*, int);
84 typedef int (*JPy_ConvertPyArg)(JNIEnv*, struct JPy_ParamDescriptor*, PyObject*, jvalue*, JPy_ArgDisposer*);
85 typedef int (*JPy_ConvertVarArgPyArg)(JNIEnv*, struct JPy_ParamDescriptor*, PyObject*, int, jvalue*, JPy_ArgDisposer*);
86
87 /**
88 * Method return value descriptor.
89 */
90 typedef struct JPy_ReturnDescriptor
91 {
92 /**
93 * The return type.
94 */
95 JPy_JType* type;
96 /**
97 * If JPy_ParamDescriptor.isReturnIndex == TRUE the index of the parameter, whose argument will serve as return value.
98 * If JPy_ParamDescriptor.isReturnIndex == FALSE it will be -1.
99 */
100 jint paramIndex;
101 }
102 JPy_ReturnDescriptor;
103
104 /**
105 * Method parameter descriptor.
106 */
107 typedef struct JPy_ParamDescriptor
108 {
109 JPy_JType* type;
110 jboolean isMutable;
111 jboolean isOutput;
112 jboolean isReturn;
113 JPy_MatchPyArg MatchPyArg;
114 JPy_MatchVarArgPyArg MatchVarArgPyArg;
115 JPy_ConvertPyArg ConvertPyArg;
116 JPy_ConvertVarArgPyArg ConvertVarArgPyArg;
117 }
118 JPy_ParamDescriptor;
119
120
121 int JType_Check(PyObject* obj);
122
123 JPy_JType* JType_GetTypeForObject(JNIEnv* jenv, jobject objectRef, jboolean resolve);
124 JPy_JType* JType_GetTypeForName(JNIEnv* jenv, const char* typeName, jboolean resolve);
125 JPy_JType* JType_GetType(JNIEnv* jenv, jclass classRef, jboolean resolve);
126
127 PyObject* JType_ConvertJavaToPythonObject(JNIEnv* jenv, JPy_JType* type, jobject objectRef);
128 int JType_ConvertPythonToJavaObject(JNIEnv* jenv, JPy_JType* type, PyObject* arg, jobject* objectRef, jboolean allowObjectWrapping);
129
130 PyObject* JType_GetOverloadedMethod(JNIEnv* jenv, JPy_JType* type, PyObject* methodName, jboolean useSuperClass);
131
132 int JType_MatchPyArgAsJObject(JNIEnv* jenv, JPy_JType* type, PyObject* pyArg);
133
134 int JType_CreateJavaPyObject(JNIEnv* jenv, JPy_JType* type, PyObject* pyArg, jobject* objectRef);
135
136 int JType_CreateJavaArray(JNIEnv* jenv, JPy_JType* componentType, PyObject* pyArg, jobject* objectRef, jboolean allowObjectWrapping);
137
138 // Non-API. Defined in jpy_jobj.c
139 int JType_InitSlots(JPy_JType* type);
140 // Non-API. Defined in jpy_jtype.c
141 int JType_ResolveType(JNIEnv* jenv, JPy_JType* type);
142
143 int JType_AddClassAttribute(JNIEnv* jenv, JPy_JType* type);
144
145 #ifdef __cplusplus
146 } /* extern "C" */
147 #endif
148 #endif /* !JPY_JTYPE_H */