[Lldb-commits] [lldb] r138154 - in /lldb/trunk: include/lldb/API/SBDebugger.h include/lldb/Interpreter/ScriptInterpreter.h scripts/Python/python-wrapper.swig source/API/SBCommandInterpreter.cpp source/API/SBDebugger.cpp source/Interpreter/ScriptInterpreterPython.cpp

Enrico Granata granata.enrico at gmail.com
Fri Aug 19 16:56:34 PDT 2011


Author: enrico
Date: Fri Aug 19 18:56:34 2011
New Revision: 138154

URL: http://llvm.org/viewvc/llvm-project?rev=138154&view=rev
Log:
Fixed some SWIG interoperability issues

Modified:
    lldb/trunk/include/lldb/API/SBDebugger.h
    lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h
    lldb/trunk/scripts/Python/python-wrapper.swig
    lldb/trunk/source/API/SBCommandInterpreter.cpp
    lldb/trunk/source/API/SBDebugger.cpp
    lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp

Modified: lldb/trunk/include/lldb/API/SBDebugger.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBDebugger.h?rev=138154&r1=138153&r2=138154&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBDebugger.h (original)
+++ lldb/trunk/include/lldb/API/SBDebugger.h Fri Aug 19 18:56:34 2011
@@ -40,6 +40,8 @@
     SBDebugger(const lldb::SBDebugger &rhs);
 
 #ifndef SWIG
+    SBDebugger(const lldb::DebuggerSP &debugger_sp);
+    
     lldb::SBDebugger &
     operator = (const lldb::SBDebugger &rhs);
 #endif

Modified: lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h?rev=138154&r1=138153&r2=138154&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h (original)
+++ lldb/trunk/include/lldb/Interpreter/ScriptInterpreter.h Fri Aug 19 18:56:34 2011
@@ -49,7 +49,7 @@
                                                                      lldb::DebuggerSP& debugger,
                                                                      const char* args,
                                                                      std::string& err_msg,
-                                                                     void* cmd_retobj);
+                                                                     lldb_private::CommandReturnObject& cmd_retobj);
 
     typedef enum
     {

Modified: lldb/trunk/scripts/Python/python-wrapper.swig
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/python-wrapper.swig?rev=138154&r1=138153&r2=138154&view=diff
==============================================================================
--- lldb/trunk/scripts/Python/python-wrapper.swig (original)
+++ lldb/trunk/scripts/Python/python-wrapper.swig Fri Aug 19 18:56:34 2011
@@ -136,7 +136,7 @@
 
     std::string retval = "";
 
-    PyObject *ValObj_PyObj = SWIG_NewPointerObj((void *) &valobj_sp, SWIGTYPE_p_lldb__SBValue, 0);
+    PyObject *ValObj_PyObj = SWIG_NewPointerObj((void *) &sb_value, SWIGTYPE_p_lldb__SBValue, 0);
     
     if (ValObj_PyObj == NULL)
         return retval;
@@ -263,9 +263,11 @@
     if (python_class_name.empty() || !session_dictionary_name)
         Py_RETURN_NONE;
 
-    lldb::ValueObjectSP* valobj_sp_ptr = new lldb::ValueObjectSP(valobj_sp);
+    // I do not want the SBValue to be deallocated when going out of scope because python
+    // has ownership of it and will manage memory for this object by itself
+    lldb::SBValue *valobj_sb = new lldb::SBValue(valobj_sp);
 
-    PyObject *ValObj_PyObj = SWIG_NewPointerObj((void *) valobj_sp_ptr, SWIGTYPE_p_lldb__SBValue, SWIG_POINTER_OWN);
+    PyObject *ValObj_PyObj = SWIG_NewPointerObj((void *)valobj_sb, SWIGTYPE_p_lldb__SBValue, SWIG_POINTER_OWN);
 
     if (ValObj_PyObj == NULL)
         Py_RETURN_NONE;
@@ -582,6 +584,14 @@
     return sb_ptr;
 }
 
+// we use this macro to bail out of LLDBSwigPythonCallCommand in order
+// to make sure that the that the SBCommandReturnObject will not destroy
+// the contained CommandReturnObject when going out of scope
+#define RETURN_RETVAL { \
+    cmd_retobj_sb.Release(); \
+    return retval; \
+}
+
 SWIGEXPORT bool
 LLDBSwigPythonCallCommand 
 (
@@ -590,25 +600,26 @@
     lldb::DebuggerSP& debugger,
     const char* args,
     std::string& err_msg,
-    void* cmd_retobj
+    lldb_private::CommandReturnObject& cmd_retobj
 )
 {
 
-    not_owning_ap<lldb_private::CommandReturnObject> auto_cmd_retobj((lldb_private::CommandReturnObject*)cmd_retobj);
+    lldb::SBCommandReturnObject cmd_retobj_sb(&cmd_retobj);
+    lldb::SBDebugger debugger_sb(debugger);
 
     bool retval = false;
 
-    PyObject *DebuggerObj_PyObj = SWIG_NewPointerObj((void *) &debugger, SWIGTYPE_p_lldb__SBDebugger, 0);
-    PyObject *CmdRetObj_PyObj = SWIG_NewPointerObj((void *) &auto_cmd_retobj, SWIGTYPE_p_lldb__SBCommandReturnObject, 0);
+    PyObject *DebuggerObj_PyObj = SWIG_NewPointerObj((void *) &debugger_sb, SWIGTYPE_p_lldb__SBDebugger, 0);
+    PyObject *CmdRetObj_PyObj = SWIG_NewPointerObj((void *) &cmd_retobj_sb, SWIGTYPE_p_lldb__SBCommandReturnObject, 0);
 
     if (DebuggerObj_PyObj == NULL)
-        return retval;
+        RETURN_RETVAL;
         
     if (CmdRetObj_PyObj == NULL)
-        return retval;
+        RETURN_RETVAL;
 
     if (!python_function_name || !session_dictionary_name)
-        return retval;
+        RETURN_RETVAL;
 
     PyObject *pmodule, *main_dict, *session_dict, *pfunc;
     PyObject *pargs, *pvalue;
@@ -642,7 +653,7 @@
             }
             
             if (!session_dict || !PyDict_Check (session_dict))
-                return retval;
+                RETURN_RETVAL;
                 
             // Find the function we need to call in the current session's dictionary.
 
@@ -673,7 +684,7 @@
                 {
                     if (PyErr_Occurred())
                         PyErr_Clear();
-                    return retval;
+                    RETURN_RETVAL;
                 }
                 
                 PyTuple_SetItem (pargs, 0, DebuggerObj_PyObj);  // This "steals" a reference to DebuggerObj_PyObj
@@ -721,7 +732,9 @@
         PyErr_Print();
         PyErr_Clear ();
     }
-    return retval;
+    RETURN_RETVAL;
 }
 
+#undef RETURN_RETVAL
+
 %}

Modified: lldb/trunk/source/API/SBCommandInterpreter.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBCommandInterpreter.cpp?rev=138154&r1=138153&r2=138154&view=diff
==============================================================================
--- lldb/trunk/source/API/SBCommandInterpreter.cpp (original)
+++ lldb/trunk/source/API/SBCommandInterpreter.cpp Fri Aug 19 18:56:34 2011
@@ -344,7 +344,7 @@
     lldb::DebuggerSP& debugger,
     const char* args,
     std::string& err_msg,
-    void* cmd_retobj
+    lldb_private::CommandReturnObject& cmd_retobj
 );
 
 

Modified: lldb/trunk/source/API/SBDebugger.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBDebugger.cpp?rev=138154&r1=138153&r2=138154&view=diff
==============================================================================
--- lldb/trunk/source/API/SBDebugger.cpp (original)
+++ lldb/trunk/source/API/SBDebugger.cpp Fri Aug 19 18:56:34 2011
@@ -128,6 +128,11 @@
 {
 }
 
+SBDebugger::SBDebugger(const lldb::DebuggerSP &debugger_sp) :
+    m_opaque_sp(debugger_sp)
+{
+}
+
 SBDebugger::SBDebugger(const SBDebugger &rhs) :
     m_opaque_sp (rhs.m_opaque_sp)
 {

Modified: lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp?rev=138154&r1=138153&r2=138154&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp (original)
+++ lldb/trunk/source/Interpreter/ScriptInterpreterPython.cpp Fri Aug 19 18:56:34 2011
@@ -20,6 +20,7 @@
 
 #include "lldb/API/SBFrame.h"
 #include "lldb/API/SBBreakpointLocation.h"
+#include "lldb/API/SBCommandReturnObject.h"
 #include "lldb/Breakpoint/StoppointCallbackContext.h"
 #include "lldb/Core/Debugger.h"
 #include "lldb/Core/Timer.h"
@@ -1930,7 +1931,7 @@
     }
     
     ScriptInterpreterPython *python_interpreter = this;
-    
+
     lldb::DebuggerSP debugger_sp = m_interpreter.GetDebugger().GetSP();
     
     bool ret_val;
@@ -1946,7 +1947,7 @@
                                              debugger_sp,
                                              args,
                                              err_msg,
-                                             (void*)&cmd_retobj);
+                                             cmd_retobj);
         python_interpreter->LeaveSession ();
     }
     else
@@ -1960,7 +1961,7 @@
                                              debugger_sp,
                                              args,
                                              err_msg,
-                                             (void*)&cmd_retobj);
+                                             cmd_retobj);
         python_interpreter->LeaveSession ();
         ReleasePythonLock ();
     }
@@ -1969,7 +1970,7 @@
         error.SetErrorString(err_msg.c_str());
     else
         error.Clear();
-    
+        
     return ret_val;
 
     





More information about the lldb-commits mailing list