https://github.com/charles-zablit created https://github.com/llvm/llvm-project/pull/180786
This patch changes the return type of methods returning `std:wstring` to `std::string` in `PythonPathSetup.cpp`. This follows lldb's style of converting to `std::wstring` at the last moment. >From 83ead0047d0c0505f6eec7787d337bac672fa234 Mon Sep 17 00:00:00 2001 From: Charles Zablit <[email protected]> Date: Tue, 10 Feb 2026 17:14:10 +0000 Subject: [PATCH] [lldb][windows] switch to using std::string instead of std::wstring in Python setup --- .../PythonPathSetup/PythonPathSetup.cpp | 37 ++++++++++--------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/lldb/source/Host/windows/PythonPathSetup/PythonPathSetup.cpp b/lldb/source/Host/windows/PythonPathSetup/PythonPathSetup.cpp index d378e6984b056..0ca1189bec283 100644 --- a/lldb/source/Host/windows/PythonPathSetup/PythonPathSetup.cpp +++ b/lldb/source/Host/windows/PythonPathSetup/PythonPathSetup.cpp @@ -21,39 +21,40 @@ using namespace llvm; #ifdef LLDB_PYTHON_DLL_RELATIVE_PATH /// Returns the full path to the lldb.exe executable. -static std::wstring GetPathToExecutableW() { +static std::string GetPathToExecutable() { std::vector<WCHAR> buffer(MAX_PATH); while (buffer.size() <= PATHCCH_MAX_CCH) { DWORD len = GetModuleFileNameW(NULL, buffer.data(), buffer.size()); if (len == 0) - return L""; - if (len < buffer.size()) - return std::wstring(buffer.data(), len); + return ""; + if (len < buffer.size()) { + std::string buffer_utf8; + if (convertWideToUTF8(std::wstring(buffer.data(), len), buffer_utf8)) + return buffer_utf8; + return ""; + } if (::GetLastError() == ERROR_INSUFFICIENT_BUFFER) buffer.resize(buffer.size() * 2); } - return L""; + return ""; } bool AddPythonDLLToSearchPath() { - std::wstring modulePath = GetPathToExecutableW(); - if (modulePath.empty()) + std::string path_str = GetPathToExecutable(); + if (path_str.empty()) return false; - SmallVector<char, MAX_PATH> utf8Path; - if (sys::windows::UTF16ToUTF8(modulePath.c_str(), modulePath.length(), - utf8Path)) - return false; - sys::path::remove_filename(utf8Path); - sys::path::append(utf8Path, LLDB_PYTHON_DLL_RELATIVE_PATH); - sys::fs::make_absolute(utf8Path); + SmallVector<char, MAX_PATH> path(path_str.begin(), path_str.end()); + sys::path::remove_filename(path); + sys::path::append(path, LLDB_PYTHON_DLL_RELATIVE_PATH); + sys::fs::make_absolute(path); - SmallVector<wchar_t, 1> widePath; - if (sys::windows::widenPath(utf8Path.data(), widePath)) + SmallVector<wchar_t, 1> path_wide; + if (sys::windows::widenPath(path.data(), path_wide)) return false; - if (sys::fs::exists(utf8Path)) - return SetDllDirectoryW(widePath.data()); + if (sys::fs::exists(path)) + return SetDllDirectoryW(path_wide.data()); return false; } #endif _______________________________________________ lldb-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
