Debian Codegraph @

native/common/include/jpype.h

raw symbols SCIP
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 See NOTICE file for details.
15 *****************************************************************************/
16 #ifndef _JPYPE_H_
17 #define _JPYPE_H_
18
19 #ifdef __GNUC__
20 // Python requires char* but C++ string constants are const char*
21 #pragma GCC diagnostic ignored "-Wwrite-strings"
22 #endif
23
24 #ifdef WIN32
25
26 #ifndef __GNUC__ // Then this must mean a variant of GCC on win32 ...
27 #pragma warning (disable:4786)
28 #endif
29
30 #if defined(__CYGWIN__)
31 // jni_md.h does not work for cygwin. Use this instead.
32 #elif defined(__GNUC__)
33 // JNICALL causes problem for function prototypes .. since I am not defining any JNI methods there is no need for it
34 #undef JNICALL
35 #define JNICALL
36 #endif
37
38 #endif
39
40 #include <jni.h>
41
42 // Define this and use to allow destructors to throw in C++11 or later
43 #if defined(_MSC_VER)
44
45 // Visual Studio C++ does not seem have changed __cplusplus since 1997
46 // see: https://docs.microsoft.com/en-us/cpp/build/reference/zc-cplusplus?view=msvc-170&viewFallbackFrom=vs-2019
47 #if (_MSVC_LAND >= 201402)
48 #define NO_EXCEPT_FALSE noexcept(false)
49 #else
50 #define NO_EXCEPT_FALSE throw(JPypeException)
51 #endif
52
53 #else
54
55 // For all the compilers that understand standards
56 #if (__cplusplus >= 201103L)
57 #define NO_EXCEPT_FALSE noexcept(false)
58 #else
59 #define NO_EXCEPT_FALSE throw(JPypeException)
60 #endif
61
62 #endif
63
64 #include <map>
65 #include <string>
66 #include <vector>
67
68 using std::map;
69 using std::string;
70 using std::vector;
71
72 #ifdef JP_INSTRUMENTATION
73 #include <cstdint>
74 template <size_t i>
75 constexpr uint32_t _hash(const char *q, uint32_t v)
76 {
77 return _hash < i - 1 > (q + 1, v * 0x1a481023 + q[0]);
78 }
79
80 template <>
81 constexpr uint32_t _hash<0>(const char *q, uint32_t v)
82 {
83 return v;
84 }
85 #define compile_hash(x) _hash<sizeof(x)-1>(x, 0)
86
87 extern void PyJPModuleFault_throw(uint32_t code);
88 extern int PyJPModuleFault_check(uint32_t code);
89 #define JP_TRACE_IN(X, ...) try { PyJPModuleFault_throw(compile_hash(X));
90 #define JP_FAULT_RETURN(X, Y) if (PyJPModuleFault_check(compile_hash(X))) return Y
91 #define JP_BLOCK(X) if (PyJPModuleFault_check(compile_hash(X))==0)
92 #else
93 #define JP_FAULT_RETURN(X, Y) if (false) while (false)
94 #define JP_BLOCK(X) if (false) while (false)
95 #endif
96
97 /** Definition of commonly used template types */
98 using StringVector = vector<string>;
99
100 /**
101 * Converter are used for bulk byte transfers from Python to Java.
102 */
103 using jconverter = jvalue (*)(void *) ;
104
105 /**
106 * Create a converter for a bulk byte transfer.
107 *
108 * Bulk transfers do not check for range and may be lossy. These are only
109 * triggered when a transfer either using memoryview or a slice operator
110 * assignment from a buffer object (such as numpy.array). Converters are
111 * created once at the start of the transfer and used to convert each
112 * byte by casting the memory and then assigning to the jvalue union with
113 * the requested type.
114 *
115 * Byte order transfers are not supported by the Python buffer API and thus
116 * have not been implemented.
117 *
118 * @param from is a Python struct designation
119 * @param itemsize is the size of the Python item
120 * @param to is the desired Java primitive type
121 * @return a converter function to convert each member.
122 */
123 extern jconverter getConverter(const char* from, int itemsize, const char* to);
124
125 extern bool _jp_cpp_exceptions;
126
127 // Types
128 class JPClass;
129 class JPValue;
130 class JPProxy;
131 class JPArray;
132 class JPArrayClass;
133 class JPArrayView;
134 class JPBoxedType;
135 class JPPrimitiveType;
136 class JPStringType;
137
138 // Members
139 class JPMethod;
140 class JPMethodDispatch;
141 class JPField;
142
143 // Services
144 class JPTypeManager;
145 class JPClassLoader;
146 class JPContext;
147 class JPBuffer;
148 class JPPyObject;
149
150 extern "C" using JCleanupHook = void (*)(void *) ;
151 extern "C" struct JPConversionInfo;
152
153 using JPClassList = vector<JPClass *>;
154 using JPFieldList = vector<JPField *>;
155 using JPMethodDispatchList = vector<JPMethodDispatch *>;
156 using JPMethodList = vector<JPMethod *>;
157
158 class JPResource
159 {
160 public:
161 virtual ~JPResource() = 0;
162 } ;
163
164 // Macros for raising an exception with jpype
165 // These must be macros so that we can update the pattern and
166 // maintain the appropriate auditing information. C++ does not
167 // have a lot for facilities to make this easy.
168 #define JP_RAISE_PYTHON() { throw JPypeException(JPError::_python_error, nullptr, JP_STACKINFO()); }
169 #define JP_RAISE_OS_ERROR_UNIX(err, msg) { throw JPypeException(JPError::_os_error_unix, msg, err, JP_STACKINFO()); }
170 #define JP_RAISE_OS_ERROR_WINDOWS(err, msg) { throw JPypeException(JPError::_os_error_windows, msg, err, JP_STACKINFO()); }
171 #define JP_RAISE(type, msg) { throw JPypeException(JPError::_python_exc, type, msg, JP_STACKINFO()); }
172
173 #ifndef PyObject_HEAD
174 struct _object;
175 using PyObject = _object;
176 #endif
177
178 #include "jp_pythontypes.h"
179
180 template <typename... T>
181 static inline JPPyObject JPPyTuple_Pack(T... args) {
182 return JPPyObject::call(PyTuple_Pack(sizeof...(T), args...));
183 }
184
185 // Base utility headers
186 #include "jp_javaframe.h"
187 #include "jp_context.h"
188 #include "jp_exception.h"
189 #include "jp_tracer.h"
190 #include "jp_typemanager.h"
191 #include "jp_encoding.h"
192 #include "jp_modifier.h"
193 #include "jp_match.h"
194
195 // Other header files
196 #include "jp_classhints.h"
197 #include "jp_method.h"
198 #include "jp_value.h"
199 #include "jp_class.h"
200
201 // Primitives classes
202 #include "jp_primitivetype.h"
203
204 #endif // _JPYPE_H_