Skip to content

Commit bcdc808

Browse files
authored
[lldb] Only use PyConfig when LLDB_EMBED_PYTHON_HOME is enabled (llvm#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.
1 parent 7d5af16 commit bcdc808

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -92,25 +92,6 @@ namespace {
9292
struct InitializePythonRAII {
9393
public:
9494
InitializePythonRAII() {
95-
PyConfig config;
96-
PyConfig_InitPythonConfig(&config);
97-
98-
#if LLDB_EMBED_PYTHON_HOME
99-
static std::string g_python_home = []() -> std::string {
100-
if (llvm::sys::path::is_absolute(LLDB_PYTHON_HOME))
101-
return LLDB_PYTHON_HOME;
102-
103-
FileSpec spec = HostInfo::GetShlibDir();
104-
if (!spec)
105-
return {};
106-
spec.AppendPathComponent(LLDB_PYTHON_HOME);
107-
return spec.GetPath();
108-
}();
109-
if (!g_python_home.empty()) {
110-
PyConfig_SetBytesString(&config, &config.home, g_python_home.c_str());
111-
}
112-
#endif
113-
11495
// The table of built-in modules can only be extended before Python is
11596
// initialized.
11697
if (!Py_IsInitialized()) {
@@ -134,9 +115,30 @@ struct InitializePythonRAII {
134115
PyImport_AppendInittab("_lldb", LLDBSwigPyInit);
135116
}
136117

118+
#if LLDB_EMBED_PYTHON_HOME
119+
PyConfig config;
120+
PyConfig_InitPythonConfig(&config);
121+
122+
static std::string g_python_home = []() -> std::string {
123+
if (llvm::sys::path::is_absolute(LLDB_PYTHON_HOME))
124+
return LLDB_PYTHON_HOME;
125+
126+
FileSpec spec = HostInfo::GetShlibDir();
127+
if (!spec)
128+
return {};
129+
spec.AppendPathComponent(LLDB_PYTHON_HOME);
130+
return spec.GetPath();
131+
}();
132+
if (!g_python_home.empty()) {
133+
PyConfig_SetBytesString(&config, &config.home, g_python_home.c_str());
134+
}
135+
137136
config.install_signal_handlers = 0;
138137
Py_InitializeFromConfig(&config);
139138
PyConfig_Clear(&config);
139+
#else
140+
Py_InitializeEx(/*install_sigs=*/0);
141+
#endif
140142

141143
// The only case we should go further and acquire the GIL: it is unlocked.
142144
PyGILState_STATE gil_state = PyGILState_Ensure();

0 commit comments

Comments
 (0)