summaryrefslogtreecommitdiffstats
path: root/lldb/source/Interpreter/ScriptInterpreterPython.cpp
diff options
context:
space:
mode:
authorEnrico Granata <egranata@apple.com>2012-04-04 17:31:29 +0000
committerEnrico Granata <egranata@apple.com>2012-04-04 17:31:29 +0000
commit0249fba8c3281d6c991e58472045e8a9bbb91910 (patch)
treefa54db9501d52ca7d65bcf8667c760f95e6b7fbb /lldb/source/Interpreter/ScriptInterpreterPython.cpp
parent8d4a8010cf9a9e2d7b7aa047677a6fc29cca630a (diff)
downloadbcm5719-llvm-0249fba8c3281d6c991e58472045e8a9bbb91910.tar.gz
bcm5719-llvm-0249fba8c3281d6c991e58472045e8a9bbb91910.zip
Fixing a potential crasher where Python would assume we have no thread state while clearing out an SBDebugger which was acquiring input from the interactive interpreter
llvm-svn: 154027
Diffstat (limited to 'lldb/source/Interpreter/ScriptInterpreterPython.cpp')
-rw-r--r--lldb/source/Interpreter/ScriptInterpreterPython.cpp23
1 files changed, 15 insertions, 8 deletions
diff --git a/lldb/source/Interpreter/ScriptInterpreterPython.cpp b/lldb/source/Interpreter/ScriptInterpreterPython.cpp
index afde01fbebd..39c111704fe 100644
--- a/lldb/source/Interpreter/ScriptInterpreterPython.cpp
+++ b/lldb/source/Interpreter/ScriptInterpreterPython.cpp
@@ -381,15 +381,22 @@ ScriptInterpreterPython::RestoreTerminalState ()
void
ScriptInterpreterPython::LeaveSession ()
{
- PyObject *sysmod = PyImport_AddModule ("sys");
- PyObject *sysdict = PyModule_GetDict (sysmod);
-
- if (m_new_sysout && sysmod && sysdict)
+ // checking that we have a valid thread state - since we use our own threading and locking
+ // in some (rare) cases during cleanup Python may end up believing we have no thread state
+ // and PyImport_AddModule will crash if that is the case - since that seems to only happen
+ // when destroying the SBDebugger, we can make do without clearing up stdout and stderr
+ if (PyThreadState_Get())
{
- if (m_old_sysout)
- PyDict_SetItemString (sysdict, "stdout", (PyObject*)m_old_sysout);
- if (m_old_syserr)
- PyDict_SetItemString (sysdict, "stderr", (PyObject*)m_old_syserr);
+ PyObject *sysmod = PyImport_AddModule ("sys");
+ PyObject *sysdict = PyModule_GetDict (sysmod);
+
+ if (m_new_sysout && sysmod && sysdict)
+ {
+ 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;
OpenPOWER on IntegriCloud