summaryrefslogtreecommitdiffstats
path: root/lldb/source/Plugins/ScriptInterpreter/Python
diff options
context:
space:
mode:
Diffstat (limited to 'lldb/source/Plugins/ScriptInterpreter/Python')
-rw-r--r--lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp22
-rw-r--r--lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h5
2 files changed, 26 insertions, 1 deletions
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
index 5c458bfd628..6a016e9e6aa 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
@@ -582,6 +582,14 @@ PythonFile::PythonFile(File &file, const char *mode)
Reset(file, mode);
}
+PythonFile::PythonFile(const char *path, const char *mode)
+{
+ FILE *fp = nullptr;
+ fp = fopen(path, mode);
+ lldb_private::File file(fp, true);
+ Reset(file, mode);
+}
+
PythonFile::PythonFile(PyRefType type, PyObject *o)
{
Reset(type, o);
@@ -651,4 +659,18 @@ PythonFile::Reset(File &file, const char *mode)
#endif
}
+bool
+PythonFile::GetUnderlyingFile(File &file) const
+{
+ if (!IsValid())
+ return false;
+
+ file.Close();
+ // We don't own the file descriptor returned by this function, make sure the
+ // File object knows about that.
+ file.SetDescriptor(PyObject_AsFileDescriptor(m_py_obj), false);
+ return file.IsValid();
+}
+
+
#endif
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
index 34549d97f3d..93513473d30 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
@@ -323,7 +323,8 @@ public:
class PythonFile : public PythonObject
{
public:
- explicit PythonFile(File &file, const char *mode);
+ PythonFile(File &file, const char *mode);
+ PythonFile(const char *path, const char *mode);
PythonFile(PyRefType type, PyObject *o);
~PythonFile() override;
@@ -333,6 +334,8 @@ class PythonFile : public PythonObject
void Reset(PyRefType type, PyObject *py_obj) override;
void Reset(File &file, const char *mode);
+
+ bool GetUnderlyingFile(File &file) const;
};
} // namespace lldb_private
OpenPOWER on IntegriCloud