-
Notifications
You must be signed in to change notification settings - Fork 14.3k
Revert "[lldb] Use Py_InitializeFromConfig with Python >= 3.8 (NFC)" #114290
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@llvm/pr-subscribers-lldb Author: Jonas Devlieghere (JDevlieghere) ChangesReverts llvm/llvm-project#114112 because this triggers a compile error:
Full diff: https://github.com/llvm/llvm-project/pull/114290.diff 1 Files Affected:
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
index 6158083a982801..7cc38da6a6a94b 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
@@ -92,38 +92,7 @@ namespace {
struct InitializePythonRAII {
public:
InitializePythonRAII() {
-#if (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 8) || (PY_MAJOR_VERSION > 3)
- PyConfig config;
- PyConfig_InitPythonConfig(&config);
-#endif
-
-#if LLDB_EMBED_PYTHON_HOME
- typedef wchar_t *str_type;
- 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();
- }
- size_t size = 0;
- return Py_DecodeLocale(absolute_python_home, &size);
- }();
- if (g_python_home != nullptr) {
-#if (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 8) || (PY_MAJOR_VERSION > 3)
- PyConfig_SetBytesString(&config, &config.home, g_python_home);
-#else
- Py_SetPythonHome(g_python_home);
-#endif
- }
-#endif
+ InitializePythonHome();
// The table of built-in modules can only be extended before Python is
// initialized.
@@ -148,22 +117,15 @@ struct InitializePythonRAII {
PyImport_AppendInittab("_lldb", LLDBSwigPyInit);
}
-#if (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 8) || (PY_MAJOR_VERSION > 3)
- config.install_signal_handlers = 0;
- Py_InitializeFromConfig(&config);
- PyConfig_Clear(&config);
- InitializeThreadsPrivate();
-#else
// Python < 3.2 and Python >= 3.2 reversed the ordering requirements for
// calling `Py_Initialize` and `PyEval_InitThreads`. < 3.2 requires that you
// call `PyEval_InitThreads` first, and >= 3.2 requires that you call it last.
-#if (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 2)
+#if (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 2) || (PY_MAJOR_VERSION > 3)
Py_InitializeEx(0);
InitializeThreadsPrivate();
#else
InitializeThreadsPrivate();
Py_InitializeEx(0);
-#endif
#endif
}
@@ -180,6 +142,32 @@ struct InitializePythonRAII {
}
private:
+ void InitializePythonHome() {
+#if LLDB_EMBED_PYTHON_HOME
+ typedef wchar_t *str_type;
+ 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();
+ }
+ size_t size = 0;
+ return Py_DecodeLocale(absolute_python_home, &size);
+ }();
+ if (g_python_home != nullptr) {
+ Py_SetPythonHome(g_python_home);
+ }
+#endif
+ }
+
void InitializeThreadsPrivate() {
// Since Python 3.7 `Py_Initialize` calls `PyEval_InitThreads` inside itself,
// so there is no way to determine whether the embedded interpreter
|
smallp-o-p
pushed a commit
to smallp-o-p/llvm-project
that referenced
this pull request
Nov 3, 2024
…lvm#114290) Reverts llvm#114112 because this triggers a compile error: ``` no known conversion from 'str_type' (aka 'wchar_t *') to 'const char *' for 3rd argument 221 | PyAPI_FUNC(PyStatus) PyConfig_SetBytesString( | ^ 222 | PyConfig *config, 223 | wchar_t **config_str, 224 | const char *str); | ~~~~~~~~~~~~~~~ 1 error generated. ```
NoumanAmir657
pushed a commit
to NoumanAmir657/llvm-project
that referenced
this pull request
Nov 4, 2024
…lvm#114290) Reverts llvm#114112 because this triggers a compile error: ``` no known conversion from 'str_type' (aka 'wchar_t *') to 'const char *' for 3rd argument 221 | PyAPI_FUNC(PyStatus) PyConfig_SetBytesString( | ^ 222 | PyConfig *config, 223 | wchar_t **config_str, 224 | const char *str); | ~~~~~~~~~~~~~~~ 1 error generated. ```
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Reverts #114112 because this triggers a compile error: