https://github.com/charles-zablit updated 
https://github.com/llvm/llvm-project/pull/181160

>From 442c48f4f3c75d17b2c41795df01d335e5bcd403 Mon Sep 17 00:00:00 2001
From: Charles Zablit <[email protected]>
Date: Thu, 12 Feb 2026 14:57:05 +0000
Subject: [PATCH 1/2] [lldb][windows] print an error if Python fails to
 initialize

---
 .../Python/ScriptInterpreterPython.cpp        | 20 +++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git 
a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp 
b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
index 35a772c1454df..9af480c4113d9 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
@@ -120,14 +120,30 @@ struct InitializePythonRAII {
       return spec.GetPath();
     }();
     if (!g_python_home.empty()) {
-      PyConfig_SetBytesString(&config, &config.home, g_python_home.c_str());
+      PyStatus py_status =
+          PyConfig_SetBytesString(&config, &config.home, 
g_python_home.c_str());
+      if (py_status._type == PyStatus::_PyStatus_TYPE_ERROR) {
+        PyConfig_Clear(&config);
+        llvm::WithColor::error() << "Failed to set the Python config: '"
+                                 << py_status.err_msg << "'.\n";
+        return;
+      }
     }
 
     config.install_signal_handlers = 0;
-    Py_InitializeFromConfig(&config);
+    PyStatus py_status = Py_InitializeFromConfig(&config);
     PyConfig_Clear(&config);
+    if (py_status._type == PyStatus::_PyStatus_TYPE_ERROR) {
+      llvm::WithColor::error()
+          << "Python failed to initialize: '" << py_status.err_msg << "'.\n";
+      return;
+    }
 #else
     Py_InitializeEx(/*install_sigs=*/0);
+    if (!Py_IsInitialized()) {
+      llvm::WithColor::error() << "Python failed to initialize.\n";
+      return;
+    }
 #endif
 
     // The only case we should go further and acquire the GIL: it is unlocked.

>From 8ace7e584c325e90e0648b1dfdf10800d7f1492e Mon Sep 17 00:00:00 2001
From: Charles Zablit <[email protected]>
Date: Fri, 13 Feb 2026 12:22:44 +0100
Subject: [PATCH 2/2] remove private API usage

---
 .../Python/ScriptInterpreterPython.cpp             | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git 
a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp 
b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
index 9af480c4113d9..c954f167a22b8 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
@@ -120,22 +120,22 @@ struct InitializePythonRAII {
       return spec.GetPath();
     }();
     if (!g_python_home.empty()) {
-      PyStatus py_status =
+      PyStatus status =
           PyConfig_SetBytesString(&config, &config.home, 
g_python_home.c_str());
-      if (py_status._type == PyStatus::_PyStatus_TYPE_ERROR) {
+      if (PyStatus_Exception(status)) {
         PyConfig_Clear(&config);
-        llvm::WithColor::error() << "Failed to set the Python config: '"
-                                 << py_status.err_msg << "'.\n";
+        llvm::WithColor::error()
+            << "Failed to set the Python config: '" << status.err_msg << 
"'.\n";
         return;
       }
     }
 
     config.install_signal_handlers = 0;
-    PyStatus py_status = Py_InitializeFromConfig(&config);
+    PyStatus status = Py_InitializeFromConfig(&config);
     PyConfig_Clear(&config);
-    if (py_status._type == PyStatus::_PyStatus_TYPE_ERROR) {
+    if (PyStatus_Exception(status)) {
       llvm::WithColor::error()
-          << "Python failed to initialize: '" << py_status.err_msg << "'.\n";
+          << "Python failed to initialize: '" << status.err_msg << "'.\n";
       return;
     }
 #else

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

Reply via email to