https://github.com/Nerixyz created 
https://github.com/llvm/llvm-project/pull/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`.

>From cde98fd91f1006ca1f5a2db0e468af219050e21d Mon Sep 17 00:00:00 2001
From: Nerixyz <[email protected]>
Date: Thu, 10 Sep 2026 15:55:06 +0200
Subject: [PATCH] [lldb][Windows] Remove use of unstable ABI and fix SB API
 visibility

---
 lldb/include/lldb/API/SBFile.h                |  8 +++++++-
 lldb/source/API/SBFile.cpp                    |  8 ++++++--
 .../Python/PythonDataObjects.cpp              | 19 +++++++++++--------
 3 files changed, 24 insertions(+), 11 deletions(-)

diff --git a/lldb/include/lldb/API/SBFile.h b/lldb/include/lldb/API/SBFile.h
index a5b63c05c042d..431c337ec38ff 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 c2f0ff89367b5..ab8e6e152d39e 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 2120739c1db75..6b041db2f0092 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
@@ -1027,12 +1027,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;
 }
 
@@ -1048,12 +1049,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

_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to