aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
diff options
context:
space:
mode:
authorJonas Devlieghere <jonas@devlieghere.com>2025-08-08 09:49:43 -0700
committerGitHub <noreply@github.com>2025-08-08 11:49:43 -0500
commitbcdc80828bcb94922db6e5b8f1c0935b2f5a67e2 (patch)
tree45619fc933f35f6592cf447dc6a8d4c95c5f4321 /lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
parent7d5af16245ab12880605d5e10608a76c2c383d8d (diff)
downloadllvm-bcdc80828bcb94922db6e5b8f1c0935b2f5a67e2.zip
llvm-bcdc80828bcb94922db6e5b8f1c0935b2f5a67e2.tar.gz
llvm-bcdc80828bcb94922db6e5b8f1c0935b2f5a67e2.tar.bz2
[lldb] Only use PyConfig when LLDB_EMBED_PYTHON_HOME is enabled (#152588)
PyConfig and friends are not part of the stable API. We could switch back to Py_SetPythonHome, which has been deprecated, but still part of the stable API. For now, limit the use of PyConfig to when LLDB_EMBED_PYTHON_HOME is enabled, which essentially means Windows. Changing the order doesn't seem to matter.
Diffstat (limited to 'lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp')
-rw-r--r--lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp40
1 files changed, 21 insertions, 19 deletions
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
index 24d604f..5b97fcb 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
@@ -92,25 +92,6 @@ namespace {
struct InitializePythonRAII {
public:
InitializePythonRAII() {
- PyConfig config;
- PyConfig_InitPythonConfig(&config);
-
-#if LLDB_EMBED_PYTHON_HOME
- static std::string g_python_home = []() -> std::string {
- if (llvm::sys::path::is_absolute(LLDB_PYTHON_HOME))
- return LLDB_PYTHON_HOME;
-
- FileSpec spec = HostInfo::GetShlibDir();
- if (!spec)
- return {};
- spec.AppendPathComponent(LLDB_PYTHON_HOME);
- return spec.GetPath();
- }();
- if (!g_python_home.empty()) {
- PyConfig_SetBytesString(&config, &config.home, g_python_home.c_str());
- }
-#endif
-
// The table of built-in modules can only be extended before Python is
// initialized.
if (!Py_IsInitialized()) {
@@ -134,9 +115,30 @@ public:
PyImport_AppendInittab("_lldb", LLDBSwigPyInit);
}
+#if LLDB_EMBED_PYTHON_HOME
+ PyConfig config;
+ PyConfig_InitPythonConfig(&config);
+
+ static std::string g_python_home = []() -> std::string {
+ if (llvm::sys::path::is_absolute(LLDB_PYTHON_HOME))
+ return LLDB_PYTHON_HOME;
+
+ FileSpec spec = HostInfo::GetShlibDir();
+ if (!spec)
+ return {};
+ spec.AppendPathComponent(LLDB_PYTHON_HOME);
+ return spec.GetPath();
+ }();
+ if (!g_python_home.empty()) {
+ PyConfig_SetBytesString(&config, &config.home, g_python_home.c_str());
+ }
+
config.install_signal_handlers = 0;
Py_InitializeFromConfig(&config);
PyConfig_Clear(&config);
+#else
+ Py_InitializeEx(/*install_sigs=*/0);
+#endif
// The only case we should go further and acquire the GIL: it is unlocked.
PyGILState_STATE gil_state = PyGILState_Ensure();