diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2021-11-19 20:06:13 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2021-11-19 20:06:13 +0000 |
commit | c0981da47d5696fe36474fcf86b4ce03ae3ff818 (patch) | |
tree | f42add1021b9f2ac6a69ac7cf6c4499962739a45 /lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp | |
parent | 344a3780b2e33f6ca763666c380202b18aab72a3 (diff) |
Diffstat (limited to 'lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp')
-rw-r--r-- | lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp | 29 |
1 files changed, 10 insertions, 19 deletions
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp index f51d9b3a796c..7c71c9329e57 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp +++ b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp @@ -998,20 +998,6 @@ bool PythonFile::Check(PyObject *py_obj) { #endif } -namespace { -class GIL { -public: - GIL() { - m_state = PyGILState_Ensure(); - assert(!PyErr_Occurred()); - } - ~GIL() { PyGILState_Release(m_state); } - -protected: - PyGILState_STATE m_state; -}; -} // namespace - const char *PythonException::toCString() const { if (!m_repr_bytes) return "unknown exception"; @@ -1114,10 +1100,12 @@ GetOptionsForPyObject(const PythonObject &obj) { auto writable = As<bool>(obj.CallMethod("writable")); if (!writable) return writable.takeError(); - if (readable.get()) - options |= File::eOpenOptionRead; - if (writable.get()) - options |= File::eOpenOptionWrite; + if (readable.get() && writable.get()) + options |= File::eOpenOptionReadWrite; + else if (writable.get()) + options |= File::eOpenOptionWriteOnly; + else if (readable.get()) + options |= File::eOpenOptionReadOnly; return options; #else PythonString py_mode = obj.GetAttributeValue("mode").AsType<PythonString>(); @@ -1413,7 +1401,10 @@ llvm::Expected<FileSP> PythonFile::ConvertToFile(bool borrowed) { if (!options) return options.takeError(); - if (options.get() & File::eOpenOptionWrite) { + File::OpenOptions rw = + options.get() & (File::eOpenOptionReadOnly | File::eOpenOptionWriteOnly | + File::eOpenOptionReadWrite); + if (rw == File::eOpenOptionWriteOnly || rw == File::eOpenOptionReadWrite) { // LLDB and python will not share I/O buffers. We should probably // flush the python buffers now. auto r = CallMethod("flush"); |