Update SWIG typemaps to use PythonFile.

Using the Python native C API is non-portable across Python versions,
so this patch changes them to use the `PythonFile` class which hides
the version specific differences behind a single interface.

llvm-svn: 250525
This commit is contained in:
Zachary Turner
2015-10-16 16:39:18 +00:00
parent 53bd975033
commit eda01c3175
3 changed files with 44 additions and 13 deletions

View File

@@ -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