aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
diff options
context:
space:
mode:
authorLawrence D'Anna <lawrence_danna@apple.com>2019-10-28 21:59:04 -0700
committerLawrence D'Anna <lawrence_danna@apple.com>2019-10-29 09:41:22 -0700
commit6a93a12a8dd98291225a282b5b8f3c97e68ebe49 (patch)
tree8c434bc0d961e94ad245051106c1205f69eeedbe /lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
parent5503455ccb3f5fcedced158332c016c8d3a7fa81 (diff)
downloadllvm-6a93a12a8dd98291225a282b5b8f3c97e68ebe49.zip
llvm-6a93a12a8dd98291225a282b5b8f3c97e68ebe49.tar.gz
llvm-6a93a12a8dd98291225a282b5b8f3c97e68ebe49.tar.bz2
[LLDB][Python] fix another fflush issue on NetBSD
Summary: Here's another instance where we were calling fflush on an input stream, which is illegal on NetBSD. Reviewers: labath, mgorny Reviewed By: mgorny Subscribers: krytarowski, lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D69488
Diffstat (limited to 'lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp')
-rw-r--r--lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp17
1 files changed, 12 insertions, 5 deletions
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
index 2b85ebf..df8bac9 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
@@ -1502,12 +1502,19 @@ Expected<PythonFile> PythonFile::FromFile(File &file, const char *mode) {
file_obj = PyFile_FromFd(file.GetDescriptor(), nullptr, mode, -1, nullptr,
"ignore", nullptr, 0);
#else
- // Read through the Python source, doesn't seem to modify these strings
- char *cmode = const_cast<char *>(mode);
// We pass ::flush instead of ::fclose here so we borrow the FILE* --
- // the lldb_private::File still owns it.
- file_obj =
- PyFile_FromFile(file.GetStream(), const_cast<char *>(""), cmode, ::fflush);
+ // the lldb_private::File still owns it. NetBSD does not allow
+ // input files to be flushed, so we have to check for that case too.
+ int (*closer)(FILE *);
+ auto opts = file.GetOptions();
+ if (!opts)
+ return opts.takeError();
+ if (opts.get() & File::eOpenOptionWrite)
+ closer = ::fflush;
+ else
+ closer = [](FILE *) { return 0; };
+ file_obj = PyFile_FromFile(file.GetStream(), py2_const_cast(""),
+ py2_const_cast(mode), closer);
#endif
if (!file_obj)