@@ -92,38 +92,7 @@ namespace {
92
92
struct InitializePythonRAII {
93
93
public:
94
94
InitializePythonRAII () {
95
- #if (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 8) || (PY_MAJOR_VERSION > 3)
96
- PyConfig config;
97
- PyConfig_InitPythonConfig (&config);
98
- #endif
99
-
100
- #if LLDB_EMBED_PYTHON_HOME
101
- typedef wchar_t *str_type;
102
- static str_type g_python_home = []() -> str_type {
103
- const char *lldb_python_home = LLDB_PYTHON_HOME;
104
- const char *absolute_python_home = nullptr ;
105
- llvm::SmallString<64 > path;
106
- if (llvm::sys::path::is_absolute (lldb_python_home)) {
107
- absolute_python_home = lldb_python_home;
108
- } else {
109
- FileSpec spec = HostInfo::GetShlibDir ();
110
- if (!spec)
111
- return nullptr ;
112
- spec.GetPath (path);
113
- llvm::sys::path::append (path, lldb_python_home);
114
- absolute_python_home = path.c_str ();
115
- }
116
- size_t size = 0 ;
117
- return Py_DecodeLocale (absolute_python_home, &size);
118
- }();
119
- if (g_python_home != nullptr ) {
120
- #if (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 8) || (PY_MAJOR_VERSION > 3)
121
- PyConfig_SetBytesString (&config, &config.home , g_python_home);
122
- #else
123
- Py_SetPythonHome (g_python_home);
124
- #endif
125
- }
126
- #endif
95
+ InitializePythonHome ();
127
96
128
97
// The table of built-in modules can only be extended before Python is
129
98
// initialized.
@@ -148,22 +117,15 @@ struct InitializePythonRAII {
148
117
PyImport_AppendInittab (" _lldb" , LLDBSwigPyInit);
149
118
}
150
119
151
- #if (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 8) || (PY_MAJOR_VERSION > 3)
152
- config.install_signal_handlers = 0 ;
153
- Py_InitializeFromConfig (&config);
154
- PyConfig_Clear (&config);
155
- InitializeThreadsPrivate ();
156
- #else
157
120
// Python < 3.2 and Python >= 3.2 reversed the ordering requirements for
158
121
// calling `Py_Initialize` and `PyEval_InitThreads`. < 3.2 requires that you
159
122
// call `PyEval_InitThreads` first, and >= 3.2 requires that you call it last.
160
- #if (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 2)
123
+ #if (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 2) || (PY_MAJOR_VERSION > 3)
161
124
Py_InitializeEx (0 );
162
125
InitializeThreadsPrivate ();
163
126
#else
164
127
InitializeThreadsPrivate ();
165
128
Py_InitializeEx (0 );
166
- #endif
167
129
#endif
168
130
}
169
131
@@ -180,6 +142,32 @@ struct InitializePythonRAII {
180
142
}
181
143
182
144
private:
145
+ void InitializePythonHome () {
146
+ #if LLDB_EMBED_PYTHON_HOME
147
+ typedef wchar_t *str_type;
148
+ static str_type g_python_home = []() -> str_type {
149
+ const char *lldb_python_home = LLDB_PYTHON_HOME;
150
+ const char *absolute_python_home = nullptr ;
151
+ llvm::SmallString<64 > path;
152
+ if (llvm::sys::path::is_absolute (lldb_python_home)) {
153
+ absolute_python_home = lldb_python_home;
154
+ } else {
155
+ FileSpec spec = HostInfo::GetShlibDir ();
156
+ if (!spec)
157
+ return nullptr ;
158
+ spec.GetPath (path);
159
+ llvm::sys::path::append (path, lldb_python_home);
160
+ absolute_python_home = path.c_str ();
161
+ }
162
+ size_t size = 0 ;
163
+ return Py_DecodeLocale (absolute_python_home, &size);
164
+ }();
165
+ if (g_python_home != nullptr ) {
166
+ Py_SetPythonHome (g_python_home);
167
+ }
168
+ #endif
169
+ }
170
+
183
171
void InitializeThreadsPrivate () {
184
172
// Since Python 3.7 `Py_Initialize` calls `PyEval_InitThreads` inside itself,
185
173
// so there is no way to determine whether the embedded interpreter
0 commit comments