diff options
| author | Johnny Chen <johnny.chen@apple.com> | 2012-02-29 01:52:13 +0000 |
|---|---|---|
| committer | Johnny Chen <johnny.chen@apple.com> | 2012-02-29 01:52:13 +0000 |
| commit | 1cf107c4332b34a23d82b7a4ed99636a577725fe (patch) | |
| tree | 2c633460cff165ec71028f99984d739758bad490 /lldb | |
| parent | f1801d65e78fc1635ccf62f2aff6ca465eb9422a (diff) | |
| download | bcm5719-llvm-1cf107c4332b34a23d82b7a4ed99636a577725fe.tar.gz bcm5719-llvm-1cf107c4332b34a23d82b7a4ed99636a577725fe.zip | |
Patch from Filipe Cabecinhas!
Attached is a small python fix to save the current stout and std err when starting a python session, then diverting them (as it was before), and restoring the previous values afterwards. Otherwise, a python script could suddenly find itself without output.
llvm-svn: 151693
Diffstat (limited to 'lldb')
| -rw-r--r-- | lldb/include/lldb/Interpreter/ScriptInterpreterPython.h | 2 | ||||
| -rw-r--r-- | lldb/source/Interpreter/ScriptInterpreterPython.cpp | 17 |
2 files changed, 16 insertions, 3 deletions
diff --git a/lldb/include/lldb/Interpreter/ScriptInterpreterPython.h b/lldb/include/lldb/Interpreter/ScriptInterpreterPython.h index 53e6b1f5f9e..f8718d3e9ff 100644 --- a/lldb/include/lldb/Interpreter/ScriptInterpreterPython.h +++ b/lldb/include/lldb/Interpreter/ScriptInterpreterPython.h @@ -252,6 +252,8 @@ private: lldb::InputReaderSP m_embedded_thread_input_reader_sp; FILE *m_dbg_stdout; void *m_new_sysout; // This is a PyObject. + void *m_old_sysout; // This is a PyObject. + void *m_old_syserr; // This is a PyObject. std::string m_dictionary_name; TerminalState m_terminal_state; bool m_session_is_active; diff --git a/lldb/source/Interpreter/ScriptInterpreterPython.cpp b/lldb/source/Interpreter/ScriptInterpreterPython.cpp index c584a819aa7..ccdf7486ca4 100644 --- a/lldb/source/Interpreter/ScriptInterpreterPython.cpp +++ b/lldb/source/Interpreter/ScriptInterpreterPython.cpp @@ -303,6 +303,15 @@ ScriptInterpreterPython::RestoreTerminalState () void ScriptInterpreterPython::LeaveSession () { + PyObject *sysmod = PyImport_AddModule ("sys"); + PyObject *sysdict = PyModule_GetDict (sysmod); + + if (m_new_sysout && sysmod && sysdict) + { + PyDict_SetItemString (sysdict, "stdout", (PyObject*)m_old_sysout); + PyDict_SetItemString (sysdict, "stderr", (PyObject*)m_old_sysout); + } + m_session_is_active = false; } @@ -336,16 +345,18 @@ ScriptInterpreterPython::EnterSession () PyRun_SimpleString (run_string.GetData()); run_string.Clear(); - + PyObject *sysmod = PyImport_AddModule ("sys"); PyObject *sysdict = PyModule_GetDict (sysmod); - + if (m_new_sysout && sysmod && sysdict) { + 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 (PyErr_Occurred()) PyErr_Clear (); } |

