From 1e909e497d67231832f511ed5c1b609650766c09 Mon Sep 17 00:00:00 2001 From: horchi Date: Tue, 11 Feb 2020 06:51:26 +0100 Subject: 2020-02-11: version 1.1.155 (horchi)\n - bugfix: Fixed crash due to wrong handling of python object (thx to Alexander Grothe)\n\n --- HISTORY.h | 7 +++++-- lib/python.c | 12 +++++++++--- lib/python.h | 1 + 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/HISTORY.h b/HISTORY.h index ff3188b..6d8b8f3 100644 --- a/HISTORY.h +++ b/HISTORY.h @@ -4,8 +4,8 @@ * ----------------------------------- */ -#define _VERSION "1.1.154" -#define VERSION_DATE "10.02.2020" +#define _VERSION "1.1.155" +#define VERSION_DATE "11.02.2020" #define DB_API 7 #ifdef GIT_REV @@ -18,6 +18,9 @@ * ------------------------------------ * +2020-02-11: version 1.1.155 (horchi) + - bugfix: Fixed crash due to wrong handling of python object (thx to Alexander Grothe) + 2020-02-10: version 1.1.154 (horchi) - change: Tray to fix mysterious sql result (mariaDb) diff --git a/lib/python.c b/lib/python.c index da6f25e..f857c94 100644 --- a/lib/python.c +++ b/lib/python.c @@ -8,6 +8,7 @@ #include "python.h" cDbTable* Python::globalEventsDb = 0; +int Python::usages = 0; int Python::globalNamingMode = 0; const char* Python::globalTmplExpression = ""; @@ -221,14 +222,16 @@ int Python::init(const char* modulePath) #if PY_MAJOR_VERSION >= 3 PyImport_AppendInittab("event", &PyInitEvent); - Py_Initialize(); // initialize the Python interpreter + if (!usages) Py_Initialize(); // initialize the Python interpreter pName = PyUnicode_FromString(file); #else - Py_Initialize(); // initialize the Python interpreter + if (!usages) Py_Initialize(); // initialize the Python interpreter Py_InitModule("event", eventMethods); pName = PyString_FromString(file); #endif + usages++; + // add search path for Python modules if (modulePath) @@ -272,13 +275,16 @@ int Python::init(const char* modulePath) int Python::exit() { + usages--; + if (pFunc) Py_XDECREF(pFunc); if (pModule) Py_DECREF(pModule); - Py_Finalize(); + if (!usages) + Py_Finalize(); return success; } diff --git a/lib/python.h b/lib/python.h index eb50964..e240992 100644 --- a/lib/python.h +++ b/lib/python.h @@ -63,6 +63,7 @@ class Python // static stuff + static int usages; static cDbTable* globalEventsDb; static int globalNamingMode; static const char* globalTmplExpression; -- cgit v1.2.3