aports/community/domoticz/domoticz-python-3.10.patch
Johannes Heimansberg 34801d7c3f community/domoticz: upgrade to 2022.1
- Python 3.10 patch based on Fedora's patch: d1b7342b08
2022-02-13 16:37:02 +00:00

162 lines
7.0 KiB
Diff

From 6e5f16b148d4fde62f53ea45c533e9a8d6592b74 Mon Sep 17 00:00:00 2001
From: Johannes Heimansberg <git@jhe.dedyn.io>
Date: Sat, 12 Feb 2022 10:43:26 +0100
Subject: [PATCH] Python 3.10 compatibility
---
CMakeLists.txt | 2 +-
hardware/plugins/DelayedLink.h | 24 +++++++++++++-----------
hardware/plugins/PluginManager.cpp | 22 +++++++++++-----------
hardware/plugins/Plugins.cpp | 1 +
4 files changed, 26 insertions(+), 23 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 7d7bf667a..d365f9c3a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -745,7 +745,7 @@ ELSE()
message(STATUS "Not found telldus-core (telldus-core.h), not adding tellstick support")
ENDIF(TELLDUSCORE_INCLUDE)
-target_link_libraries(domoticz ${Boost_LIBRARIES} ${ZLIB_LIBRARIES} ${MINIZIP_LIBRARIES} ${CURL_LIBRARIES} pthread ${MQTT_LIBRARIES} ${LUA_LIBRARIES} ${CMAKE_DL_LIBS} ${TELLDUS_LIBRARIES})
+target_link_libraries(domoticz ${Boost_LIBRARIES} ${ZLIB_LIBRARIES} ${MINIZIP_LIBRARIES} ${CURL_LIBRARIES} pthread -lpython3.10 ${MQTT_LIBRARIES} ${LUA_LIBRARIES} ${CMAKE_DL_LIBS} ${TELLDUS_LIBRARIES})
IF(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
target_link_libraries(domoticz -lresolv)
diff --git a/hardware/plugins/DelayedLink.h b/hardware/plugins/DelayedLink.h
index c20ba0632..ea38d87ac 100644
--- a/hardware/plugins/DelayedLink.h
+++ b/hardware/plugins/DelayedLink.h
@@ -9,6 +9,7 @@
#ifdef WITH_THREAD
# undefine WITH_THREAD
#endif
+#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include <structmember.h>
#include <frameobject.h>
@@ -114,14 +115,14 @@ namespace Plugins {
DECLARE_PYTHON_SYMBOL(PyObject*, PyModule_Create2, struct PyModuleDef* COMMA int);
#endif
DECLARE_PYTHON_SYMBOL(int, PyModule_AddObject, PyObject* COMMA const char* COMMA PyObject*);
- DECLARE_PYTHON_SYMBOL(int, PyArg_ParseTuple, PyObject* COMMA const char* COMMA ...);
- DECLARE_PYTHON_SYMBOL(int, PyArg_ParseTupleAndKeywords, PyObject* COMMA PyObject* COMMA const char* COMMA char*[] COMMA ...);
+ DECLARE_PYTHON_SYMBOL(int, _PyArg_ParseTuple_SizeT, PyObject* COMMA const char* COMMA ...);
+ DECLARE_PYTHON_SYMBOL(int, _PyArg_ParseTupleAndKeywords_SizeT, PyObject* COMMA PyObject* COMMA const char* COMMA char*[] COMMA ...);
DECLARE_PYTHON_SYMBOL(PyObject*, PyUnicode_FromFormat, const char* COMMA ...);
- DECLARE_PYTHON_SYMBOL(PyObject*, Py_BuildValue, const char* COMMA ...);
+ DECLARE_PYTHON_SYMBOL(PyObject*, _Py_BuildValue_SizeT, const char* COMMA ...);
DECLARE_PYTHON_SYMBOL(void, PyMem_Free, void*);
DECLARE_PYTHON_SYMBOL(PyObject*, PyBool_FromLong, long);
- DECLARE_PYTHON_SYMBOL(int, PyRun_SimpleStringFlags, const char* COMMA PyCompilerFlags*);
- DECLARE_PYTHON_SYMBOL(int, PyRun_SimpleFileExFlags, FILE* COMMA const char* COMMA int COMMA PyCompilerFlags*);
+ DECLARE_PYTHON_SYMBOL(int, PyRun_SimpleStringFlags, const char* COMMA PyCompilerFlags*);
+ DECLARE_PYTHON_SYMBOL(int, PyRun_SimpleFileExFlags, FILE* COMMA const char* COMMA int COMMA PyCompilerFlags*);
DECLARE_PYTHON_SYMBOL(void*, PyCapsule_Import, const char *name COMMA int);
DECLARE_PYTHON_SYMBOL(void*, PyType_GenericAlloc, const PyTypeObject * COMMA Py_ssize_t);
DECLARE_PYTHON_SYMBOL(PyObject*, PyUnicode_DecodeUTF8, const char * COMMA Py_ssize_t COMMA const char *);
@@ -170,6 +171,7 @@ namespace Plugins {
if (!shared_lib_) shared_lib_ = LoadLibrary("python34.dll");
# endif
#else
+ if (!shared_lib_) FindLibrary("python3.10", true);
if (!shared_lib_) FindLibrary("python3.9", true);
if (!shared_lib_) FindLibrary("python3.8", true);
if (!shared_lib_) FindLibrary("python3.7", true);
@@ -262,10 +264,10 @@ namespace Plugins {
RESOLVE_PYTHON_SYMBOL(PyModule_Create2);
#endif
RESOLVE_PYTHON_SYMBOL(PyModule_AddObject);
- RESOLVE_PYTHON_SYMBOL(PyArg_ParseTuple);
- RESOLVE_PYTHON_SYMBOL(PyArg_ParseTupleAndKeywords);
+ RESOLVE_PYTHON_SYMBOL(_PyArg_ParseTuple_SizeT);
+ RESOLVE_PYTHON_SYMBOL(_PyArg_ParseTupleAndKeywords_SizeT);
RESOLVE_PYTHON_SYMBOL(PyUnicode_FromFormat);
- RESOLVE_PYTHON_SYMBOL(Py_BuildValue);
+ RESOLVE_PYTHON_SYMBOL(_Py_BuildValue_SizeT);
RESOLVE_PYTHON_SYMBOL(PyMem_Free);
#ifdef _DEBUG
RESOLVE_PYTHON_SYMBOL(_Py_Dealloc);
@@ -494,8 +496,8 @@ extern SharedLibraryProxy* pythonLib;
#define PyObject_IsInstance pythonLib->PyObject_IsInstance
#define PyObject_IsSubclass pythonLib->PyObject_IsSubclass
#define PyObject_Dir pythonLib->PyObject_Dir
-#define PyArg_ParseTuple pythonLib->PyArg_ParseTuple
-#define Py_BuildValue pythonLib->Py_BuildValue
+#define PyArg_ParseTuple pythonLib->_PyArg_ParseTuple_SizeT
+#define Py_BuildValue pythonLib->_Py_BuildValue_SizeT
#define PyMem_Free pythonLib->PyMem_Free
#ifdef _DEBUG
# define PyModule_Create2TraceRefs pythonLib->PyModule_Create2TraceRefs
@@ -503,7 +505,7 @@ extern SharedLibraryProxy* pythonLib;
# define PyModule_Create2 pythonLib->PyModule_Create2
#endif
#define PyModule_AddObject pythonLib->PyModule_AddObject
-#define PyArg_ParseTupleAndKeywords pythonLib->PyArg_ParseTupleAndKeywords
+#define PyArg_ParseTupleAndKeywords pythonLib->_PyArg_ParseTupleAndKeywords_SizeT
#ifdef _DEBUG
# define _Py_Dealloc pythonLib->_Py_Dealloc
diff --git a/hardware/plugins/PluginManager.cpp b/hardware/plugins/PluginManager.cpp
index ee9398957..2f1e9b17a 100644
--- a/hardware/plugins/PluginManager.cpp
+++ b/hardware/plugins/PluginManager.cpp
@@ -31,7 +31,7 @@
#include "DelayedLink.h"
#include "../../main/EventsPythonModule.h"
-#define MINIMUM_PYTHON_VERSION "3.4.0"
+#define MINIMUM_PYTHON_VERSION "3.10.0"
#define ATTRIBUTE_VALUE(pElement, Name, Value) \
{ \
@@ -111,6 +111,16 @@ namespace Plugins {
return false;
}
+ Py_Initialize();
+
+ // Initialise threads. Python 3.7+ does this inside Py_Initialize so done here for compatibility
+ if (!PyEval_ThreadsInitialized())
+ {
+ PyEval_InitThreads();
+ }
+
+ m_InitialPythonThread = PyEval_SaveThread();
+
// Set program name, this prevents it being set to 'python'
Py_SetProgramName(Py_GetProgramFullPath());
@@ -132,16 +142,6 @@ namespace Plugins {
return false;
}
- Py_Initialize();
-
- // Initialise threads. Python 3.7+ does this inside Py_Initialize so done here for compatibility
- if (!PyEval_ThreadsInitialized())
- {
- PyEval_InitThreads();
- }
-
- m_InitialPythonThread = PyEval_SaveThread();
-
m_bEnabled = true;
_log.Log(LOG_STATUS, "PluginSystem: Started, Python version '%s', %d plugin definitions loaded.", sVersion.c_str(), (int)m_PluginXml.size());
}
diff --git a/hardware/plugins/Plugins.cpp b/hardware/plugins/Plugins.cpp
index 01f0beace..f419147b6 100644
--- a/hardware/plugins/Plugins.cpp
+++ b/hardware/plugins/Plugins.cpp
@@ -2268,6 +2268,7 @@ namespace Plugins
{
if (PyErr_Occurred())
{
+ LogPythonException(sHandler);
PyErr_Clear();
Log(LOG_NORM, "Python exception set prior to callback '%s'", sHandler.c_str());
}
--
2.35.1