[Lldb-commits] [lldb] r162203 - /lldb/trunk/scripts/Python/python-typemaps.swig
Filipe Cabecinhas
me at filcab.net
Mon Aug 20 09:10:44 PDT 2012
Author: filcab
Date: Mon Aug 20 11:10:44 2012
New Revision: 162203
URL: http://llvm.org/viewvc/llvm-project?rev=162203&view=rev
Log:
Add FILE* typemaps for SBDebugger.GetInputFileHandle() and friends.
Modified:
lldb/trunk/scripts/Python/python-typemaps.swig
Modified: lldb/trunk/scripts/Python/python-typemaps.swig
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/python-typemaps.swig?rev=162203&r1=162202&r2=162203&view=diff
==============================================================================
--- lldb/trunk/scripts/Python/python-typemaps.swig (original)
+++ lldb/trunk/scripts/Python/python-typemaps.swig Mon Aug 20 11:10:44 2012
@@ -333,3 +333,38 @@
%typemap(freearg) (uint32_t *versions) {
free($1);
}
+
+%typemap(in) FILE * {
+ if (!PyFile_Check($input)) {
+ int fd = PyObject_AsFileDescriptor($input);
+ PyObject *py_mode = PyObject_GetAttrString($input, "mode");
+ const char *mode = PyString_AsString(py_mode);
+ if (-1 != fd && mode) {
+ FILE *f;
+ if ((f = fdopen(fd, mode)))
+ $1 = f;
+ else
+ PyErr_SetString(PyExc_TypeError, strerror(errno));
+ } else {
+ PyErr_SetString(PyExc_TypeError,"not a file-like object");
+ return NULL;
+ }
+ }
+ $1 = PyFile_AsFile($input);
+}
+
+%typemap(out) FILE * {
+ char mode[4] = {0};
+#ifdef __MACOSX__
+ int i = 0;
+ short flags = $1->_flags;
+
+ if (flags & __SRD)
+ mode[i++] = 'r';
+ else if (flags & __SWR)
+ mode[i++] = 'w';
+ else // if (flags & __SRW)
+ mode[i++] = 'a';
+#endif
+ $result = PyFile_FromFile($1, const_cast<char*>(""), mode, fclose);
+}
More information about the lldb-commits
mailing list