aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp')
-rw-r--r--contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp29
1 files changed, 10 insertions, 19 deletions
diff --git a/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp b/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
index f51d9b3a796c..7c71c9329e57 100644
--- a/contrib/llvm-project/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
+++ b/contrib/llvm-project/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");