From 0e1f0b84d0008e6fe93abd33ee24e4924da581cd Mon Sep 17 00:00:00 2001 From: Gabor Gyimesi Date: Tue, 5 Nov 2024 14:07:09 +0100 Subject: [PATCH] Review update --- extensions/python/CMakeLists.txt | 2 ++ extensions/python/pythonlibloader/PythonLibLoader.cpp | 11 ++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/extensions/python/CMakeLists.txt b/extensions/python/CMakeLists.txt index fac450593b..126c7d3395 100644 --- a/extensions/python/CMakeLists.txt +++ b/extensions/python/CMakeLists.txt @@ -34,8 +34,10 @@ target_link_libraries(minifi-python-script-extension PRIVATE ${LIBMINIFI} Thread include(GenericPython) if(APPLE) + target_compile_definitions(minifi-python-lib-loader-extension PUBLIC Py_LIMITED_API=0x03090000) target_compile_definitions(minifi-python-script-extension PUBLIC Py_LIMITED_API=0x03090000) else() + target_compile_definitions(minifi-python-lib-loader-extension PUBLIC Py_LIMITED_API=0x03060000) target_compile_definitions(minifi-python-script-extension PUBLIC Py_LIMITED_API=0x03060000) endif() target_compile_definitions(minifi-python-script-extension PUBLIC PY_SSIZE_T_CLEAN) diff --git a/extensions/python/pythonlibloader/PythonLibLoader.cpp b/extensions/python/pythonlibloader/PythonLibLoader.cpp index 9831ade040..ee1e9024df 100644 --- a/extensions/python/pythonlibloader/PythonLibLoader.cpp +++ b/extensions/python/pythonlibloader/PythonLibLoader.cpp @@ -50,6 +50,13 @@ class PythonLibLoader { throw std::runtime_error("Failed to load libpython"); } logger_->log_info("Loaded libpython from path '{}'", lib_python_path); + + command = python_command + " -c \"import sys; print(sys.version_info.major << 24 | sys.version_info.minor << 16)\""; + auto loaded_version = std::stoi(execCommand(command)); + if (loaded_version < Py_LIMITED_API) { + logger_->log_error("Loaded python version is not compatible with minimum python version, loaded version: {:#08X}, minimum python version: {:#08X}", loaded_version, Py_LIMITED_API); + throw std::runtime_error("Loaded python version is not compatible with minimum python version"); + } } PythonLibLoader(PythonLibLoader&&) = delete; @@ -82,11 +89,9 @@ class PythonLibLoader { }; #endif -static bool init(const std::shared_ptr& config) { +static bool init([[maybe_unused]] const std::shared_ptr& config) { #if !defined(WIN32) && !defined(__APPLE__) static PythonLibLoader python_lib_loader(config); -#else - (void)config; #endif return true; }