aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
diff options
context:
space:
mode:
authorJonas Devlieghere <jonas@devlieghere.com>2025-08-06 09:06:54 -0700
committerGitHub <noreply@github.com>2025-08-06 09:06:54 -0700
commit3686e5b52f2a02c1c19050479d1dd0fd9d1dd4f8 (patch)
tree36f4ba80f2fbfb820b81cd3e96531eda10353555 /lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
parent056608a2821e34752b1e47f73a8d544b5c9ad787 (diff)
downloadllvm-3686e5b52f2a02c1c19050479d1dd0fd9d1dd4f8.zip
llvm-3686e5b52f2a02c1c19050479d1dd0fd9d1dd4f8.tar.gz
llvm-3686e5b52f2a02c1c19050479d1dd0fd9d1dd4f8.tar.bz2
[lldb] Eliminate (_)Py_IsFinalizing (NFC) (#152226)
Looking at the implementation of `pylifecycle.c` in cpython, finalizing and initialized are set at the same time. Therefore we can eliminate the call to `Py_IsFinalizing` and only check `Py_IsInitialized`, which is part of the stable API. I converted the check to an assert and confirmed that during my test suite runs, we never got into the if block. Because we check before taking the lock, there is an opportunity for a race, but that exact same race exists with the original code.
Diffstat (limited to 'lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp')
-rw-r--r--lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp19
1 files changed, 3 insertions, 16 deletions
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
index 82aa022..27ac5432 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
@@ -71,24 +71,11 @@ Expected<std::string> python::As<std::string>(Expected<PythonObject> &&obj) {
return std::string(utf8.get());
}
-static bool python_is_finalizing() {
-#if PY_VERSION_HEX >= 0x030d0000
- return Py_IsFinalizing();
-#else
- return _Py_IsFinalizing();
-#endif
-}
-
void PythonObject::Reset() {
if (m_py_obj && Py_IsInitialized()) {
- if (python_is_finalizing()) {
- // Leak m_py_obj rather than crashing the process.
- // https://docs.python.org/3/c-api/init.html#c.PyGILState_Ensure
- } else {
- PyGILState_STATE state = PyGILState_Ensure();
- Py_DECREF(m_py_obj);
- PyGILState_Release(state);
- }
+ PyGILState_STATE state = PyGILState_Ensure();
+ Py_DECREF(m_py_obj);
+ PyGILState_Release(state);
}
m_py_obj = nullptr;
}