diff options
author | Lawrence D'Anna <lawrence_danna@apple.com> | 2019-10-17 22:22:09 +0000 |
---|---|---|
committer | Lawrence D'Anna <lawrence_danna@apple.com> | 2019-10-17 22:22:09 +0000 |
commit | 03819d1c80ad5d7b34f8fe0d375fcd2ef6aa5e7f (patch) | |
tree | 7d1f66147d89ee00239ace90f0b8280720979c7e /lldb/source/Plugins/ScriptInterpreter/Python | |
parent | c86a6acaee55c98072ff06d372d049cb4a671fb5 (diff) | |
download | bcm5719-llvm-03819d1c80ad5d7b34f8fe0d375fcd2ef6aa5e7f.tar.gz bcm5719-llvm-03819d1c80ad5d7b34f8fe0d375fcd2ef6aa5e7f.zip |
eliminate one form of PythonObject::Reset()
Summary:
I'd like to eliminate all forms of Reset() and all public constructors
on these objects, so the only way to make them is with Take<> and Retain<>
and the only way to copy or move them is with actual c++ copy, move, or
assignment.
This is a simple place to start.
Reviewers: JDevlieghere, clayborg, labath, jingham
Reviewed By: labath
Subscribers: lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D69080
llvm-svn: 375182
Diffstat (limited to 'lldb/source/Plugins/ScriptInterpreter/Python')
-rw-r--r-- | lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp | 2 | ||||
-rw-r--r-- | lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h | 30 |
2 files changed, 5 insertions, 27 deletions
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp index 3ac404b532d..1fb9355b9ee 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp +++ b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp @@ -410,7 +410,7 @@ void PythonString::SetString(llvm::StringRef string) { llvm::consumeError(s.takeError()); Reset(); } else { - PythonObject::Reset(std::move(s.get())); + *this = std::move(s.get()); } } diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h index 7f460234ffb..5823f740a53 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h +++ b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h @@ -182,7 +182,8 @@ public: Reset(type, py_obj); } - PythonObject(const PythonObject &rhs) : m_py_obj(nullptr) { Reset(rhs); } + PythonObject(const PythonObject &rhs) + : PythonObject(PyRefType::Borrowed, rhs.m_py_obj) {} PythonObject(PythonObject &&rhs) { m_py_obj = rhs.m_py_obj; @@ -197,19 +198,6 @@ public: m_py_obj = nullptr; } - void Reset(const PythonObject &rhs) { - if (!rhs.IsValid()) - Reset(); - else - Reset(PyRefType::Borrowed, rhs.m_py_obj); - } - - // PythonObject is implicitly convertible to PyObject *, which will call the - // wrong overload. We want to explicitly disallow this, since a PyObject - // *always* owns its reference. Therefore the overload which takes a - // PyRefType doesn't make sense, and the copy constructor should be used. - void Reset(PyRefType type, const PythonObject &ref) = delete; - void Reset(PyRefType type, PyObject *py_obj) { if (py_obj == m_py_obj) return; @@ -244,19 +232,9 @@ public: return result; } - PythonObject &operator=(const PythonObject &other) { - Reset(PyRefType::Borrowed, other.get()); - return *this; - } - - void Reset(PythonObject &&other) { + PythonObject &operator=(PythonObject other) { Reset(); - m_py_obj = other.m_py_obj; - other.m_py_obj = nullptr; - } - - PythonObject &operator=(PythonObject &&other) { - Reset(std::move(other)); + m_py_obj = std::exchange(other.m_py_obj, nullptr); return *this; } |