aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2022-01-27 22:17:16 +0000
committerDimitry Andric <dim@FreeBSD.org>2022-05-14 11:44:34 +0000
commit04eeddc0aa8e0a417a16eaf9d7d095207f4a8623 (patch)
tree2a5d3b2fe5c852e91531d128d9177754572d5338 /contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
parent0eae32dcef82f6f06de6419a0d623d7def0cc8f6 (diff)
parent6f8fc217eaa12bf657be1c6468ed9938d10168b3 (diff)
Diffstat (limited to 'contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h')
-rw-r--r--contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h54
1 files changed, 25 insertions, 29 deletions
diff --git a/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h b/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
index 56bc55d239d1..2094f0b3afd2 100644
--- a/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
+++ b/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
@@ -83,30 +83,6 @@ protected:
PyGILState_STATE m_state;
};
-class StructuredPythonObject : public StructuredData::Generic {
-public:
- StructuredPythonObject() : StructuredData::Generic() {}
-
- StructuredPythonObject(void *obj) : StructuredData::Generic(obj) {
- Py_XINCREF(GetValue());
- }
-
- ~StructuredPythonObject() override {
- if (Py_IsInitialized())
- Py_XDECREF(GetValue());
- SetValue(nullptr);
- }
-
- bool IsValid() const override { return GetValue() && GetValue() != Py_None; }
-
- void Serialize(llvm::json::OStream &s) const override;
-
-private:
- StructuredPythonObject(const StructuredPythonObject &) = delete;
- const StructuredPythonObject &
- operator=(const StructuredPythonObject &) = delete;
-};
-
enum class PyObjectType {
Unknown,
None,
@@ -263,11 +239,7 @@ public:
~PythonObject() { Reset(); }
- void Reset() {
- if (m_py_obj && Py_IsInitialized())
- Py_DECREF(m_py_obj);
- m_py_obj = nullptr;
- }
+ void Reset();
void Dump() const {
if (m_py_obj)
@@ -767,6 +739,30 @@ public:
}
};
+class StructuredPythonObject : public StructuredData::Generic {
+public:
+ StructuredPythonObject() : StructuredData::Generic() {}
+
+ // Take ownership of the object we received.
+ StructuredPythonObject(PythonObject obj)
+ : StructuredData::Generic(obj.release()) {}
+
+ ~StructuredPythonObject() override {
+ // Hand ownership back to a (temporary) PythonObject instance and let it
+ // take care of releasing it.
+ PythonObject(PyRefType::Owned, static_cast<PyObject *>(GetValue()));
+ }
+
+ bool IsValid() const override { return GetValue() && GetValue() != Py_None; }
+
+ void Serialize(llvm::json::OStream &s) const override;
+
+private:
+ StructuredPythonObject(const StructuredPythonObject &) = delete;
+ const StructuredPythonObject &
+ operator=(const StructuredPythonObject &) = delete;
+};
+
} // namespace python
} // namespace lldb_private