Author: Nerixyz Date: 2026-09-25T10:23:22+02:00 New Revision: 5f2881edaf60c7f793ea87d5ad0305791af50831
URL: https://github.com/llvm/llvm-project/commit/5f2881edaf60c7f793ea87d5ad0305791af50831 DIFF: https://github.com/llvm/llvm-project/commit/5f2881edaf60c7f793ea87d5ad0305791af50831.diff LOG: [lldb][Windows] Remove use of unstable ABI and fix SB API visibility (#222665) Addresses the post-commit review comments from the original PR (https://github.com/llvm/llvm-project/pull/217126#pullrequestreview-5162589053). - `SBFile::OpenFdFromHandle` is now visible on all platforms (just `#ifndef SWIG`) and returns -1 by default. - Removed non-stable `PyLong_Check` in favor of `PyErr_Occurred` and `PyErr_Clear`. (cherry picked from commit ba1687b72476eb368641b9a9f565a38cf41b7393) Added: Modified: lldb/include/lldb/API/SBFile.h lldb/source/API/SBFile.cpp lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp Removed: ################################################################################ diff --git a/lldb/include/lldb/API/SBFile.h b/lldb/include/lldb/API/SBFile.h index 835c70f480595c..73b7dc461b443c 100644 --- a/lldb/include/lldb/API/SBFile.h +++ b/lldb/include/lldb/API/SBFile.h @@ -35,7 +35,13 @@ class LLDB_API SBFile { SBFile(int fd, const char *mode, bool transfer_ownership); ~SBFile(); -#if defined(_WIN32) && !defined(SWIG) +#ifndef SWIG + /// Open a file descriptor in liblldb from a Windows HANDLE. + /// + /// This is useful for builds that statically link to the C runtime (`/MT`), + /// because the fd -> HANDLE mapping is local to liblldb's CRT instance. + /// + /// On other platforms, this always returns -1. static int OpenFdFromHandle(intptr_t handle, int flags); #endif diff --git a/lldb/source/API/SBFile.cpp b/lldb/source/API/SBFile.cpp index c2f0ff89367b55..ab8e6e152d39e8 100644 --- a/lldb/source/API/SBFile.cpp +++ b/lldb/source/API/SBFile.cpp @@ -69,11 +69,15 @@ SBFile::SBFile(int fd, const char *mode, bool transfer_ownership) { std::make_shared<NativeFile>(fd, options.get(), transfer_ownership); } -#ifdef _WIN32 int SBFile::OpenFdFromHandle(intptr_t handle, int flags) { +#if _WIN32 return _open_osfhandle(handle, flags); -} +#else + (void)handle; + (void)flags; + return -1; #endif +} SBError SBFile::Read(uint8_t *buf, size_t num_bytes, size_t *bytes_read) { LLDB_INSTRUMENT_VA(this, buf, num_bytes, bytes_read); diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp index 7c9dbbd4852c8b..8b2d66a168c730 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp +++ b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp @@ -933,12 +933,13 @@ int PythonFile::TranslateFdToPython(int our_fd) { Py_XDECREF(open_osf); if (!fd_obj) return -1; - if (!PyLong_Check(fd_obj)) { - Py_XDECREF(fd_obj); - return -1; - } + long theirs = PyLong_AsLong(fd_obj); Py_XDECREF(fd_obj); + if (PyErr_Occurred()) { + PyErr_Clear(); + return -1; + } return (int)theirs; } @@ -954,12 +955,14 @@ int PythonFile::TranslateFdFromPython(int their_fd) { Py_XDECREF(get_handle); if (!handle_obj) return -1; - if (!PyLong_Check(handle_obj)) { - Py_XDECREF(handle_obj); - return -1; - } + size_t handle = PyLong_AsSize_t(handle_obj); Py_XDECREF(handle_obj); + if (PyErr_Occurred()) { + PyErr_Clear(); + return -1; + } + return _open_osfhandle((intptr_t)handle, 0); } #else _______________________________________________ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
