From 5bb4de039efc777ba624a1253e5a153c9a3002bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mika=C3=ABl=20Capelle?= Date: Fri, 14 Jun 2024 16:13:52 +0200 Subject: [PATCH] Fix for Python debug build (#128) * Minor updates for debug Python/PyQt. * Fix issue with destructor of lambda in shared holder. --- CMakeLists.txt | 3 +++ src/plugin_python_en.ts | 1 - src/proxy/CMakeLists.txt | 2 +- .../include/pybind11_qt/pybind11_qt_holder.h | 2 +- .../include/pybind11_utils/shared_cpp_owner.h | 2 +- src/runner/pythonrunner.cpp | 16 +++++++++------- 6 files changed, 15 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bb45be8..e92c331 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,6 +16,9 @@ set(PYTHON_BUILD_PATH ${PYTHON_ROOT}/PCBuild/amd64) set(Python_USE_STATIC_LIBS False) set(Python_INCLUDE_DIR ${PYTHON_ROOT}/Include) set(Python_EXECUTABLE ${PYTHON_BUILD_PATH}/python.exe) +if (EXISTS "${PYTHON_BUILD_PATH}/python_d.exe") + set(Python_EXECUTABLE ${PYTHON_BUILD_PATH}/python_d.exe) +endif() file(GLOB Python_LIBRARY ${PYTHON_BUILD_PATH}/python[0-9][0-9]*.lib) find_package(Python COMPONENTS Interpreter Development REQUIRED) diff --git a/src/plugin_python_en.ts b/src/plugin_python_en.ts index 7f5c814..9ef7836 100644 --- a/src/plugin_python_en.ts +++ b/src/plugin_python_en.ts @@ -54,7 +54,6 @@ Do you want to try initializing python again (at the risk of another crash)? The path to Mod Organizer (%1) contains a semicolon.<br>While this is legal on NTFS drives, many applications do not handle it correctly.<br>Unfortunately MO depends on libraries that seem to fall into that group.<br>As a result the python plugin cannot be loaded, and the only solution we can offer is to remove the semicolon or move MO to a path without a semicolon. - The path to Mod Organizer (%1) contains a semicolon. <br>While this is legal on NTFS drives, many softwares do not handle it correctly.<br>Unfortunately MO depends on libraries that seem to fall into that group.<br>As a result the python plugin cannot be loaded, and the only solution we canoffer is to remove the semicolon or move MO to a path without a semicolon. diff --git a/src/proxy/CMakeLists.txt b/src/proxy/CMakeLists.txt index 4c43cc1..bee4952 100644 --- a/src/proxy/CMakeLists.txt +++ b/src/proxy/CMakeLists.txt @@ -34,7 +34,7 @@ mo2_add_translations(proxy set(DLL_DIRS ${PLUGIN_PYTHON_DIR}/dlls) file(GLOB dlls_to_install ${PYTHON_BUILD_PATH}/libffi*.dll - ${PYTHON_BUILD_PATH}/python${Python_VERSION_SHORT}.dll) + ${PYTHON_BUILD_PATH}/python${Python_VERSION_SHORT}*.dll) install(FILES ${dlls_to_install} DESTINATION ${DLL_DIRS}) # install Python files diff --git a/src/pybind11-qt/include/pybind11_qt/pybind11_qt_holder.h b/src/pybind11-qt/include/pybind11_qt/pybind11_qt_holder.h index 08fdd78..39200d5 100644 --- a/src/pybind11-qt/include/pybind11_qt/pybind11_qt_holder.h +++ b/src/pybind11-qt/include/pybind11_qt/pybind11_qt_holder.h @@ -29,7 +29,7 @@ namespace pybind11::detail::qt { ~qobject_holder_impl() { gil_scoped_acquire s; - p_ = std::move(none()); + p_ = object(); } }; diff --git a/src/pybind11-utils/include/pybind11_utils/shared_cpp_owner.h b/src/pybind11-utils/include/pybind11_utils/shared_cpp_owner.h index 4eac89e..02c2111 100644 --- a/src/pybind11-utils/include/pybind11_utils/shared_cpp_owner.h +++ b/src/pybind11-utils/include/pybind11_utils/shared_cpp_owner.h @@ -54,7 +54,7 @@ namespace mo2::python::detail { holder.reset(holder.get(), [pyobj = py::reinterpret_borrow( src)](auto*) mutable { py::gil_scoped_acquire s; - pyobj = std::move(py::none()); + pyobj = py::object(); // we do NOT delete the object here - if this was the last reference to // the Python object, the Python object will delete it diff --git a/src/runner/pythonrunner.cpp b/src/runner/pythonrunner.cpp index 20e55d2..35b2216 100644 --- a/src/runner/pythonrunner.cpp +++ b/src/runner/pythonrunner.cpp @@ -132,13 +132,15 @@ namespace mo2::python { return false; } - py::module_ mainModule = py::module_::import("__main__"); - py::object mainNamespace = mainModule.attr("__dict__"); - mainNamespace["sys"] = py::module_::import("sys"); - mainNamespace["mobase"] = py::module_::import("mobase"); - - mo2::python::configure_python_stream(); - mo2::python::configure_python_logging(mainNamespace["mobase"]); + { + py::module_ mainModule = py::module_::import("__main__"); + py::object mainNamespace = mainModule.attr("__dict__"); + mainNamespace["sys"] = py::module_::import("sys"); + mainNamespace["mobase"] = py::module_::import("mobase"); + + mo2::python::configure_python_stream(); + mo2::python::configure_python_logging(mainNamespace["mobase"]); + } // we need to release the GIL here - which is what this does //