From 0642cd768b80665585c8500bed2933a3b99123dc Mon Sep 17 00:00:00 2001 From: Adrian Prantl Date: Tue, 27 Aug 2024 10:59:31 -0700 Subject: [lldb] Turn lldb_private::Status into a value type. (#106163) This patch removes all of the Set.* methods from Status. This cleanup is part of a series of patches that make it harder use the anti-pattern of keeping a long-lives Status object around and updating it while dropping any errors it contains on the floor. This patch is largely NFC, the more interesting next steps this enables is to: 1. remove Status.Clear() 2. assert that Status::operator=() never overwrites an error 3. remove Status::operator=() Note that step (2) will bring 90% of the benefits for users, and step (3) will dramatically clean up the error handling code in various places. In the end my goal is to convert all APIs that are of the form ` ResultTy DoFoo(Status& error) ` to ` llvm::Expected DoFoo() ` How to read this patch? The interesting changes are in Status.h and Status.cpp, all other changes are mostly ` perl -pi -e 's/\.SetErrorString/ = Status::FromErrorString/g' $(git grep -l SetErrorString lldb/source) ` plus the occasional manual cleanup. --- .../Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp') diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp index 7c7035e..ce14b53 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp +++ b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp @@ -1247,7 +1247,8 @@ public: if (!bytes_written) return Status(bytes_written.takeError()); if (bytes_written.get() < 0) - return Status(".write() method returned a negative number!"); + return Status::FromErrorString( + ".write() method returned a negative number!"); static_assert(sizeof(long long) >= sizeof(size_t), "overflow"); num_bytes = bytes_written.get(); return Status(); @@ -1301,7 +1302,8 @@ public: if (!bytes_written) return Status(bytes_written.takeError()); if (bytes_written.get() < 0) - return Status(".write() method returned a negative number!"); + return Status::FromErrorString( + ".write() method returned a negative number!"); static_assert(sizeof(long long) >= sizeof(size_t), "overflow"); num_bytes = bytes_written.get(); return Status(); @@ -1313,7 +1315,8 @@ public: size_t orig_num_bytes = num_bytes; num_bytes = 0; if (orig_num_bytes < 6) { - return Status("can't read less than 6 bytes from a utf8 text stream"); + return Status::FromErrorString( + "can't read less than 6 bytes from a utf8 text stream"); } auto pystring = As( m_py_obj.CallMethod("read", (unsigned long long)num_chars)); -- cgit v1.1