[Lldb-commits] [lldb] r375182 - eliminate one form of PythonObject::Reset()
Lawrence D'Anna via lldb-commits
lldb-commits at lists.llvm.org
Thu Oct 17 15:22:09 PDT 2019
Author: lawrence_danna
Date: Thu Oct 17 15:22:09 2019
New Revision: 375182
URL: http://llvm.org/viewvc/llvm-project?rev=375182&view=rev
Log:
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
Modified:
lldb/trunk/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
lldb/trunk/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
lldb/trunk/unittests/ScriptInterpreter/Python/PythonDataObjectsTests.cpp
Modified: lldb/trunk/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp?rev=375182&r1=375181&r2=375182&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp (original)
+++ lldb/trunk/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp Thu Oct 17 15:22:09 2019
@@ -410,7 +410,7 @@ void PythonString::SetString(llvm::Strin
llvm::consumeError(s.takeError());
Reset();
} else {
- PythonObject::Reset(std::move(s.get()));
+ *this = std::move(s.get());
}
}
Modified: lldb/trunk/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h?rev=375182&r1=375181&r2=375182&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h (original)
+++ lldb/trunk/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h Thu Oct 17 15:22:09 2019
@@ -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;
}
Modified: lldb/trunk/unittests/ScriptInterpreter/Python/PythonDataObjectsTests.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/ScriptInterpreter/Python/PythonDataObjectsTests.cpp?rev=375182&r1=375181&r2=375182&view=diff
==============================================================================
--- lldb/trunk/unittests/ScriptInterpreter/Python/PythonDataObjectsTests.cpp (original)
+++ lldb/trunk/unittests/ScriptInterpreter/Python/PythonDataObjectsTests.cpp Thu Oct 17 15:22:09 2019
@@ -323,8 +323,8 @@ TEST_F(PythonDataObjectsTest, TestPython
PythonList list(PyRefType::Owned, py_list);
PythonObject list_items[list_size];
- list_items[0].Reset(PythonInteger(long_value0));
- list_items[1].Reset(PythonString(string_value1));
+ list_items[0] = PythonInteger(long_value0);
+ list_items[1] = PythonString(string_value1);
for (unsigned i = 0; i < list_size; ++i)
list.SetItemAtIndex(i, list_items[i]);
@@ -469,10 +469,10 @@ TEST_F(PythonDataObjectsTest, TestPython
PythonObject py_keys[dict_entries];
PythonObject py_values[dict_entries];
- py_keys[0].Reset(PythonString(key_0));
- py_keys[1].Reset(PythonInteger(key_1));
- py_values[0].Reset(PythonInteger(value_0));
- py_values[1].Reset(PythonString(value_1));
+ py_keys[0] = PythonString(key_0);
+ py_keys[1] = PythonInteger(key_1);
+ py_values[0] = PythonInteger(value_0);
+ py_values[1] = PythonString(value_1);
PyObject *py_dict = PyDict_New();
EXPECT_TRUE(PythonDictionary::Check(py_dict));
@@ -509,10 +509,10 @@ TEST_F(PythonDataObjectsTest, TestPython
PythonString keys[dict_entries];
PythonObject values[dict_entries];
- keys[0].Reset(PythonString(key_0));
- keys[1].Reset(PythonString(key_1));
- values[0].Reset(PythonInteger(value_0));
- values[1].Reset(PythonString(value_1));
+ keys[0] = PythonString(key_0);
+ keys[1] = PythonString(key_1);
+ values[0] = PythonInteger(value_0);
+ values[1] = PythonString(value_1);
PythonDictionary dict(PyInitialValue::Empty);
for (int i = 0; i < 2; ++i)
More information about the lldb-commits
mailing list