| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
#ifndef _JPYPE_H_ |
| 17 |
#define _JPYPE_H_ |
| 18 |
|
| 19 |
#ifdef __GNUC__ |
| 20 |
|
| 21 |
#pragma GCC diagnostic ignored "-Wwrite-strings" |
| 22 |
#endif |
| 23 |
|
| 24 |
#ifdef WIN32 |
| 25 |
|
| 26 |
#ifndef __GNUC__ |
| 27 |
#pragma warning (disable:4786) |
| 28 |
#endif |
| 29 |
|
| 30 |
#if defined(__CYGWIN__) |
| 31 |
|
| 32 |
#elif defined(__GNUC__) |
| 33 |
|
| 34 |
#undef JNICALL |
| 35 |
#define JNICALL |
| 36 |
#endif |
| 37 |
|
| 38 |
#endif |
| 39 |
|
| 40 |
#include <jni.h> |
| 41 |
|
| 42 |
|
| 43 |
#if defined(_MSC_VER) |
| 44 |
|
| 45 |
|
| 46 |
|
| 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 |
|
| 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 |
|
| 98 |
using StringVector = vector<string>; |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
using jconverter = jvalue (*)(void *) ; |
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
extern jconverter getConverter(const char* from, int itemsize, const char* to); |
| 124 |
|
| 125 |
extern bool _jp_cpp_exceptions; |
| 126 |
|
| 127 |
|
| 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 |
|
| 139 |
class JPMethod; |
| 140 |
class JPMethodDispatch; |
| 141 |
class JPField; |
| 142 |
|
| 143 |
|
| 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 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 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 |
|
| 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 |
|
| 196 |
#include "jp_classhints.h" |
| 197 |
#include "jp_method.h" |
| 198 |
#include "jp_value.h" |
| 199 |
#include "jp_class.h" |
| 200 |
|
| 201 |
|
| 202 |
#include "jp_primitivetype.h" |
| 203 |
|
| 204 |
#endif |