@@ -92,7 +92,38 @@ namespace {
92
92
struct InitializePythonRAII {
93
93
public:
94
94
InitializePythonRAII () {
95
- InitializePythonHome ();
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
96
127
97
128
// The table of built-in modules can only be extended before Python is
98
129
// initialized.
@@ -117,15 +148,22 @@ struct InitializePythonRAII {
117
148
PyImport_AppendInittab (" _lldb" , LLDBSwigPyInit);
118
149
}
119
150
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
120
157
// Python < 3.2 and Python >= 3.2 reversed the ordering requirements for
121
158
// calling `Py_Initialize` and `PyEval_InitThreads`. < 3.2 requires that you
122
159
// call `PyEval_InitThreads` first, and >= 3.2 requires that you call it last.
123
- #if (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 2) || (PY_MAJOR_VERSION > 3)
160
+ #if (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 2)
124
161
Py_InitializeEx (0 );
125
162
InitializeThreadsPrivate ();
126
163
#else
127
164
InitializeThreadsPrivate ();
128
165
Py_InitializeEx (0 );
166
+ #endif
129
167
#endif
130
168
}
131
169
@@ -142,32 +180,6 @@ struct InitializePythonRAII {
142
180
}
143
181
144
182
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
-
171
183
void InitializeThreadsPrivate () {
172
184
// Since Python 3.7 `Py_Initialize` calls `PyEval_InitThreads` inside itself,
173
185
// so there is no way to determine whether the embedded interpreter
0 commit comments