Skip to content

Commit

Permalink
Review update
Browse files Browse the repository at this point in the history
  • Loading branch information
lordgamez committed Nov 5, 2024
1 parent 86d7409 commit 0e1f0b8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 2 additions & 0 deletions extensions/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 8 additions & 3 deletions extensions/python/pythonlibloader/PythonLibLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -82,11 +89,9 @@ class PythonLibLoader {
};
#endif

static bool init(const std::shared_ptr<minifi::Configure>& config) {
static bool init([[maybe_unused]] const std::shared_ptr<minifi::Configure>& config) {
#if !defined(WIN32) && !defined(__APPLE__)
static PythonLibLoader python_lib_loader(config);
#else
(void)config;
#endif
return true;
}
Expand Down

0 comments on commit 0e1f0b8

Please sign in to comment.