Skip to content

Commit ad623a8

Browse files
authored
[lldb] Eliminate PyGILState_Check (NFC) (#152006)
Eliminate calls to PyGILState_Check, which is not part of the Python Limited C API. In the Locker, we can use PyGILState_Ensure directly. We could do something similar to replace the assert, but I don't think it's worth it. We don't assert that we hold the GIL anywhere else.
1 parent 9d15189 commit ad623a8

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,6 @@ PythonObject PythonObject::GetAttributeValue(llvm::StringRef attr) const {
261261
}
262262

263263
StructuredData::ObjectSP PythonObject::CreateStructuredObject() const {
264-
assert(PyGILState_Check());
265264
switch (GetObjectType()) {
266265
case PyObjectType::Dictionary:
267266
return PythonDictionary(PyRefType::Borrowed, m_py_obj)

lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,12 @@ struct InitializePythonRAII {
139139
PyConfig_Clear(&config);
140140

141141
// The only case we should go further and acquire the GIL: it is unlocked.
142-
if (PyGILState_Check())
142+
PyGILState_STATE gil_state = PyGILState_Ensure();
143+
if (gil_state != PyGILState_UNLOCKED)
143144
return;
144145

145146
m_was_already_initialized = true;
146-
m_gil_state = PyGILState_Ensure();
147+
m_gil_state = gil_state;
147148
LLDB_LOGV(GetLog(LLDBLog::Script),
148149
"Ensured PyGILState. Previous state = {0}",
149150
m_gil_state == PyGILState_UNLOCKED ? "unlocked" : "locked");

0 commit comments

Comments
 (0)