[Lldb-commits] [lldb] 6ff4af8 - [lldb] Fix D114722 for python<=3.6
Pavel Labath via lldb-commits
lldb-commits at lists.llvm.org
Wed Jan 19 03:50:04 PST 2022
Author: Pavel Labath
Date: 2022-01-19T12:49:46+01:00
New Revision: 6ff4af8e182333740a58176a3e9cbc84f6828216
URL: https://github.com/llvm/llvm-project/commit/6ff4af8e182333740a58176a3e9cbc84f6828216
DIFF: https://github.com/llvm/llvm-project/commit/6ff4af8e182333740a58176a3e9cbc84f6828216.diff
LOG: [lldb] Fix D114722 for python<=3.6
_Py_IsFinalizing was called _Py_Finalizing back then (and it was a
variable instead of a function).
Added:
Modified:
lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
Removed:
################################################################################
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
index 13dabb2eff3cd..32020f983f605 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
@@ -69,6 +69,28 @@ Expected<std::string> python::As<std::string>(Expected<PythonObject> &&obj) {
return std::string(utf8.get());
}
+static bool python_is_finalizing() {
+#if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION < 7
+ return _Py_Finalizing != nullptr;
+#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);
+ }
+ }
+ m_py_obj = nullptr;
+}
+
Expected<long long> PythonObject::AsLongLong() const {
if (!m_py_obj)
return nullDeref();
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
index 7dd8a7426f15b..2094f0b3afd21 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
@@ -239,19 +239,7 @@ class PythonObject {
~PythonObject() { Reset(); }
- void Reset() {
- if (m_py_obj && Py_IsInitialized()) {
- if (_Py_IsFinalizing()) {
- // 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);
- }
- }
- m_py_obj = nullptr;
- }
+ void Reset();
void Dump() const {
if (m_py_obj)
More information about the lldb-commits
mailing list