| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
#ifndef PYJP_H |
| 17 |
#define PYJP_H |
| 18 |
#include <Python.h> |
| 19 |
#include "jpype.h" |
| 20 |
#include "jp_pythontypes.h" |
| 21 |
|
| 22 |
class JPStackInfo; |
| 23 |
#ifdef JP_TRACING_ENABLE |
| 24 |
#define JP_PY_TRY(...) \ |
| 25 |
JPypeTracer _trace(__VA_ARGS__); \ |
| 26 |
try { do {} while(0) |
| 27 |
#define JP_PY_CATCH(...) \ |
| 28 |
} catch(...) { \ |
| 29 |
PyJPModule_rethrow(JP_STACKINFO()); } \ |
| 30 |
return __VA_ARGS__ |
| 31 |
#define JP_PY_CATCH_NONE(...) } catch(...) {} return __VA_ARGS__ |
| 32 |
#else |
| 33 |
#ifndef JP_INSTRUMENTATION |
| 34 |
#define JP_PY_TRY(...) try { do {} while(0) |
| 35 |
#else |
| 36 |
#define JP_PY_TRY(...) JP_TRACE_IN(__VA_ARGS__) |
| 37 |
#endif |
| 38 |
#define JP_PY_CATCH(...) } catch(...) \ |
| 39 |
{ PyJPModule_rethrow(JP_STACKINFO()); } \ |
| 40 |
return __VA_ARGS__ |
| 41 |
#define JP_PY_CATCH_NONE(...) } catch(...) {} return __VA_ARGS__ |
| 42 |
#endif |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
#define JP_PY_CHECK() { if (PyErr_Occurred() != 0) JP_RAISE_PYTHON(); } // GCOVR_EXCL_LINE |
| 47 |
|
| 48 |
#ifdef __cplusplus |
| 49 |
extern "C" |
| 50 |
{ |
| 51 |
#endif |
| 52 |
|
| 53 |
|
| 54 |
#ifndef Py_TRASHCAN_BEGIN |
| 55 |
|
| 56 |
#define Py_TRASHCAN_BEGIN(X, Y) |
| 57 |
#define Py_TRASHCAN_END |
| 58 |
#endif |
| 59 |
|
| 60 |
PyMODINIT_FUNC PyInit__jpype(); |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
void PyJP_SetStringWithCause(PyObject *exception, const char *str); |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
PyObject* PyJP_GetAttrDescriptor(PyTypeObject *type, PyObject *attr_name); |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
int PyJP_IsInstanceSingle(PyObject* obj, PyTypeObject* type); |
| 91 |
int PyJP_IsSubClassSingle(PyTypeObject* type, PyTypeObject* obj); |
| 92 |
|
| 93 |
struct PyJPArray |
| 94 |
{ |
| 95 |
PyObject_HEAD |
| 96 |
JPArray *m_Array; |
| 97 |
JPArrayView *m_View; |
| 98 |
} ; |
| 99 |
|
| 100 |
struct PyJPClassHints |
| 101 |
{ |
| 102 |
PyObject_HEAD |
| 103 |
JPClassHints *m_Hints; |
| 104 |
} ; |
| 105 |
|
| 106 |
struct PyJPProxy |
| 107 |
{ |
| 108 |
PyObject_HEAD |
| 109 |
JPProxy* m_Proxy; |
| 110 |
PyObject* m_Target; |
| 111 |
PyObject* m_Dispatch; |
| 112 |
bool m_Convert; |
| 113 |
} ; |
| 114 |
|
| 115 |
struct JPConversionInfo |
| 116 |
{ |
| 117 |
PyObject *ret; |
| 118 |
PyObject *exact; |
| 119 |
PyObject *implicit; |
| 120 |
PyObject *attributes; |
| 121 |
PyObject *expl; |
| 122 |
PyObject *none; |
| 123 |
} ; |
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
extern PyTypeObject *PyJPArray_Type; |
| 128 |
extern PyTypeObject *PyJPArrayPrimitive_Type; |
| 129 |
extern PyTypeObject *PyJPBuffer_Type; |
| 130 |
extern PyTypeObject *PyJPClass_Type; |
| 131 |
extern PyTypeObject *PyJPComparable_Type; |
| 132 |
extern PyTypeObject *PyJPMethod_Type; |
| 133 |
extern PyTypeObject *PyJPObject_Type; |
| 134 |
extern PyTypeObject *PyJPProxy_Type; |
| 135 |
extern PyTypeObject *PyJPException_Type; |
| 136 |
extern PyTypeObject *PyJPNumberLong_Type; |
| 137 |
extern PyTypeObject *PyJPNumberFloat_Type; |
| 138 |
extern PyTypeObject *PyJPNumberBool_Type; |
| 139 |
extern PyTypeObject *PyJPChar_Type; |
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
extern PyObject *PyJPModule; |
| 144 |
extern PyObject *_JArray; |
| 145 |
extern PyObject *_JChar; |
| 146 |
extern PyObject *_JObject; |
| 147 |
extern PyObject *_JInterface; |
| 148 |
extern PyObject *_JException; |
| 149 |
extern PyObject *_JClassPre; |
| 150 |
extern PyObject *_JClassPost; |
| 151 |
extern PyObject *_JClassDoc; |
| 152 |
extern PyObject *_JMethodDoc; |
| 153 |
extern PyObject *_JMethodAnnotations; |
| 154 |
extern PyObject *_JMethodCode; |
| 155 |
extern PyObject *_JObjectKey; |
| 156 |
extern PyObject *_JVMNotRunning; |
| 157 |
extern PyObject* PyJPClassMagic; |
| 158 |
|
| 159 |
extern JPContext* JPContext_global; |
| 160 |
|
| 161 |
|
| 162 |
int PyJPClass_Check(PyObject* obj); |
| 163 |
PyObject *PyJPClass_FromSpecWithBases(PyType_Spec *spec, PyObject *bases); |
| 164 |
|
| 165 |
|
| 166 |
PyObject *PyJPValue_alloc(PyTypeObject* type, Py_ssize_t nitems ); |
| 167 |
void PyJPValue_free(void* obj); |
| 168 |
void PyJPValue_finalize(void* obj); |
| 169 |
int PyJPValue_traverse(PyObject *self, visitproc visit, void *arg); |
| 170 |
int PyJPValue_clear(PyObject *self); |
| 171 |
|
| 172 |
|
| 173 |
PyObject *PyJPValue_str(PyObject* self); |
| 174 |
bool PyJPValue_hasJavaSlot(PyTypeObject* type); |
| 175 |
Py_ssize_t PyJPValue_getJavaSlotOffset(PyObject* self); |
| 176 |
JPValue *PyJPValue_getJavaSlot(PyObject* obj); |
| 177 |
|
| 178 |
|
| 179 |
PyObject *PyJPModule_getClass(PyObject* module, PyObject *obj); |
| 180 |
PyObject *PyJPValue_getattro(PyObject *obj, PyObject *name); |
| 181 |
int PyJPValue_setattro(PyObject *self, PyObject *name, PyObject *value); |
| 182 |
PyObject *PyJPChar_Create(PyTypeObject *type, Py_UCS2 p); |
| 183 |
|
| 184 |
#ifdef __cplusplus |
| 185 |
} |
| 186 |
#endif |
| 187 |
|
| 188 |
void PyJPClass_hook(JPJavaFrame &frame, JPClass* cls); |
| 189 |
|
| 190 |
|
| 191 |
JPPyObject PyJPArray_create(JPJavaFrame &frame, PyTypeObject* wrapper, const JPValue& value); |
| 192 |
JPPyObject PyJPBuffer_create(JPJavaFrame &frame, PyTypeObject *type, const JPValue & value); |
| 193 |
JPPyObject PyJPClass_create(JPJavaFrame &frame, JPClass* cls); |
| 194 |
JPPyObject PyJPNumber_create(JPJavaFrame &frame, JPPyObject& wrapper, const JPValue& value); |
| 195 |
JPPyObject PyJPField_create(JPField* m); |
| 196 |
JPPyObject PyJPMethod_create(JPMethodDispatch *m, PyObject *instance); |
| 197 |
|
| 198 |
JPClass* PyJPClass_getJPClass(PyObject* obj); |
| 199 |
JPProxy* PyJPProxy_getJPProxy(PyObject* obj); |
| 200 |
void PyJPModule_rethrow(const JPStackInfo& info); |
| 201 |
void PyJPValue_assignJavaSlot(JPJavaFrame &frame, PyObject* obj, const JPValue& value); |
| 202 |
bool PyJPValue_isSetJavaSlot(PyObject* self); |
| 203 |
JPPyObject PyTrace_FromJavaException(JPJavaFrame& frame, jthrowable th, jthrowable prev); |
| 204 |
void PyJPException_normalize(JPJavaFrame frame, JPPyObject exc, jthrowable th, jthrowable enclosing); |
| 205 |
|
| 206 |
#define _ASSERT_JVM_RUNNING(context) assertJVMRunning((JPContext*)context, JP_STACKINFO()) |
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
inline JPContext* PyJPModule_getContext() |
| 219 |
{ |
| 220 |
#ifdef JP_INSTRUMENTATION |
| 221 |
PyJPModuleFault_throw(compile_hash("PyJPModule_getContext")); |
| 222 |
#endif |
| 223 |
JPContext* context = JPContext_global; |
| 224 |
_ASSERT_JVM_RUNNING(context); |
| 225 |
return context; |
| 226 |
} |
| 227 |
void PyJPModule_loadResources(PyObject* module); |
| 228 |
|
| 229 |
#endif |