[Lldb-commits] [lldb] [lldb] Fix Python GIL-not-held issue in CreateStructuredDataFromScriptObject (PR #136309)

Vladislav Dzhidzhoev via lldb-commits lldb-commits at lists.llvm.org
Fri Apr 18 07:26:00 PDT 2025


https://github.com/dzhidzhoev created https://github.com/llvm/llvm-project/pull/136309

TestStructuredDataAPI.py fails with Python debug build ver. 3.12+ due to call to Py_XINCREF while GIL is not held.

>From 48538eb932283ef5652555402cc68a244e59c730 Mon Sep 17 00:00:00 2001
From: Vladislav Dzhidzhoev <vdzhidzhoev at accesssoftek.com>
Date: Fri, 18 Apr 2025 16:11:40 +0200
Subject: [PATCH] [lldb] Fix Python GIL-not-held issue in
 CreateStructuredDataFromScriptObject

TestStructuredDataAPI.py fails with Python debug build ver. 3.12+ due to
call to Py_XINCREF while GIL is not held.
---
 .../ScriptInterpreter/Python/ScriptInterpreterPython.cpp        | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
index a9c81273c1302..553ee7e80b359 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp
@@ -1569,10 +1569,10 @@ StructuredData::ObjectSP
 ScriptInterpreterPythonImpl::CreateStructuredDataFromScriptObject(
     ScriptObject obj) {
   void *ptr = const_cast<void *>(obj.GetPointer());
+  Locker py_lock(this, Locker::AcquireLock | Locker::NoSTDIN, Locker::FreeLock);
   PythonObject py_obj(PyRefType::Borrowed, static_cast<PyObject *>(ptr));
   if (!py_obj.IsValid() || py_obj.IsNone())
     return {};
-  Locker py_lock(this, Locker::AcquireLock | Locker::NoSTDIN, Locker::FreeLock);
   return py_obj.CreateStructuredObject();
 }
 



More information about the lldb-commits mailing list