From b024b0b0ceec797d193b0505d1fdd54f95bcaa10 Mon Sep 17 00:00:00 2001 From: Reino Ruusu Date: Wed, 25 Jan 2017 18:51:02 +0200 Subject: [PATCH] Python tweaks - Changed the way context modules are created - Allow Python to produce SCL console output Change-Id: I41e8b876d55db8815959ebc90487c3e481f4604b --- .../jnipython.dll | Bin 33792 -> 35328 bytes .../src/sclpy.c | 143 ++++++++++++++---- .../src/sclpy.h | 3 + .../simantics/pythonlink/PythonContext.java | 11 +- 4 files changed, 125 insertions(+), 32 deletions(-) diff --git a/org.simantics.pythonlink.win32.x86_64/jnipython.dll b/org.simantics.pythonlink.win32.x86_64/jnipython.dll index 7fff774adac1bb1b1d2c5ffbffa6043e44d877e1..1770fb739bc91fd7193ea478c320ecd35812dbe6 100644 GIT binary patch literal 35328 zcmeHwdwf*Ywg1jzAV9(d$VfoIL4u9eLLgX!0nLyE&%gu&1VjNRVKRYeNT!n+3%wSx zNh1|Nvl_WZtU?S1BvOb8Y4KfjN| z=Va}(A8W6*_S$Q&z4o4=z4Z~R@yxkwY7Bt`!cWHAFQ=k*V>D&nr~lOSLvOQmNqa;p&qmH=r6BL zee8t!%nyt`u?X*bW?Xb)F`(nl3HrV1DJ>SF^2Zj@_VT(#W?q*#-##dDpb+zrbD7M&dof@-r`IMBpmd@T7W#va z2}L_zNO<@piUL%XjZDzkLTqdlqEt4Qe;*a%?+PDhvborU4eM02X z!1nT)5b&-FpzJy7JRJ}59^Efq?Lw4K@K;s@Duj458yUbUF2b`APt>OX>M}uA6A$%6 z!A3kJrnPvYJ_SOwP4LNz%;Tddr20RKs)S?#;q!ZI>O3HTirVlHzIAw_J_SO|hu4B3 zs9S=RIkhk)kcSpN*XuiLMJy6ogJdU)Gln5YSwZg~*x0z-^+$0p8bu}wg$&hbX;z0l%@ zQ()S16ROltkvWb{uqhNS8c)b0M zE2ot+K;t?jNNOZKITpEXQ7S`&TvurH`TVY)!X) z&_c-eGROP1T}4@T&@LRtT_N7a$gP=M*Nl7^6o){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z2|nT1Nb71b_GdttGB6KNU_GGwbUSeFAj8mFppHa! zSvF%&BN4qB7@LE+0XiA@G7@!oJJ90JHC&erOvuCRCLy5r2t>FSX*u|WCy^F_J_Fp7 z59OfSfNu>k=oa8BLk)U6@V5fS-h>P*WGo6R<2YzqA@3oP5pG&CWh0CXtq@u+R6sbj z$e^)&*!PmAWp#J4!KdYA!b&1}T5?ZInpRgjRvGbWwY?>2-$R?(j*i$d{y)Pa5bR;3 z??5*L6H1KAz9%%_)0ywdj816JAWcVOgxio*(1bk^9|}MdCLm>iCagt@0bM%=hF@K!1XQy81X5P zZ9w26y5pqhMuv`jl}^SEfF^tm=}pjtS0qgsf+$CPigrgQ7>ayPZ@#BLI`N%D3SMTQ z4*DAE5+=GZsX^xe-Rma7?GU2ySvJ{FssjIvR0%%a7Y-s(067EHkzAm0abfe3NM-?W z&s0Q7(EEVD-GUeanoVP@7>Rmp2R=5PvA=-75vbz8w{ID{OAuAaPy^M#jYwn=VVk5~ zGZFindClass(env, WRITER_CLASS); + jmethodID writeMethod = (*env)->GetMethodID(env, writerClass, "write", "([CII)V"); + jcharArray chars = (*env)->NewCharArray(env, (jsize)length); + + (*env)->SetCharArrayRegion(env, chars, 0, length, what); + (*env)->CallVoidMethod(env, sclWriter, writeMethod, chars, 0, length); + } + } + + return Py_BuildValue(""); +} + +static PyMethodDef sclWriterMethods[] = { + {"write", writeToSCL, METH_VARARGS, "Write something."}, + {NULL, NULL, 0, NULL} +}; + + JNIEXPORT jlong JNICALL Java_org_simantics_pythonlink_PythonContext_createContextImpl(JNIEnv *env, jobject thisObj) { char name[16]; @@ -43,6 +81,15 @@ JNIEXPORT jlong JNICALL Java_org_simantics_pythonlink_PythonContext_createContex Py_Initialize(); initCalled = 1; + { + static struct PyModuleDef moduledef = { PyModuleDef_HEAD_INIT, "sclwriter", NULL, -1, sclWriterMethods, }; + PyObject *m = PyModule_Create(&moduledef); + + if (m == NULL) throwException(env, PYTHON_EXCEPTION, "Failed to create SCL writer module"); + PySys_SetObject("stdout", m); + PySys_SetObject("stderr", m); + } + hasNumpy = _import_array(); hasNumpy = hasNumpy != -1; } @@ -50,18 +97,35 @@ JNIEXPORT jlong JNICALL Java_org_simantics_pythonlink_PythonContext_createContex sprintf(name, "SCL_%d", ++moduleCount); { - PyObject *module = PyModule_New(name); - PyObject *main = PyImport_AddModule("__main__"); + PyObject *module; + PyModuleDef *modDef = malloc(sizeof(PyModuleDef)); + memset(modDef, 0, sizeof(PyModuleDef)); + modDef->m_name = strdup(name); + modDef->m_doc = NULL; + modDef->m_size = -1; - PyDict_Merge(PyModule_GetDict(module), PyModule_GetDict(main), 0); + module = PyModule_Create(modDef); + Py_INCREF(module); + PyState_AddModule(module, modDef); - return (jlong)module; + { + PyObject *builtin = PyImport_AddModule("builtins"); + PyObject *dict = PyModule_GetDict(module); + PyDict_SetItemString(dict, "__builtin__", builtin); + PyDict_SetItemString(dict, "__builtins__", builtin); + + return (jlong)modDef; + } } } JNIEXPORT void JNICALL Java_org_simantics_pythonlink_PythonContext_deleteContextImpl(JNIEnv *env, jobject thisObj, jlong contextID) { - PyObject *module = (PyObject*)contextID; + PyModuleDef *modDef = (PyModuleDef*)contextID; + PyObject *module = PyState_FindModule(modDef); Py_XDECREF(module); + PyState_RemoveModule(modDef); + free((char*)modDef->m_name); + free(modDef); } PyObject *getPythonBool(jboolean value) { @@ -783,7 +847,7 @@ jobject pythonDictionaryAsMap(JNIEnv *env, PyObject *dict) { } JNIEXPORT void JNICALL Java_org_simantics_pythonlink_PythonContext_setPythonBooleanVariableImpl(JNIEnv *env, jobject thisObj, jlong contextID, jstring variableName, jboolean value) { - PyObject *module = (PyObject*)contextID; + PyObject *module = getModule(contextID); PyObject *pythonName = getPythonString(env, variableName); PyObject *val = getPythonBool(value); @@ -792,7 +856,7 @@ JNIEXPORT void JNICALL Java_org_simantics_pythonlink_PythonContext_setPythonBool } JNIEXPORT void JNICALL Java_org_simantics_pythonlink_PythonContext_setPythonBooleanArrayVariableImpl(JNIEnv *env, jobject thisObj, jlong contextID, jstring variableName, jbooleanArray value) { - PyObject *module = (PyObject*)contextID; + PyObject *module = getModule(contextID); PyObject *pythonName = getPythonString(env, variableName); PyObject *val = getPythonBooleanList(env, value); @@ -801,7 +865,7 @@ JNIEXPORT void JNICALL Java_org_simantics_pythonlink_PythonContext_setPythonBool } JNIEXPORT void JNICALL Java_org_simantics_pythonlink_PythonContext_setPythonLongVariableImpl(JNIEnv *env, jobject thisObj, jlong contextID, jstring variableName, jlong value) { - PyObject *module = (PyObject*)contextID; + PyObject *module = getModule(contextID); PyObject *pythonName = getPythonString(env, variableName); PyObject *val = PyLong_FromLongLong(value); @@ -810,7 +874,7 @@ JNIEXPORT void JNICALL Java_org_simantics_pythonlink_PythonContext_setPythonLong } JNIEXPORT void JNICALL Java_org_simantics_pythonlink_PythonContext_setPythonIntegerArrayVariableImpl(JNIEnv *env, jobject thisObj, jlong contextID, jstring variableName, jintArray value) { - PyObject *module = (PyObject*)contextID; + PyObject *module = getModule(contextID); PyObject *pythonName = getPythonString(env, variableName); PyObject *val = getPythonIntegerList(env, value); @@ -819,7 +883,7 @@ JNIEXPORT void JNICALL Java_org_simantics_pythonlink_PythonContext_setPythonInte } JNIEXPORT void JNICALL Java_org_simantics_pythonlink_PythonContext_setPythonLongArrayVariableImpl(JNIEnv *env, jobject thisObj, jlong contextID, jstring variableName, jlongArray value) { - PyObject *module = (PyObject*)contextID; + PyObject *module = getModule(contextID); PyObject *pythonName = getPythonString(env, variableName); PyObject *val = getPythonLongList(env, value); @@ -828,7 +892,7 @@ JNIEXPORT void JNICALL Java_org_simantics_pythonlink_PythonContext_setPythonLong } JNIEXPORT void JNICALL Java_org_simantics_pythonlink_PythonContext_setPythonDoubleVariableImpl(JNIEnv *env, jobject thisObj, jlong contextID, jstring variableName, jdouble value) { - PyObject *module = (PyObject*)contextID; + PyObject *module = getModule(contextID); PyObject *pythonName = getPythonString(env, variableName); PyObject *val = PyFloat_FromDouble(value); @@ -837,7 +901,7 @@ JNIEXPORT void JNICALL Java_org_simantics_pythonlink_PythonContext_setPythonDoub } JNIEXPORT void JNICALL Java_org_simantics_pythonlink_PythonContext_setPythonFloatArrayVariableImpl(JNIEnv *env, jobject thisObj, jlong contextID, jstring variableName, jfloatArray value) { - PyObject *module = (PyObject*)contextID; + PyObject *module = getModule(contextID); PyObject *pythonName = getPythonString(env, variableName); PyObject *val = getPythonFloatList(env, value); @@ -846,7 +910,7 @@ JNIEXPORT void JNICALL Java_org_simantics_pythonlink_PythonContext_setPythonFloa } JNIEXPORT void JNICALL Java_org_simantics_pythonlink_PythonContext_setPythonDoubleArrayVariableImpl(JNIEnv *env, jobject thisObj, jlong contextID, jstring variableName, jdoubleArray value) { - PyObject *module = (PyObject*)contextID; + PyObject *module = getModule(contextID); PyObject *pythonName = getPythonString(env, variableName); PyObject *val = getPythonDoubleList(env, value); @@ -855,7 +919,7 @@ JNIEXPORT void JNICALL Java_org_simantics_pythonlink_PythonContext_setPythonDoub } JNIEXPORT void JNICALL Java_org_simantics_pythonlink_PythonContext_setPythonStringVariableImpl(JNIEnv *env, jobject thisObj, jlong contextID, jstring variableName, jstring value) { - PyObject *module = (PyObject*)contextID; + PyObject *module = getModule(contextID); PyObject *pythonName = getPythonString(env, variableName); PyObject *val = getPythonString(env, value); @@ -864,7 +928,7 @@ JNIEXPORT void JNICALL Java_org_simantics_pythonlink_PythonContext_setPythonStri } JNIEXPORT void JNICALL Java_org_simantics_pythonlink_PythonContext_setPythonStringArrayVariableImpl(JNIEnv *env, jobject thisObj, jlong contextID, jstring variableName, jobjectArray value) { - PyObject *module = (PyObject*)contextID; + PyObject *module = getModule(contextID); PyObject *pythonName = getPythonString(env, variableName); PyObject *val = getPythonStringList(env, value); @@ -873,7 +937,7 @@ JNIEXPORT void JNICALL Java_org_simantics_pythonlink_PythonContext_setPythonStri } JNIEXPORT void JNICALL Java_org_simantics_pythonlink_PythonContext_setPythonNDArrayVariableImpl(JNIEnv *env, jobject thisObj, jlong contextID, jstring variableName, jobject value) { - PyObject *module = (PyObject*)contextID; + PyObject *module = getModule(contextID); if (!hasNumpy) { throwPythonException(env, "Importing numpy failed"); @@ -889,7 +953,7 @@ JNIEXPORT void JNICALL Java_org_simantics_pythonlink_PythonContext_setPythonNDAr } 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 *module = getModule(contextID); PyObject *pythonName = getPythonString(env, variableName); PyObject *val = getPythonObject(env, value, binding); @@ -898,16 +962,26 @@ JNIEXPORT void JNICALL Java_org_simantics_pythonlink_PythonContext_setPythonVari } JNIEXPORT jint JNICALL Java_org_simantics_pythonlink_PythonContext_executePythonStatementImpl(JNIEnv *env, jobject thisObj, jlong contextID, jstring statement) { - PyObject *module = (PyObject*)contextID; + PyObject *module = getModule(contextID); const char *utfchars = (*env)->GetStringUTFChars(env, statement, NULL); PyErr_Clear(); { + jclass sclReportingWriterClass = (*env)->FindClass(env, SCL_REPORTING_WRITER_CLASS); + jmethodID constructor = (*env)->GetMethodID(env, sclReportingWriterClass, "", "()V"); + jmethodID flushMethod = (*env)->GetMethodID(env, sclReportingWriterClass, "flush", "()V"); + PyObject *globals; globals = PyModule_GetDict(module); + currentEnv = env; + if (sclReportingWriterClass && constructor) + sclWriter = (*env)->NewObject(env, sclReportingWriterClass, constructor); + else + sclWriter = NULL; + { PyObject *result = PyRun_String(utfchars, Py_file_input, globals, globals); @@ -951,13 +1025,20 @@ JNIEXPORT jint JNICALL Java_org_simantics_pythonlink_PythonContext_executePython (*env)->ReleaseStringUTFChars(env, statement, utfchars); + if (sclWriter != NULL) { + (*env)->CallVoidMethod(env, sclWriter, flushMethod); + } + + currentEnv = NULL; + sclWriter = NULL; + return result != NULL ? 0 : 1; } } } JNIEXPORT jstring JNICALL Java_org_simantics_pythonlink_PythonContext_getPythonStringVariableImpl(JNIEnv *env, jobject thisObj, jlong contextID, jstring variableName) { - PyObject *module = (PyObject*)contextID; + PyObject *module = getModule(contextID); PyObject *pythonName = getPythonString(env, variableName); @@ -979,7 +1060,7 @@ JNIEXPORT jstring JNICALL Java_org_simantics_pythonlink_PythonContext_getPythonS } JNIEXPORT jobjectArray JNICALL Java_org_simantics_pythonlink_PythonContext_getPythonStringArrayVariableImpl(JNIEnv *env, jobject thisObj, jlong contextID, jstring variableName) { - PyObject *module = (PyObject*)contextID; + PyObject *module = getModule(contextID); PyObject *pythonName = getPythonString(env, variableName); @@ -1001,7 +1082,7 @@ JNIEXPORT jobjectArray JNICALL Java_org_simantics_pythonlink_PythonContext_getPy } JNIEXPORT jboolean JNICALL Java_org_simantics_pythonlink_PythonContext_getPythonBooleanVariableImpl(JNIEnv *env, jobject thisObj, jlong contextID, jstring variableName) { - PyObject *module = (PyObject*)contextID; + PyObject *module = getModule(contextID); PyObject *pythonName = getPythonString(env, variableName); @@ -1020,7 +1101,7 @@ JNIEXPORT jboolean JNICALL Java_org_simantics_pythonlink_PythonContext_getPython } JNIEXPORT jbooleanArray JNICALL Java_org_simantics_pythonlink_PythonContext_getPythonBooleanArrayVariableImpl(JNIEnv *env, jobject thisObj, jlong contextID, jstring variableName) { - PyObject *module = (PyObject*)contextID; + PyObject *module = getModule(contextID); PyObject *pythonName = getPythonString(env, variableName); @@ -1042,7 +1123,7 @@ JNIEXPORT jbooleanArray JNICALL Java_org_simantics_pythonlink_PythonContext_getP } JNIEXPORT jlong JNICALL Java_org_simantics_pythonlink_PythonContext_getPythonLongVariableImpl(JNIEnv *env, jobject thisObj, jlong contextID, jstring variableName) { - PyObject *module = (PyObject*)contextID; + PyObject *module = getModule(contextID); PyObject *pythonName = getPythonString(env, variableName); @@ -1064,7 +1145,7 @@ JNIEXPORT jlong JNICALL Java_org_simantics_pythonlink_PythonContext_getPythonLon } JNIEXPORT jintArray JNICALL Java_org_simantics_pythonlink_PythonContext_getPythonIntegerArrayVariableImpl(JNIEnv *env, jobject thisObj, jlong contextID, jstring variableName) { - PyObject *module = (PyObject*)contextID; + PyObject *module = getModule(contextID); PyObject *pythonName = getPythonString(env, variableName); @@ -1086,7 +1167,7 @@ JNIEXPORT jintArray JNICALL Java_org_simantics_pythonlink_PythonContext_getPytho } JNIEXPORT jlongArray JNICALL Java_org_simantics_pythonlink_PythonContext_getPythonLongArrayVariableImpl(JNIEnv *env, jobject thisObj, jlong contextID, jstring variableName) { - PyObject *module = (PyObject*)contextID; + PyObject *module = getModule(contextID); PyObject *pythonName = getPythonString(env, variableName); @@ -1108,7 +1189,7 @@ JNIEXPORT jlongArray JNICALL Java_org_simantics_pythonlink_PythonContext_getPyth } JNIEXPORT jdouble JNICALL Java_org_simantics_pythonlink_PythonContext_getPythonDoubleVariableImpl(JNIEnv *env, jobject thisObj, jlong contextID, jstring variableName) { - PyObject *module = (PyObject*)contextID; + PyObject *module = getModule(contextID); PyObject *pythonName = getPythonString(env, variableName); @@ -1130,7 +1211,7 @@ JNIEXPORT jdouble JNICALL Java_org_simantics_pythonlink_PythonContext_getPythonD } JNIEXPORT jdoubleArray JNICALL Java_org_simantics_pythonlink_PythonContext_getPythonDoubleArrayVariableImpl(JNIEnv *env, jobject thisObj, jlong contextID, jstring variableName) { - PyObject *module = (PyObject*)contextID; + PyObject *module = getModule(contextID); PyObject *pythonName = getPythonString(env, variableName); @@ -1152,7 +1233,7 @@ JNIEXPORT jdoubleArray JNICALL Java_org_simantics_pythonlink_PythonContext_getPy } JNIEXPORT jobject JNICALL Java_org_simantics_pythonlink_PythonContext_getPythonNDArrayVariableImpl(JNIEnv *env, jobject thisObj, jlong contextID, jstring variableName) { - PyObject *module = (PyObject*)contextID; + PyObject *module = getModule(contextID); if (!hasNumpy) { throwPythonException(env, "Importing numpy failed"); @@ -1186,7 +1267,7 @@ JNIEXPORT jobject JNICALL Java_org_simantics_pythonlink_PythonContext_getPythonN } JNIEXPORT jobject JNICALL Java_org_simantics_pythonlink_PythonContext_getPythonVariantVariableImpl(JNIEnv *env, jobject thisObj, jlong contextID, jstring variableName) { - PyObject *module = (PyObject*)contextID; + PyObject *module = getModule(contextID); PyObject *pythonName = getPythonString(env, variableName); @@ -1205,7 +1286,7 @@ JNIEXPORT jobject JNICALL Java_org_simantics_pythonlink_PythonContext_getPythonV } JNIEXPORT jint JNICALL Java_org_simantics_pythonlink_PythonContext_getPythonVariableTypeImpl(JNIEnv *env, jobject thisObj, jlong contextID, jstring variableName) { - PyObject *module = (PyObject*)contextID; + PyObject *module = getModule(contextID); PyObject *dict = PyModule_GetDict(module); PyObject *pythonName = getPythonString(env, variableName); @@ -1243,7 +1324,7 @@ JNIEXPORT jint JNICALL Java_org_simantics_pythonlink_PythonContext_getPythonVari } JNIEXPORT jobjectArray JNICALL Java_org_simantics_pythonlink_PythonContext_getPythonVariableNamesImpl(JNIEnv *env, jobject thisObj, jlong contextID) { - PyObject *module = (PyObject*)contextID; + PyObject *module = getModule(contextID); PyObject *dict = PyModule_GetDict(module); PyObject *keys = PyDict_Keys(dict); diff --git a/org.simantics.pythonlink.win32.x86_64/src/sclpy.h b/org.simantics.pythonlink.win32.x86_64/src/sclpy.h index 4032d48..15d681d 100644 --- a/org.simantics.pythonlink.win32.x86_64/src/sclpy.h +++ b/org.simantics.pythonlink.win32.x86_64/src/sclpy.h @@ -34,6 +34,9 @@ #define MAP_CLASS "java/util/Map" #define SET_CLASS "java/util/Set" +#define WRITER_CLASS "java/io/Writer" +#define SCL_REPORTING_WRITER_CLASS "org/simantics/scl/runtime/reporting/SCLReportingWriter" + #define PACKAGE_PREFIX "org/simantics/pythonlink/" #define NDARRAY_CLASS (PACKAGE_PREFIX "NDArray") diff --git a/org.simantics.pythonlink/src/org/simantics/pythonlink/PythonContext.java b/org.simantics.pythonlink/src/org/simantics/pythonlink/PythonContext.java index 6c96dd3..2063c0b 100644 --- a/org.simantics.pythonlink/src/org/simantics/pythonlink/PythonContext.java +++ b/org.simantics.pythonlink/src/org/simantics/pythonlink/PythonContext.java @@ -13,6 +13,8 @@ import org.simantics.databoard.Bindings; import org.simantics.databoard.binding.Binding; import org.simantics.databoard.binding.error.BindingException; import org.simantics.databoard.binding.mutable.Variant; +import org.simantics.scl.runtime.SCLContext; +import org.simantics.scl.runtime.reporting.SCLReportingHandler; public class PythonContext implements Closeable { private long contextID; @@ -75,7 +77,14 @@ public class PythonContext implements Closeable { } public void executePythonStatement(String statement) { - execute(() -> executePythonStatementImpl( contextID, statement )); + SCLContext sclContext = SCLContext.getCurrent(); + + execute(() -> { + SCLContext.push(sclContext); + executePythonStatementImpl( contextID, statement ); + SCLContext.pop(); + }); + for (Listener l : listeners) { l.updated(null); } } -- 2.47.1