[Lldb-commits] [lldb] r142754 - in /lldb/trunk: include/lldb/Core/FormatClasses.h include/lldb/Interpreter/ScriptInterpreterPython.h source/Core/FormatClasses.cpp source/Interpreter/ScriptInterpreterPython.cpp

Benjamin Kramer benny.kra at googlemail.com
Sun Oct 23 09:49:03 PDT 2011


Author: d0k
Date: Sun Oct 23 11:49:03 2011
New Revision: 142754

URL: http://llvm.org/viewvc/llvm-project?rev=142754&view=rev
Log:
Move Python.h includes out of the headers into the .cpp file where it's actually used.

Python.h includes a ton of macros that can cause weird behavior down the road.

Modified:
    lldb/trunk/include/lldb/Core/FormatClasses.h
    lldb/trunk/include/lldb/Interpreter/ScriptInterpreterPython.h
    lldb/trunk/source/Core/FormatClasses.cpp
    lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp

Modified: lldb/trunk/include/lldb/Core/FormatClasses.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/FormatClasses.h?rev=142754&r1=142753&r2=142754&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/FormatClasses.h (original)
+++ lldb/trunk/include/lldb/Core/FormatClasses.h Sun Oct 23 11:49:03 2011
@@ -11,13 +11,6 @@
 #define lldb_FormatClasses_h_
 
 // C Includes
-
-#if defined (__APPLE__)
-#include <Python/Python.h>
-#else
-#include <Python.h>
-#endif
-
 #include <stdint.h>
 #include <unistd.h>
 
@@ -302,7 +295,7 @@
     {
     private:
         std::string m_python_class;
-        PyObject* m_wrapper;
+        void *m_wrapper; // Wraps PyObject.
         ScriptInterpreter *m_interpreter;
     public:
         
@@ -310,10 +303,7 @@
                  lldb::ValueObjectSP be);
         
         virtual
-        ~FrontEnd()
-        {
-            Py_XDECREF(m_wrapper);
-        }
+        ~FrontEnd();
         
         virtual uint32_t
         CalculateNumChildren()

Modified: lldb/trunk/include/lldb/Interpreter/ScriptInterpreterPython.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/ScriptInterpreterPython.h?rev=142754&r1=142753&r2=142754&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/ScriptInterpreterPython.h (original)
+++ lldb/trunk/include/lldb/Interpreter/ScriptInterpreterPython.h Sun Oct 23 11:49:03 2011
@@ -11,12 +11,6 @@
 #ifndef liblldb_ScriptInterpreterPython_h_
 #define liblldb_ScriptInterpreterPython_h_
 
-#if defined (__APPLE__)
-#include <Python/Python.h>
-#else
-#include <Python.h>
-#endif
-
 #include "lldb/lldb-private.h"
 #include "lldb/Interpreter/ScriptInterpreter.h"
 #include "lldb/Core/InputReader.h"
@@ -197,7 +191,7 @@
     lldb_utility::PseudoTerminal m_embedded_python_pty;
     lldb::InputReaderSP m_embedded_thread_input_reader_sp;
     FILE *m_dbg_stdout;
-    PyObject *m_new_sysout;
+    void *m_new_sysout; // This is a PyObject.
     std::string m_dictionary_name;
     TerminalState m_terminal_state;
     bool m_session_is_active;

Modified: lldb/trunk/source/Core/FormatClasses.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/FormatClasses.cpp?rev=142754&r1=142753&r2=142754&view=diff
==============================================================================
--- lldb/trunk/source/Core/FormatClasses.cpp (original)
+++ lldb/trunk/source/Core/FormatClasses.cpp Sun Oct 23 11:49:03 2011
@@ -8,6 +8,11 @@
 //===----------------------------------------------------------------------===//
 
 // C Includes
+#if defined (__APPLE__)
+#include <Python/Python.h>
+#else
+#include <Python.h>
+#endif
 
 // C++ Includes
 #include <ostream>
@@ -243,7 +248,12 @@
     if (m_interpreter == NULL)
         m_wrapper = NULL;
     else
-        m_wrapper = (PyObject*)m_interpreter->CreateSyntheticScriptedProvider(m_python_class, m_backend);
+        m_wrapper = m_interpreter->CreateSyntheticScriptedProvider(m_python_class, m_backend);
+}
+
+SyntheticScriptProvider::FrontEnd::~FrontEnd()
+{
+  Py_XDECREF((PyObject*)m_wrapper);
 }
 
 lldb::ValueObjectSP

Modified: lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp?rev=142754&r1=142753&r2=142754&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp (original)
+++ lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp Sun Oct 23 11:49:03 2011
@@ -8,8 +8,13 @@
 //===----------------------------------------------------------------------===//
 
 // In order to guarantee correct working with Python, Python.h *MUST* be
-// the *FIRST* header file included in ScriptInterpreterPython.h, and that
-// must be the *FIRST* header file included here.
+// the *FIRST* header file included here.
+
+#if defined (__APPLE__)
+#include <Python/Python.h>
+#else
+#include <Python.h>
+#endif
 
 #include "lldb/Interpreter/ScriptInterpreterPython.h"
 
@@ -242,11 +247,11 @@
         {
             while (!GetPythonLock (1))
                 fprintf (tmp_fh, "Python interpreter locked on another thread; waiting to acquire lock...\n");
-            Py_DECREF (m_new_sysout);
+            Py_DECREF ((PyObject*)m_new_sysout);
             ReleasePythonLock ();
         }
         else
-            Py_DECREF (m_new_sysout);
+            Py_DECREF ((PyObject*)m_new_sysout);
     }
 }
 
@@ -358,7 +363,7 @@
     if ((m_new_sysout != NULL)
         && (sysmod != NULL)
         && (sysdict != NULL))
-            PyDict_SetItemString (sysdict, "stdout", m_new_sysout);
+            PyDict_SetItemString (sysdict, "stdout", (PyObject*)m_new_sysout);
             
     if (PyErr_Occurred())
         PyErr_Clear ();





More information about the lldb-commits mailing list