summaryrefslogtreecommitdiffstats
path: root/lldb/scripts
diff options
context:
space:
mode:
authorLawrence D'Anna <lawrence_danna@apple.com>2019-10-15 16:46:27 +0000
committerLawrence D'Anna <lawrence_danna@apple.com>2019-10-15 16:46:27 +0000
commitd9b553ec9961e95740535d3aeff62817f867767f (patch)
treea20193fd70d7956369ddf7c7b75407b7273c597f /lldb/scripts
parent1184c27fa586f8fe713921150146d433aae969ff (diff)
downloadbcm5719-llvm-d9b553ec9961e95740535d3aeff62817f867767f.tar.gz
bcm5719-llvm-d9b553ec9961e95740535d3aeff62817f867767f.zip
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
Diffstat (limited to 'lldb/scripts')
-rw-r--r--lldb/scripts/Python/python-typemaps.swig16
-rw-r--r--lldb/scripts/interface/SBFile.i17
2 files changed, 33 insertions, 0 deletions
diff --git a/lldb/scripts/Python/python-typemaps.swig b/lldb/scripts/Python/python-typemaps.swig
index 9428c7c92ff..b9389022512 100644
--- a/lldb/scripts/Python/python-typemaps.swig
+++ b/lldb/scripts/Python/python-typemaps.swig
@@ -434,6 +434,22 @@ bool SetNumberFromPyObject<double>(double &number, PyObject *obj) {
}
}
+%typemap(out) lldb::FileSP {
+ using namespace lldb_private;
+ $result = nullptr;
+ lldb::FileSP &sp = $1;
+ if (sp) {
+ PythonFile pyfile = unwrapOrSetPythonException(PythonFile::FromFile(*sp));
+ if (!pyfile.IsValid())
+ return nullptr;
+ $result = pyfile.release();
+ }
+ if (!$result)
+ {
+ $result = Py_None;
+ Py_INCREF(Py_None);
+ }
+}
// FIXME both of these paths wind up calling fdopen() with no provision for ever calling
// fclose() on the result. SB interfaces that use FILE* should be deprecated for scripting
diff --git a/lldb/scripts/interface/SBFile.i b/lldb/scripts/interface/SBFile.i
index 179446d5a53..27b83641338 100644
--- a/lldb/scripts/interface/SBFile.i
+++ b/lldb/scripts/interface/SBFile.i
@@ -77,6 +77,23 @@ public:
operator bool() const;
SBError Close();
+
+ %feature("docstring", "
+ Convert this SBFile into a python io.IOBase file object.
+
+ If the SBFile is itself a wrapper around a python file object,
+ this will return that original object.
+
+ The file returned from here should be considered borrowed,
+ in the sense that you may read and write to it, and flush it,
+ etc, but you should not close it. If you want to close the
+ SBFile, call SBFile.Close().
+
+ If there is no underlying python file to unwrap, GetFile will
+ use the file descriptor, if availble to create a new python
+ file object using `open(fd, mode=..., closefd=False)`
+ ");
+ FileSP GetFile();
};
} // namespace lldb
OpenPOWER on IntegriCloud