aboutsummaryrefslogtreecommitdiff
path: root/lldb/scripts/Python
diff options
context:
space:
mode:
authorZachary Turner <zturner@google.com>2015-10-16 16:39:18 +0000
committerZachary Turner <zturner@google.com>2015-10-16 16:39:18 +0000
commiteda01c31757db23748a0efa1629442de5cd53282 (patch)
tree287899e8cf2269aab99f5034d993a16f9573284d /lldb/scripts/Python
parent53bd9750337aff1c62891ed1309b99b9f186ddfd (diff)
downloadllvm-eda01c31757db23748a0efa1629442de5cd53282.zip
llvm-eda01c31757db23748a0efa1629442de5cd53282.tar.gz
llvm-eda01c31757db23748a0efa1629442de5cd53282.tar.bz2
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
Diffstat (limited to 'lldb/scripts/Python')
-rw-r--r--lldb/scripts/Python/python-typemaps.swig30
1 files changed, 18 insertions, 12 deletions
diff --git a/lldb/scripts/Python/python-typemaps.swig b/lldb/scripts/Python/python-typemaps.swig
index 2444d04..309b25a 100644
--- a/lldb/scripts/Python/python-typemaps.swig
+++ b/lldb/scripts/Python/python-typemaps.swig
@@ -503,27 +503,31 @@
%typemap(in) FILE * {
if ($input == Py_None)
$1 = NULL;
- else if (!PyFile_Check($input)) {
+ else if (!lldb_private::PythonFile::Check($input)) {
int fd = PyObject_AsFileDescriptor($input);
- PyObject *py_mode = PyObject_GetAttrString($input, "mode");
- if (!py_mode) {
- PyErr_SetString(PyExc_TypeError,"not a file-like object");
- return NULL;
- }
- const char *mode = PyString_AsString(py_mode);
- if (-1 != fd && mode) {
+ lldb_private::PythonString py_mode(lldb_private::PyRefType::Owned,
+ PyObject_GetAttrString($input, "mode"));
+
+ if (-1 != fd && py_mode.IsValid()) {
FILE *f;
- if ((f = fdopen(fd, mode)))
+ if ((f = fdopen(fd, py_mode.GetString().str().c_str())))
$1 = f;
else
PyErr_SetString(PyExc_TypeError, strerror(errno));
} else {
PyErr_SetString(PyExc_TypeError,"not a file-like object");
- return NULL;
+ return nullptr;
}
}
else
- $1 = PyFile_AsFile($input);
+ {
+ lldb_private::File file;
+ lldb_private::PythonFile py_file(lldb_private::PyRefType::Borrowed, $input);
+ if (!py_file.GetUnderlyingFile(file))
+ return nullptr;
+
+ $1 = file.GetStream();
+ }
}
%typemap(out) FILE * {
@@ -539,7 +543,9 @@
else // if (flags & __SRW)
mode[i++] = 'a';
#endif
- $result = PyFile_FromFile($1, const_cast<char*>(""), mode, fflush);
+ lldb_private::File file($1, false);
+ lldb_private::PythonFile py_file(file, mode);
+ $result = py_file.release();
}
%typemap(in) (const char* string, int len) {