From d9b553ec9961e95740535d3aeff62817f867767f Mon Sep 17 00:00:00 2001 From: Lawrence D'Anna Date: Tue, 15 Oct 2019 16:46:27 +0000 Subject: SBFile::GetFile: convert SBFile back into python native files. Summary: This makes SBFile::GetFile public and adds a SWIG typemap to convert the result back into a python native file. If the underlying File itself came from a python file, it is returned identically. Otherwise a new python file object is created using the file descriptor. Reviewers: JDevlieghere, jasonmolenda, labath Reviewed By: labath Subscribers: lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D68737 llvm-svn: 374911 --- .../ScriptInterpreter/Python/PythonDataObjects.h | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h') diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h index a26b64a..b794810 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h +++ b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h @@ -638,7 +638,7 @@ public: void Reset(PyRefType type, PyObject *py_obj) override; ArgInfo GetNumArguments() const; - + // If the callable is a Py_Class, then find the number of arguments // of the __init__ method. ArgInfo GetNumInitArguments() const; @@ -658,7 +658,6 @@ public: class PythonFile : public PythonObject { public: PythonFile(); - PythonFile(File &file, const char *mode); PythonFile(PyRefType type, PyObject *o); ~PythonFile() override; @@ -668,7 +667,21 @@ public: using PythonObject::Reset; void Reset(PyRefType type, PyObject *py_obj) override; - void Reset(File &file, const char *mode); + + static llvm::Expected FromFile(File &file, + const char *mode = nullptr); + + // FIXME delete this after FILE* typemaps are deleted + // and ScriptInterpreterPython is fixed + PythonFile(File &file, const char *mode = nullptr) { + auto f = FromFile(file, mode); + if (f) + *this = std::move(f.get()); + else { + Reset(); + llvm::consumeError(f.takeError()); + } + } lldb::FileUP GetUnderlyingFile() const; -- cgit v1.1