[Lldb-commits] [lldb] r162152 - in /lldb/branches/apple/python-GIL: ./ include/lldb/Interpreter/ScriptInterpreterPython.h source/Interpreter/ScriptInterpreterPython.cpp

Johnny Chen johnny.chen at apple.com
Fri Aug 17 17:26:56 PDT 2012


Author: johnny
Date: Fri Aug 17 19:26:56 2012
New Revision: 162152

URL: http://llvm.org/viewvc/llvm-project?rev=162152&view=rev
Log:
Merge changes from ToT trunk.

Modified:
    lldb/branches/apple/python-GIL/   (props changed)
    lldb/branches/apple/python-GIL/include/lldb/Interpreter/ScriptInterpreterPython.h
    lldb/branches/apple/python-GIL/source/Interpreter/ScriptInterpreterPython.cpp

Propchange: lldb/branches/apple/python-GIL/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Aug 17 19:26:56 2012
@@ -1 +1 @@
-/lldb/trunk:156467-162002
+/lldb/trunk:156467-162147

Modified: lldb/branches/apple/python-GIL/include/lldb/Interpreter/ScriptInterpreterPython.h
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/apple/python-GIL/include/lldb/Interpreter/ScriptInterpreterPython.h?rev=162152&r1=162151&r2=162152&view=diff
==============================================================================
--- lldb/branches/apple/python-GIL/include/lldb/Interpreter/ScriptInterpreterPython.h (original)
+++ lldb/branches/apple/python-GIL/include/lldb/Interpreter/ScriptInterpreterPython.h Fri Aug 17 19:26:56 2012
@@ -315,8 +315,10 @@
                          size_t bytes_len);
 
 
+    lldb_utility::PseudoTerminal m_embedded_thread_pty;
     lldb_utility::PseudoTerminal m_embedded_python_pty;
     lldb::InputReaderSP m_embedded_thread_input_reader_sp;
+    lldb::InputReaderSP m_embedded_python_input_reader_sp;
     FILE *m_dbg_stdout;
     PyObject *m_new_sysout;
     PyObject *m_old_sysout;

Modified: lldb/branches/apple/python-GIL/source/Interpreter/ScriptInterpreterPython.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/apple/python-GIL/source/Interpreter/ScriptInterpreterPython.cpp?rev=162152&r1=162151&r2=162152&view=diff
==============================================================================
--- lldb/branches/apple/python-GIL/source/Interpreter/ScriptInterpreterPython.cpp (original)
+++ lldb/branches/apple/python-GIL/source/Interpreter/ScriptInterpreterPython.cpp Fri Aug 17 19:26:56 2012
@@ -252,23 +252,20 @@
 
 ScriptInterpreterPython::PythonInputReaderManager::~PythonInputReaderManager()
 {
-    if (m_interpreter)
-    {
-        if (m_interpreter->m_embedded_thread_input_reader_sp)
-            m_interpreter->m_embedded_thread_input_reader_sp->SetIsDone (true);
-        m_interpreter->m_embedded_python_pty.CloseSlaveFileDescriptor();
-    }
-    
-    
-    if (m_reader_sp)
+    // Nothing to do if either m_interpreter or m_reader_sp is invalid.
+    if (!m_interpreter || !m_reader_sp)
+        return;
+
+    m_reader_sp->SetIsDone (true);
+    if (m_debugger_sp)
+        m_debugger_sp->PopInputReader(m_reader_sp);
+
+    // Only mess with m_interpreter's counterpart if, indeed, they are the same object.
+    if (m_reader_sp.get() == m_interpreter->m_embedded_thread_input_reader_sp.get())
     {
-        m_reader_sp->SetIsDone (true);
-        if (m_debugger_sp)
-            m_debugger_sp->PopInputReader(m_reader_sp);
-    }
-    
-    if (m_interpreter)
+        m_interpreter->m_embedded_thread_pty.CloseSlaveFileDescriptor();
         m_interpreter->m_embedded_thread_input_reader_sp.reset();
+    }
 }
 
 size_t
@@ -306,16 +303,16 @@
             script_interpreter->SaveTerminalState(input_fd);
 
             char error_str[1024];
-            if (script_interpreter->m_embedded_python_pty.OpenFirstAvailableMaster (O_RDWR|O_NOCTTY, error_str, 
+            if (script_interpreter->m_embedded_thread_pty.OpenFirstAvailableMaster (O_RDWR|O_NOCTTY, error_str, 
                                                                                     sizeof(error_str)))
             {
                 if (log)
                     log->Printf ("ScriptInterpreterPython::NonInteractiveInputReaderCallback, Activate, succeeded in opening master pty (fd = %d).",
-                                 script_interpreter->m_embedded_python_pty.GetMasterFileDescriptor());
+                                 script_interpreter->m_embedded_thread_pty.GetMasterFileDescriptor());
                 {
                     StreamString run_string;
                     char error_str[1024];
-                    const char *pty_slave_name = script_interpreter->m_embedded_python_pty.GetSlaveName (error_str, sizeof (error_str));
+                    const char *pty_slave_name = script_interpreter->m_embedded_thread_pty.GetSlaveName (error_str, sizeof (error_str));
                     if (pty_slave_name != NULL && PyThreadState_GetDict() != NULL)
                     {
                         ScriptInterpreterPython::Locker locker(script_interpreter,
@@ -390,14 +387,14 @@
             break;
             
         case eInputReaderGotToken:
-            if (script_interpreter->m_embedded_python_pty.GetMasterFileDescriptor() != -1)
+            if (script_interpreter->m_embedded_thread_pty.GetMasterFileDescriptor() != -1)
             {
                 if (log)
                     log->Printf ("ScriptInterpreterPython::NonInteractiveInputReaderCallback, GotToken, bytes='%s', byte_len = %lu", bytes,
                                  bytes_len);
                 if (bytes && bytes_len)
-                    ::write (script_interpreter->m_embedded_python_pty.GetMasterFileDescriptor(), bytes, bytes_len);
-                ::write (script_interpreter->m_embedded_python_pty.GetMasterFileDescriptor(), "\n", 1);
+                    ::write (script_interpreter->m_embedded_thread_pty.GetMasterFileDescriptor(), bytes, bytes_len);
+                ::write (script_interpreter->m_embedded_thread_pty.GetMasterFileDescriptor(), "\n", 1);
             }
             else
             {
@@ -414,7 +411,7 @@
         {
             StreamString run_string;
             char error_str[1024];
-            const char *pty_slave_name = script_interpreter->m_embedded_python_pty.GetSlaveName (error_str, sizeof (error_str));
+            const char *pty_slave_name = script_interpreter->m_embedded_thread_pty.GetSlaveName (error_str, sizeof (error_str));
             if (pty_slave_name != NULL && PyThreadState_GetDict() != NULL)
             {
                 ScriptInterpreterPython::Locker locker(script_interpreter,
@@ -436,7 +433,7 @@
             
             script_interpreter->RestoreTerminalState ();
             
-            script_interpreter->m_embedded_python_pty.CloseMasterFileDescriptor();
+            script_interpreter->m_embedded_thread_pty.CloseMasterFileDescriptor();
             break;
     }
     
@@ -445,8 +442,10 @@
 
 ScriptInterpreterPython::ScriptInterpreterPython (CommandInterpreter &interpreter) :
     ScriptInterpreter (interpreter, eScriptLanguagePython),
+    m_embedded_thread_pty (),
     m_embedded_python_pty (),
     m_embedded_thread_input_reader_sp (),
+    m_embedded_python_input_reader_sp (),
     m_dbg_stdout (interpreter.GetDebugger().GetOutputFile().GetStream()),
     m_new_sysout (NULL),
     m_old_sysout (NULL),
@@ -520,10 +519,19 @@
     if (m_embedded_thread_input_reader_sp.get() != NULL)
     {
         m_embedded_thread_input_reader_sp->SetIsDone (true);
-        m_embedded_python_pty.CloseSlaveFileDescriptor();
+        m_embedded_thread_pty.CloseSlaveFileDescriptor();
         const InputReaderSP reader_sp = m_embedded_thread_input_reader_sp;
+        debugger.PopInputReader (reader_sp);
         m_embedded_thread_input_reader_sp.reset();
+    }
+    
+    if (m_embedded_python_input_reader_sp.get() != NULL)
+    {
+        m_embedded_python_input_reader_sp->SetIsDone (true);
+        m_embedded_python_pty.CloseSlaveFileDescriptor();
+        const InputReaderSP reader_sp = m_embedded_python_input_reader_sp;
         debugger.PopInputReader (reader_sp);
+        m_embedded_python_input_reader_sp.reset();
     }
     
     if (m_new_sysout)
@@ -975,7 +983,7 @@
         if (error.Success())
         {
             debugger.PushInputReader (reader_sp);
-            m_embedded_thread_input_reader_sp = reader_sp;
+            m_embedded_python_input_reader_sp = reader_sp;
         }
     }
 }
@@ -2004,8 +2012,8 @@
         run_string.Clear();
     }
     
-    if (script_interpreter->m_embedded_thread_input_reader_sp)
-        script_interpreter->m_embedded_thread_input_reader_sp->SetIsDone (true);
+    if (script_interpreter->m_embedded_python_input_reader_sp)
+        script_interpreter->m_embedded_python_input_reader_sp->SetIsDone (true);
     
     script_interpreter->m_embedded_python_pty.CloseSlaveFileDescriptor();
 
@@ -2016,9 +2024,12 @@
 
     // Clean up the input reader and make the debugger pop it off the stack.
     Debugger &debugger = script_interpreter->GetCommandInterpreter().GetDebugger();
-    const InputReaderSP reader_sp = script_interpreter->m_embedded_thread_input_reader_sp;
-    script_interpreter->m_embedded_thread_input_reader_sp.reset();
-    debugger.PopInputReader (reader_sp);
+    const InputReaderSP reader_sp = script_interpreter->m_embedded_python_input_reader_sp;
+    if (reader_sp)
+    {
+        debugger.PopInputReader (reader_sp);
+        script_interpreter->m_embedded_python_input_reader_sp.reset();
+    }
     
     return NULL;
 }





More information about the lldb-commits mailing list