[Lldb-commits] [lldb] r152337 - /lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp

Johnny Chen johnny.chen at apple.com
Thu Mar 8 12:53:04 PST 2012


Author: johnny
Date: Thu Mar  8 14:53:04 2012
New Revision: 152337

URL: http://llvm.org/viewvc/llvm-project?rev=152337&view=rev
Log:
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.

Modified:
    lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp

Modified: lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp?rev=152337&r1=152336&r2=152337&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp (original)
+++ lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp Thu Mar  8 14:53:04 2012
@@ -240,6 +240,8 @@
     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 @@
         
     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 @@
 
     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 @@
     {
         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())





More information about the lldb-commits mailing list