aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
diff options
context:
space:
mode:
authorLawrence D'Anna <lawrence_danna@apple.com>2019-09-26 17:54:59 +0000
committerLawrence D'Anna <lawrence_danna@apple.com>2019-09-26 17:54:59 +0000
commit2fce1137c7c227f40edbb657c484797addba38ca (patch)
tree1aca86d16d377f546f54a9b2c4782e51f113008c /lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
parent875d20bcde2e2b1990f3a4bdfc800959e8a72ed6 (diff)
downloadllvm-2fce1137c7c227f40edbb657c484797addba38ca.zip
llvm-2fce1137c7c227f40edbb657c484797addba38ca.tar.gz
llvm-2fce1137c7c227f40edbb657c484797addba38ca.tar.bz2
Convert FileSystem::Open() to return Expected<FileUP>
Summary: This patch converts FileSystem::Open from this prototype: Status Open(File &File, const FileSpec &file_spec, ...); to this one: llvm::Expected<std::unique_ptr<File>> Open(const FileSpec &file_spec, ...); This is beneficial on its own, as llvm::Expected is a more modern and recommended error type than Status. It is also a necessary step towards https://reviews.llvm.org/D67891, and further developments for lldb_private::File. Reviewers: JDevlieghere, jasonmolenda, labath Reviewed By: labath Subscribers: mgorny, lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D67996 llvm-svn: 373003
Diffstat (limited to 'lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp')
-rw-r--r--lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp17
1 files changed, 7 insertions, 10 deletions
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
index 97f8388..bb7f77f 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
@@ -949,11 +949,6 @@ PythonFile::PythonFile() : PythonObject() {}
PythonFile::PythonFile(File &file, const char *mode) { Reset(file, mode); }
-PythonFile::PythonFile(const char *path, const char *mode) {
- lldb_private::File file;
- FileSystem::Instance().Open(file, FileSpec(path), GetOptionsFromMode(mode));
- Reset(file, mode);
-}
PythonFile::PythonFile(PyRefType type, PyObject *o) { Reset(type, o); }
@@ -1036,17 +1031,19 @@ uint32_t PythonFile::GetOptionsFromMode(llvm::StringRef mode) {
.Default(0);
}
-bool PythonFile::GetUnderlyingFile(File &file) const {
+FileUP PythonFile::GetUnderlyingFile() const {
if (!IsValid())
- return false;
+ return nullptr;
- file.Close();
// We don't own the file descriptor returned by this function, make sure the
// File object knows about that.
PythonString py_mode = GetAttributeValue("mode").AsType<PythonString>();
auto options = PythonFile::GetOptionsFromMode(py_mode.GetString());
- file.SetDescriptor(PyObject_AsFileDescriptor(m_py_obj), options, false);
- return file.IsValid();
+ auto file = std::make_unique<File>(PyObject_AsFileDescriptor(m_py_obj),
+ options, false);
+ if (!file->IsValid())
+ return nullptr;
+ return file;
}
#endif