summaryrefslogtreecommitdiffstats
path: root/lldb/source/Interpreter/ScriptInterpreterPython.cpp
diff options
context:
space:
mode:
authorJohnny Chen <johnny.chen@apple.com>2012-03-08 20:53:04 +0000
committerJohnny Chen <johnny.chen@apple.com>2012-03-08 20:53:04 +0000
commit5d34629daf7a434f4763dc19bb654af7c200de0b (patch)
tree6419af978e00cad27fdc9d016718e124734c14bb /lldb/source/Interpreter/ScriptInterpreterPython.cpp
parent8292678017571be445490071aebb744588f2fa1d (diff)
downloadbcm5719-llvm-5d34629daf7a434f4763dc19bb654af7c200de0b.tar.gz
bcm5719-llvm-5d34629daf7a434f4763dc19bb654af7c200de0b.zip
Fixed a crasher when Xcode calls into ScriptInterpreterPython::ResetOutputFileHandle().
The Locker should only perform acquire/free lock operation, but no enter/leave session at all. Also added sanity checks for items passed to the PyDict_SetItemString() calls. llvm-svn: 152337
Diffstat (limited to 'lldb/source/Interpreter/ScriptInterpreterPython.cpp')
-rw-r--r--lldb/source/Interpreter/ScriptInterpreterPython.cpp21
1 files changed, 15 insertions, 6 deletions
diff --git a/lldb/source/Interpreter/ScriptInterpreterPython.cpp b/lldb/source/Interpreter/ScriptInterpreterPython.cpp
index 1653e92e9b5..7a9140f0a2a 100644
--- a/lldb/source/Interpreter/ScriptInterpreterPython.cpp
+++ b/lldb/source/Interpreter/ScriptInterpreterPython.cpp
@@ -240,6 +240,8 @@ ScriptInterpreterPython::ScriptInterpreterPython (CommandInterpreter &interprete
m_embedded_thread_input_reader_sp (),
m_dbg_stdout (interpreter.GetDebugger().GetOutputFile().GetStream()),
m_new_sysout (NULL),
+ m_old_sysout (NULL),
+ m_old_syserr (NULL),
m_run_one_line (NULL),
m_dictionary_name (interpreter.GetDebugger().GetInstanceName().AsCString()),
m_terminal_state (),
@@ -332,8 +334,10 @@ ScriptInterpreterPython::ResetOutputFileHandle (FILE *fh)
m_dbg_stdout = fh;
- Locker py_lock(this);
-
+ Locker locker(this,
+ ScriptInterpreterPython::Locker::AcquireLock,
+ ScriptInterpreterPython::Locker::FreeAcquiredLock);
+
m_new_sysout = PyFile_FromFile (m_dbg_stdout, (char *) "", (char *) "w", _check_and_flush);
}
@@ -365,8 +369,10 @@ ScriptInterpreterPython::LeaveSession ()
if (m_new_sysout && sysmod && sysdict)
{
- PyDict_SetItemString (sysdict, "stdout", (PyObject*)m_old_sysout);
- PyDict_SetItemString (sysdict, "stderr", (PyObject*)m_old_sysout);
+ if (m_old_sysout)
+ PyDict_SetItemString (sysdict, "stdout", (PyObject*)m_old_sysout);
+ if (m_old_syserr)
+ PyDict_SetItemString (sysdict, "stderr", (PyObject*)m_old_syserr);
}
m_session_is_active = false;
@@ -410,8 +416,11 @@ ScriptInterpreterPython::EnterSession ()
{
m_old_sysout = PyDict_GetItemString(sysdict, "stdout");
m_old_syserr = PyDict_GetItemString(sysdict, "stderr");
- PyDict_SetItemString (sysdict, "stdout", (PyObject*)m_new_sysout);
- PyDict_SetItemString (sysdict, "stderr", (PyObject*)m_new_sysout);
+ if (m_new_sysout)
+ {
+ PyDict_SetItemString (sysdict, "stdout", (PyObject*)m_new_sysout);
+ PyDict_SetItemString (sysdict, "stderr", (PyObject*)m_new_sysout);
+ }
}
if (PyErr_Occurred())
OpenPOWER on IntegriCloud