Author: labath Date: Thu Oct 3 01:44:33 2019 New Revision: 373573 URL: http://llvm.org/viewvc/llvm-project?rev=373573&view=rev Log: "Fix" TestFileHandle.py on non-darwin platforms
This test exposed a very long standing issue that the python file objects returned by the FILE* typemap were unusable on non-darwin platforms. The reason they work on darwin is that they rely on a non-standard extension to fetch the "mode" of a FILE* object. On other platforms, this code was #ifdefed out, and so we were returning an empty mode. As there's no portable way to get this information, I just change the non-darwin path to return "r+", which should permit both reading and writing operations on the object. If the underlying file descriptor turns out to be incompatible with this mode, the operating system should return EBADF (or equivalent), instead of the "file not open for XXX" error from python. 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=373573&r1=373572&r2=373573&view=diff ============================================================================== --- lldb/trunk/scripts/Python/python-typemaps.swig (original) +++ lldb/trunk/scripts/Python/python-typemaps.swig Thu Oct 3 01:44:33 2019 @@ -406,6 +406,8 @@ bool SetNumberFromPyObject<double>(doubl } %typemap(out) FILE * { + // TODO: This is gross. We should find a way to fetch the mode flags from the + // lldb_private::File object. char mode[4] = {0}; %#ifdef __APPLE__ int i = 0; @@ -420,6 +422,12 @@ bool SetNumberFromPyObject<double>(doubl else // if (flags & __SRW) mode[i++] = 'a'; } +%#else + // There's no portable way to get the mode here. We just return a mode which + // permits both reads and writes and count on the operating system to return + // an error when an invalid operation is attempted. + mode[0] = 'r'; + mode[1] = '+'; %#endif using namespace lldb_private; NativeFile file($1, false); _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits