diff options
author | Haibo Huang <hhb@google.com> | 2020-02-21 15:52:15 -0800 |
---|---|---|
committer | Haibo Huang <hhb@google.com> | 2020-02-21 16:25:30 -0800 |
commit | 3ec3f62f0a0b1ac13230922c91ffc988c1b1e8d5 (patch) | |
tree | 42d70bdb510a259307763acacf26b0b47c085863 /lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp | |
parent | bf4933b4ea657128f1afcf19758866d41e5aebf9 (diff) | |
download | llvm-3ec3f62f0a0b1ac13230922c91ffc988c1b1e8d5.zip llvm-3ec3f62f0a0b1ac13230922c91ffc988c1b1e8d5.tar.gz llvm-3ec3f62f0a0b1ac13230922c91ffc988c1b1e8d5.tar.bz2 |
Allow customized relative PYTHONHOME (Attemp 1)
Summary:
This is another attempt of 0bb90628b5f7c170689d2d3f019af773772fc649.
The difference is that g_python_home is not declared as const. Since
some versions of python do not expect that.
Subscribers: mgorny, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D74998
Diffstat (limited to 'lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp')
-rw-r--r-- | lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp index 722af71..3e93ddbf 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp +++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp @@ -277,14 +277,36 @@ public: private: void InitializePythonHome() { -#if defined(LLDB_PYTHON_HOME) +#if LLDB_EMBED_PYTHON_HOME #if PY_MAJOR_VERSION >= 3 - size_t size = 0; - static wchar_t *g_python_home = Py_DecodeLocale(LLDB_PYTHON_HOME, &size); + typedef wchar_t* str_type; #else - static char g_python_home[] = LLDB_PYTHON_HOME; + typedef char* str_type; #endif - Py_SetPythonHome(g_python_home); + static str_type g_python_home = []() -> str_type { + const char *lldb_python_home = LLDB_PYTHON_HOME; + const char *absolute_python_home = nullptr; + llvm::SmallString<64> path; + if (llvm::sys::path::is_absolute(lldb_python_home)) { + absolute_python_home = lldb_python_home; + } else { + FileSpec spec = HostInfo::GetShlibDir(); + if (!spec) + return nullptr; + spec.GetPath(path); + llvm::sys::path::append(path, lldb_python_home); + absolute_python_home = path.c_str(); + } +#if PY_MAJOR_VERSION >= 3 + size_t size = 0; + return Py_DecodeLocale(absolute_python_home, &size); +#else + return strdup(absolute_python_home); +#endif + }(); + if (g_python_home != nullptr) { + Py_SetPythonHome(g_python_home); + } #else #if defined(__APPLE__) && PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION == 7 // For Darwin, the only Python version supported is the one shipped in the |