return map;
}
-JNIEXPORT void JNICALL Java_org_simantics_pythonlink_PythonContext_setPythonBooleanVariableImpl(JNIEnv *env, jobject thisObj, jlong contextID, jstring variableName, jboolean value) {
- PyObject *module = (PyObject*)contextID;
-
- PyObject *pythonName = getPythonString(env, variableName);
- PyObject *val = getPythonBool(value);
-
- setPythonVariable(module, pythonName, val);
-}
-
-JNIEXPORT void JNICALL Java_org_simantics_pythonlink_PythonContext_setPythonBooleanArrayVariableImpl(JNIEnv *env, jobject thisObj, jlong contextID, jstring variableName, jbooleanArray value) {
- PyObject *module = (PyObject*)contextID;
-
- PyObject *pythonName = getPythonString(env, variableName);
- PyObject *val = getPythonBooleanList(env, value);
-
- setPythonVariable(module, pythonName, val);
-}
-
-JNIEXPORT void JNICALL Java_org_simantics_pythonlink_PythonContext_setPythonLongVariableImpl(JNIEnv *env, jobject thisObj, jlong contextID, jstring variableName, jlong value) {
- PyObject *module = (PyObject*)contextID;
-
- PyObject *pythonName = getPythonString(env, variableName);
- PyObject *val = PyLong_FromLongLong(value);
-
- setPythonVariable(module, pythonName, val);
-}
-
-JNIEXPORT void JNICALL Java_org_simantics_pythonlink_PythonContext_setPythonIntegerArrayVariableImpl(JNIEnv *env, jobject thisObj, jlong contextID, jstring variableName, jintArray value) {
- PyObject *module = (PyObject*)contextID;
-
- PyObject *pythonName = getPythonString(env, variableName);
- PyObject *val = getPythonIntegerList(env, value);
-
- setPythonVariable(module, pythonName, val);
-}
-
-JNIEXPORT void JNICALL Java_org_simantics_pythonlink_PythonContext_setPythonLongArrayVariableImpl(JNIEnv *env, jobject thisObj, jlong contextID, jstring variableName, jlongArray value) {
- PyObject *module = (PyObject*)contextID;
-
- PyObject *pythonName = getPythonString(env, variableName);
- PyObject *val = getPythonLongList(env, value);
-
- setPythonVariable(module, pythonName, val);
-}
-
-JNIEXPORT void JNICALL Java_org_simantics_pythonlink_PythonContext_setPythonDoubleVariableImpl(JNIEnv *env, jobject thisObj, jlong contextID, jstring variableName, jdouble value) {
- PyObject *module = (PyObject*)contextID;
-
- PyObject *pythonName = getPythonString(env, variableName);
- PyObject *val = PyFloat_FromDouble(value);
-
- setPythonVariable(module, pythonName, val);
-}
-
-JNIEXPORT void JNICALL Java_org_simantics_pythonlink_PythonContext_setPythonFloatArrayVariableImpl(JNIEnv *env, jobject thisObj, jlong contextID, jstring variableName, jfloatArray value) {
- PyObject *module = (PyObject*)contextID;
-
- PyObject *pythonName = getPythonString(env, variableName);
- PyObject *val = getPythonFloatList(env, value);
-
- setPythonVariable(module, pythonName, val);
-}
-
-JNIEXPORT void JNICALL Java_org_simantics_pythonlink_PythonContext_setPythonDoubleArrayVariableImpl(JNIEnv *env, jobject thisObj, jlong contextID, jstring variableName, jdoubleArray value) {
- PyObject *module = (PyObject*)contextID;
-
- PyObject *pythonName = getPythonString(env, variableName);
- PyObject *val = getPythonDoubleList(env, value);
-
- setPythonVariable(module, pythonName, val);
-}
-
-JNIEXPORT void JNICALL Java_org_simantics_pythonlink_PythonContext_setPythonStringVariableImpl(JNIEnv *env, jobject thisObj, jlong contextID, jstring variableName, jstring value) {
- PyObject *module = (PyObject*)contextID;
-
- PyObject *pythonName = getPythonString(env, variableName);
- PyObject *val = getPythonString(env, value);
-
- setPythonVariable(module, pythonName, val);
-}
-
-JNIEXPORT void JNICALL Java_org_simantics_pythonlink_PythonContext_setPythonStringArrayVariableImpl(JNIEnv *env, jobject thisObj, jlong contextID, jstring variableName, jobjectArray value) {
- PyObject *module = (PyObject*)contextID;
-
- PyObject *pythonName = getPythonString(env, variableName);
- PyObject *val = getPythonStringList(env, value);
-
- setPythonVariable(module, pythonName, val);
-}
+#define DEF_SETTER(typename, jtype, j2py) \
+ JNIEXPORT void JNICALL \
+ Java_org_simantics_pythonlink_PythonContext_setPython \
+ ##typename##VariableImpl( \
+ JNIEnv *env, jobject thisObj, jlong contextID, jstring variableName, \
+ jtype value) { \
+ PyObject *module = (PyObject*)contextID; \
+ \
+ PyEval_RestoreThread(main_ts); \
+ setPythonVariable(module, getPythonString(env, variableName), \
+ j2py(env, value)); \
+ PyEval_SaveThread(); \
+ }
-JNIEXPORT void JNICALL Java_org_simantics_pythonlink_PythonContext_setPythonNDArrayVariableImpl(JNIEnv *env, jobject thisObj, jlong contextID, jstring variableName, jobject value) {
+#define getPythonBoolean(env, value) getPythonBool(value)
+#define getPythonLong(env, value) PyLong_FromLongLong(value)
+#define getPythonDouble(env, value) PyFloat_FromDouble(value)
+
+DEF_SETTER(Boolean, jboolean, getPythonBoolean)
+DEF_SETTER(BooleanArray, jbooleanArray, getPythonBooleanList)
+DEF_SETTER(Long, jlong, getPythonLong)
+DEF_SETTER(IntegerArray, jintArray, getPythonIntegerList)
+DEF_SETTER(LongArray, jlongArray, getPythonLongList)
+DEF_SETTER(Double, jdouble, getPythonDouble)
+DEF_SETTER(FloatArray, jfloatArray, getPythonFloatList)
+DEF_SETTER(DoubleArray, jdoubleArray, getPythonDoubleList)
+DEF_SETTER(String, jstring, getPythonString)
+DEF_SETTER(StringArray, jobjectArray, getPythonStringList)
+
+JNIEXPORT void JNICALL
+Java_org_simantics_pythonlink_PythonContext_setPythonNDArrayVariableImpl(
+ JNIEnv *env, jobject thisObj, jlong contextID, jstring variableName,
+ jobject value) {
PyObject *module = (PyObject*)contextID;
if (!hasNumpy) {
return;
}
+ PyEval_RestoreThread(main_ts);
{
PyObject *pythonName = getPythonString(env, variableName);
PyObject *val = getPythonNDArray(env, value);
setPythonVariable(module, pythonName, val);
}
+ PyEval_SaveThread();
}
-JNIEXPORT void JNICALL Java_org_simantics_pythonlink_PythonContext_setPythonVariantVariableImpl(JNIEnv *env, jobject thisObj, jlong contextID, jstring variableName, jobject value, jobject binding) {
+JNIEXPORT void JNICALL
+Java_org_simantics_pythonlink_PythonContext_setPythonVariantVariableImpl(
+ JNIEnv *env, jobject thisObj, jlong contextID, jstring variableName,
+ jobject value, jobject binding) {
PyObject *module = (PyObject*)contextID;
- PyObject *pythonName = getPythonString(env, variableName);
- PyObject *val = getPythonObject(env, value, binding);
-
- setPythonVariable(module, pythonName, val);
+ PyEval_RestoreThread(main_ts);
+ setPythonVariable(module, getPythonString(env, variableName),
+ getPythonObject(env, value, binding));
+ PyEval_SaveThread();
}
-JNIEXPORT jint JNICALL Java_org_simantics_pythonlink_PythonContext_executePythonStatementImpl(JNIEnv *env, jobject thisObj, jlong contextID, jstring statement) {
+JNIEXPORT jint JNICALL
+Java_org_simantics_pythonlink_PythonContext_executePythonStatementImpl(
+ JNIEnv *env, jobject thisObj, jlong contextID, jstring statement) {
PyObject *module = (PyObject*)contextID;
const char *utfchars = (*env)->GetStringUTFChars(env, statement, NULL);