From 60a974076fd7fd49df930b18a212a117ea7d032c Mon Sep 17 00:00:00 2001 From: tkorvola Date: Tue, 7 Feb 2017 19:40:00 +0200 Subject: [PATCH] Plug more reference leaks. I hope I am getting it right. The Python C API is a bit messy regarding reference behaviour. Change-Id: I0e78b4f8e46eb387caf0d751f6bffac5f1b10c18 --- .../jnipython.dll | Bin 67584 -> 68096 bytes .../src/sclpy.c | 58 ++++++++++++------ 2 files changed, 39 insertions(+), 19 deletions(-) diff --git a/org.simantics.pythonlink.win32.x86_64/jnipython.dll b/org.simantics.pythonlink.win32.x86_64/jnipython.dll index c2f62cb7f5de3bbfa0d808fa900bb308711c0fab..7cc11fd3f764998be28d7d5c889260ff1499bb2d 100644 GIT binary patch delta 10927 zcmZ`<3tUvy)<1J(Y(Q}UJs_Ys$lwD+QBZk^jtF|RArMh9QSq62tu&$RRu>ddaYU!K zDJhy}4^t`?-%n6f%okb~z06lOh!$Em?eTTK|Jvuwi0S3`+iR`8_FDhF_G_Je&X8|+ z%U|JUzu!@>Tazhhe~m&%Qwz~U5Xzy*R+W(}Sb*+^$NO7Q^+G9U9%8s|E9)b6*447{ zptsmU&|lfdpoWSs#7JGQeZv;gV!6vzfLu}%QlErO&6gN*YBsUwquP>{cSgVcM1{AvYJbRer~ zAd)Xg8bv;qp!#Hi3?!7YR)R3A{)7zi4XQs&Ba!1l=Jp2(!nD@!B~sWANe~DRa55SHr&q;nJr+@B%p-VWnrstfTZTDX zwpq<-ihUCnOfJ^XzXn$Ds@Wvu23SkD@wyuax}>$p2kyxph&m9 zbsUN`MO^a@G^|c@&a?%~|P zYK~N-U2J!Yj3k}vG0EvM)aCItLXr`PNw#@DNzJjcA!icCe&Yo1WPsDfm!-BGZMb3N zVGdv)w;Yo9+hq(QHyFk#s_}oQl_DAmL5=7JOc3j7m?~Zg*nGO2DAW(|dXlYX;2zQe zB20ydcS0n(AU3KH#pGfy#f~qy?=d%8w&m$xa;Z2H_6Mz6PZjBID=nDcA@E=t#-Zmy z+{X@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A6*FVpJuQj2*_|-y;lIh3nI)Raxi3b<;75g>pGR z^1sGaNw!X6{{(RfVv6X&U6+&k~ z`0|R#={O|M@Y#bm!fE;<=}7JvaX9uLV-R#Q)#1=gqyN%cI)udS$@%0?}4m{jFAyVQTPOw8v&a=-62! zv^|0;Mt_<3WMiobpwAD!;@45o1c*X_#?Q$EZBuLdie3N0!NEF;#&S!@B4L}#d!QbK zddxPeKHRGvGh>PEvj(Y)GGZJ3emKtPQvVapmr-)y&A7(PL-6XO6TEu2%)y|HVhaq) z_VSU>dxVY+6og8=iD!Z9^n$PzvM>1TAVJs#IS1TCFa8v0*$^xU_0a4BFTeqP333H^ zh(QnvJswK{*$&=&0%nux!S|qaV0v)VL@bYiH9**d63!aH<0m0{rU(B7C4uR| z<0nJM^x%6?WTpp?pMoV|dhk6cnM@BpZYpLFau)a%lx)a%z{kwQK$w0e*8iE=SOQi7 zZ<&qJLiPo(Ln($_5B`tmu>_Fw!DHuO2_T!nucA~!z5~7*yLc<)O7P^lSOUmt;6J16 zg)IC7j|~(%WIOoedFbP;1(85_bv`;m!!Gb4IamV7Y2aQ9FwKyC!MD7GC15t-7f|j% z&Mp^(Qz!|asb@hWWHV%TGDV}vklFFI1tk^oR&dQKK}d(}0iJBZ?$1ZX4E`F*LCE>w zpArBeUji@2QE&w^;~P;PK&}M8gyK=Ja$lSWzK|=yZ=kTBU3F^(;Q&esWOm|&qAY@M g4EP9?9LNDocn;+vD(qlcjnb(e$H|-)o9_kuKjnmk>Hq)$ diff --git a/org.simantics.pythonlink.win32.x86_64/src/sclpy.c b/org.simantics.pythonlink.win32.x86_64/src/sclpy.c index caed56d..762df28 100644 --- a/org.simantics.pythonlink.win32.x86_64/src/sclpy.c +++ b/org.simantics.pythonlink.win32.x86_64/src/sclpy.c @@ -32,6 +32,7 @@ jint throwIllegalArgumentException( JNIEnv *env, const char *message ) { return throwException( env, ILLEGAL_ARGUMENT_EXCEPTION, message ); } +// Returns a borrowed reference. PyObject* getModule(jlong contextID) { return PyState_FindModule((PyModuleDef*) contextID); // return PyImport_AddModule("__main__"); @@ -105,19 +106,27 @@ static PyMethodDef sclWriterMethods[] = { {NULL, NULL, 0, NULL} }; -JNIEXPORT void JNICALL Java_org_simantics_pythonlink_PythonContext_initializePython(JNIEnv *env, jobject thisObj, jobject writer) { +JNIEXPORT void JNICALL +Java_org_simantics_pythonlink_PythonContext_initializePython( + JNIEnv *env, jobject thisObj, jobject writer) { Py_Initialize(); { - static struct PyModuleDef moduledef = { PyModuleDef_HEAD_INIT, "sclwriter", NULL, -1, sclWriterMethods, }; - PyObject *m = PyModule_Create(&moduledef); + static struct PyModuleDef moduledef = { + PyModuleDef_HEAD_INIT, "sclwriter", NULL, -1, sclWriterMethods + }; + PyObject *m = PyModule_Create(&moduledef); sclWriter = (*env)->NewGlobalRef(env, writer); - if (m == NULL) throwException(env, PYTHON_EXCEPTION, "Failed to create SCL writer module"); - - PySys_SetObject("stdout", m); - PySys_SetObject("stderr", m); + if (m == NULL) { + throwException(env, PYTHON_EXCEPTION, + "Failed to create SCL writer module"); + } else { + PySys_SetObject("stdout", m); + PySys_SetObject("stderr", m); + Py_DECREF(m); + } } hasNumpy = _import_array(); @@ -145,12 +154,11 @@ JNIEXPORT jlong JNICALL Java_org_simantics_pythonlink_PythonContext_createContex modDef->m_size = -1; module = PyModule_Create(modDef); - Py_INCREF(module); PyState_AddModule(module, modDef); - { PyObject *builtin = PyImport_AddModule("builtins"); PyObject *dict = PyModule_GetDict(module); + Py_DECREF(module); PyDict_SetItemString(dict, "__builtin__", builtin); PyDict_SetItemString(dict, "__builtins__", builtin); @@ -160,12 +168,11 @@ JNIEXPORT jlong JNICALL Java_org_simantics_pythonlink_PythonContext_createContex } } -JNIEXPORT void JNICALL Java_org_simantics_pythonlink_PythonContext_deleteContextImpl(JNIEnv *env, jobject thisObj, jlong contextID) { +JNIEXPORT void JNICALL +Java_org_simantics_pythonlink_PythonContext_deleteContextImpl( + JNIEnv *env, jobject thisObj, jlong contextID) { PyModuleDef *modDef = (PyModuleDef*)contextID; - PyObject *module; PyEval_RestoreThread(main_ts); - module = PyState_FindModule(modDef); - Py_XDECREF(module); PyState_RemoveModule(modDef); free((char*)modDef->m_name); free(modDef); @@ -204,6 +211,7 @@ PyObject *getPythonStringList(JNIEnv *env, jobjectArray value) { PyList_SetItem(result, i, getPythonString(env, (jstring)item)); } else { + Py_INCREF(Py_None); PyList_SetItem(result, i, Py_None); } } @@ -416,8 +424,12 @@ PyObject *getPythonRecordObject(JNIEnv *env, jobject object, jobject binding) { jobject componentObject = (*env)->CallObjectMethod(env, binding, getComponent, object, i); jobject componentBinding = (*env)->CallObjectMethod(env, binding, getComponentBinding, i); - PyObject *item = getPythonObject(env, componentObject, componentBinding); - PyDict_SetItem(result, getPythonString(env, fieldName), item); + PyObject + *key = getPythonString(env, fieldName), + *item = getPythonObject(env, componentObject, componentBinding); + PyDict_SetItem(result, key, item); + Py_DECREF(key); + Py_DECREF(item); } return result; @@ -440,8 +452,10 @@ PyObject *getPythonArrayObject(JNIEnv *env, jobject object, jobject binding) { jobject item = (*env)->CallObjectMethod(env, binding, getMethod, object, i); if (item != NULL) PyList_SetItem(result, i, getPythonObject(env, item, componentBinding)); - else + else { + Py_INCREF(Py_None); PyList_SetItem(result, i, Py_None); + } } return result; @@ -470,7 +484,12 @@ PyObject *getPythonMapObject(JNIEnv *env, jobject object, jobject binding) { for (i = 0; i < size; i++) { jobject key = (*env)->GetObjectArrayElement(env, keys, i); jobject item = (*env)->GetObjectArrayElement(env, values, i); - PyDict_SetItem(result, getPythonObject(env, key, keyBinding), getPythonObject(env, item, valueBinding)); + PyObject + *pkey = getPythonObject(env, key, keyBinding), + *pitem = getPythonObject(env, item, valueBinding); + PyDict_SetItem(result, pkey, pitem); + Py_DECREF(pkey); + Py_DECREF(pitem); } (*env)->DeleteLocalRef(env, keys); @@ -601,6 +620,7 @@ PyObject *getPythonObject(JNIEnv *env, jobject value, jobject binding) { } } +// Steals refs to name & value. void setPythonVariable(PyObject *module, PyObject *name, PyObject *value) { if (name && value) { PyDict_SetItem(PyModule_GetDict(module), name, value); @@ -1013,8 +1033,8 @@ Java_org_simantics_pythonlink_PythonContext_executePythonStatementImpl( { PyObject *result = PyRun_String(utfchars, Py_file_input, globals, globals); - PyObject *exceptionType = PyErr_Occurred(); + if (exceptionType != NULL) { PyObject *exception, *traceback, *message; PyErr_Fetch(&exceptionType, &exception, &traceback); @@ -1055,7 +1075,7 @@ Java_org_simantics_pythonlink_PythonContext_executePythonStatementImpl( // Returns a borrowed reference. static PyObject *getPythonValue( JNIEnv *env, jlong contextID, jstring variableName) { - PyObject *module = getModule(contextID); + PyObject *module = getModule(contextID); PyObject *pythonName = getPythonString(env, variableName); PyObject *value = PyDict_GetItem(PyModule_GetDict(module), pythonName); -- 2.47.1