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 --- lib/python.c | 12 +++++++++--- lib/python.h | 1 + 2 files changed, 10 insertions(+), 3 deletions(-) (limited to 'lib') 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