[Lldb-commits] [lldb] r252803 - Remove `FindSessionDictionary` and rely on PythonDataObjects.

Zachary Turner via lldb-commits lldb-commits at lists.llvm.org
Wed Nov 11 13:07:30 PST 2015


Author: zturner
Date: Wed Nov 11 15:07:29 2015
New Revision: 252803

URL: http://llvm.org/viewvc/llvm-project?rev=252803&view=rev
Log:
Remove `FindSessionDictionary` and rely on PythonDataObjects.

This had been relegated to a simple forwarding function, so just
delete it in preparation of migrating all of these functions out
of python-wrapper.swig.

Modified:
    lldb/trunk/scripts/Python/python-wrapper.swig

Modified: lldb/trunk/scripts/Python/python-wrapper.swig
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/Python/python-wrapper.swig?rev=252803&r1=252802&r2=252803&view=diff
==============================================================================
--- lldb/trunk/scripts/Python/python-wrapper.swig (original)
+++ lldb/trunk/scripts/Python/python-wrapper.swig Wed Nov 11 15:07:29 2015
@@ -26,13 +26,6 @@ private:
     bool m_print;
 };
 
-static PyObject*
-FindSessionDictionary(const char *dict_name)
-{
-    using namespace lldb_private;
-    return PythonModule::MainModule().ResolveName(dict_name).release();
-}
-
 // TODO(zturner): This entire class should be moved to PythonDataObjects.h
 // and properly abstracted and unit-tested.
 class PyCallable
@@ -191,30 +184,27 @@ LLDBSwigPythonBreakpointCallbackFunction
     const lldb::BreakpointLocationSP& bp_loc_sp
 )
 {
+    using namespace lldb_private;
     lldb::SBFrame sb_frame (frame_sp);
     lldb::SBBreakpointLocation sb_bp_loc(bp_loc_sp);
 
     bool stop_at_breakpoint = true;
 
-    {
-        PyErr_Cleaner py_err_cleaner(true);
-
-        PyCallable pfunc = PyCallable::FindWithFunctionName(python_function_name,session_dictionary_name);
+    PyErr_Cleaner py_err_cleaner(true);
+    PythonDictionary dict = PythonModule::MainModule().ResolveName(session_dictionary_name).AsType<PythonDictionary>();
 
-        if (!pfunc)
-            return stop_at_breakpoint;
+    PyCallable pfunc = PyCallable::FindWithFunctionName(python_function_name,dict.get());
 
-        PyObject* session_dict = NULL;
-        PyObject* pvalue = NULL;
-        pvalue = pfunc(sb_frame, sb_bp_loc, session_dict = FindSessionDictionary(session_dictionary_name));
+    if (!pfunc)
+        return stop_at_breakpoint;
 
-        Py_XINCREF (session_dict);
+    PyObject* pvalue = NULL;
+    pvalue = pfunc(sb_frame, sb_bp_loc, dict.get());
 
-        if (pvalue == Py_False)
-            stop_at_breakpoint = false;
+    if (pvalue == Py_False)
+        stop_at_breakpoint = false;
 
-        Py_XDECREF (pvalue);
-    }
+    Py_XDECREF (pvalue);
 
     return stop_at_breakpoint;
 }
@@ -231,30 +221,28 @@ LLDBSwigPythonWatchpointCallbackFunction
     const lldb::WatchpointSP& wp_sp
 )
 {
+    using namespace lldb_private;
     lldb::SBFrame sb_frame (frame_sp);
     lldb::SBWatchpoint sb_wp(wp_sp);
 
     bool stop_at_watchpoint = true;
 
-    {
-        PyErr_Cleaner py_err_cleaner(true);
+    PyErr_Cleaner py_err_cleaner(true);
 
-        PyCallable pfunc = PyCallable::FindWithFunctionName(python_function_name,session_dictionary_name);
+    PythonDictionary dict = PythonModule::MainModule().ResolveName(session_dictionary_name).AsType<PythonDictionary>();
 
-        if (!pfunc)
-            return stop_at_watchpoint;
+    PyCallable pfunc = PyCallable::FindWithFunctionName(python_function_name,dict.get());
 
-        PyObject* session_dict = NULL;
-        PyObject* pvalue = NULL;
-        pvalue = pfunc(sb_frame, sb_wp, session_dict = FindSessionDictionary(session_dictionary_name));
+    if (!pfunc)
+        return stop_at_watchpoint;
 
-        Py_XINCREF (session_dict);
+    PyObject* pvalue = NULL;
+    pvalue = pfunc(sb_frame, sb_wp, dict.get());
 
-        if (pvalue == Py_False)
-            stop_at_watchpoint = false;
+    if (pvalue == Py_False)
+        stop_at_watchpoint = false;
 
-        Py_XDECREF (pvalue);
-    }
+    Py_XDECREF (pvalue);
 
     return stop_at_watchpoint;
 }
@@ -364,6 +352,7 @@ LLDBSwigPythonCreateSyntheticProvider
     const lldb::ValueObjectSP& valobj_sp
 )
 {
+    using namespace lldb_private;
     PyObject* retval = NULL;
 
     if (python_class_name == NULL || python_class_name[0] == '\0' || !session_dictionary_name)
@@ -378,24 +367,19 @@ LLDBSwigPythonCreateSyntheticProvider
     if (ValObj_PyObj == NULL)
         Py_RETURN_NONE;
 
-    {
-        PyErr_Cleaner py_err_cleaner(true);
+    PyErr_Cleaner py_err_cleaner(true);
 
-        PyCallable pfunc = PyCallable::FindWithFunctionName(python_class_name,session_dictionary_name);
+    PythonDictionary dict = PythonModule::MainModule().ResolveName(session_dictionary_name).AsType<PythonDictionary>();
+    PyCallable pfunc = PyCallable::FindWithFunctionName(python_class_name,dict.get());
 
-        if (!pfunc)
-            return retval;
+    if (!pfunc)
+        return retval;
 
-        Py_INCREF(ValObj_PyObj);
+    Py_INCREF(ValObj_PyObj);
 
-        PyObject* session_dict = NULL;
-        session_dict = FindSessionDictionary(session_dictionary_name);
-        retval = pfunc(sb_value, session_dict);
+    retval = pfunc(sb_value, dict.get());
 
-        Py_XINCREF (session_dict);
-
-        Py_XINCREF(retval);
-    }
+    Py_XINCREF(retval);
 
     if (retval)
         return retval;
@@ -411,6 +395,7 @@ LLDBSwigPythonCreateCommandObject
     const lldb::DebuggerSP debugger_sp
 )
 {
+    using namespace lldb_private;
     PyObject* retval = NULL;
 
     if (python_class_name == NULL || python_class_name[0] == '\0' || !session_dictionary_name)
@@ -418,22 +403,16 @@ LLDBSwigPythonCreateCommandObject
 
     lldb::SBDebugger debugger_sb(debugger_sp);
 
-    {
-        PyErr_Cleaner py_err_cleaner(true);
-
-        PyCallable pfunc = PyCallable::FindWithFunctionName(python_class_name,session_dictionary_name);
-
-        if (!pfunc)
-            return retval;
+    PyErr_Cleaner py_err_cleaner(true);
+    PythonDictionary dict = PythonModule::MainModule().ResolveName(session_dictionary_name).AsType<PythonDictionary>();
+    PyCallable pfunc = PyCallable::FindWithFunctionName(python_class_name,dict.get());
 
-        PyObject* session_dict = NULL;
-        session_dict = FindSessionDictionary(session_dictionary_name);
-        retval = pfunc(debugger_sb, session_dict);
+    if (!pfunc)
+        return retval;
 
-        Py_XINCREF (session_dict);
+    retval = pfunc(debugger_sb, dict.get());
 
-        Py_XINCREF(retval);
-    }
+    Py_XINCREF(retval);
 
     if (retval)
         return retval;
@@ -449,6 +428,7 @@ LLDBSwigPythonCreateScriptedThreadPlan
     const lldb::ThreadPlanSP& thread_plan_sp
 )
 {
+    using namespace lldb_private;
     PyObject* retval = NULL;
 
     if (python_class_name == NULL || python_class_name[0] == '\0' || !session_dictionary_name)
@@ -463,27 +443,22 @@ LLDBSwigPythonCreateScriptedThreadPlan
     if (ThreadPlan_PyObj == NULL)
         Py_RETURN_NONE;
 
-    {
-        PyErr_Cleaner py_err_cleaner(true);
-
-        PyCallable pfunc = PyCallable::FindWithFunctionName(python_class_name, session_dictionary_name);
+    PyErr_Cleaner py_err_cleaner(true);
 
-        if (!pfunc)
-            return retval;
+    PythonDictionary dict = PythonModule::MainModule().ResolveName(session_dictionary_name).AsType<PythonDictionary>();
+    PyCallable pfunc = PyCallable::FindWithFunctionName(python_class_name, dict.get());
 
-        Py_INCREF(ThreadPlan_PyObj);
+    if (!pfunc)
+        return retval;
 
-        PyObject* session_dict = NULL;
-        session_dict = FindSessionDictionary(session_dictionary_name);
-        retval = pfunc(tp_value, session_dict);
+    Py_INCREF(ThreadPlan_PyObj);
 
-        // FIXME: At this point we should check that the class we found supports all the methods
-        // that we need.
+    retval = pfunc(tp_value, dict.get());
 
-        Py_XINCREF (session_dict);
+    // FIXME: At this point we should check that the class we found supports all the methods
+    // that we need.
 
-        Py_XINCREF(retval);
-    }
+    Py_XINCREF(retval);
 
     if (retval)
         return retval;
@@ -831,7 +806,7 @@ LLDBSwigPythonCallCommand
     lldb::ExecutionContextRefSP exe_ctx_ref_sp
 )
 {
-
+    using namespace lldb_private;
     lldb::SBCommandReturnObject cmd_retobj_sb(&cmd_retobj);
     SBCommandReturnObjectReleaser cmd_retobj_sb_releaser(cmd_retobj_sb);
     lldb::SBDebugger debugger_sb(debugger);
@@ -839,29 +814,26 @@ LLDBSwigPythonCallCommand
 
     bool retval = false;
 
-    {
-        PyErr_Cleaner py_err_cleaner(true);
-        PyCallable pfunc = PyCallable::FindWithFunctionName(python_function_name,session_dictionary_name);
+    PyErr_Cleaner py_err_cleaner(true);
+    PythonDictionary dict = PythonModule::MainModule().ResolveName(session_dictionary_name).AsType<PythonDictionary>();
+    PyCallable pfunc = PyCallable::FindWithFunctionName(python_function_name,dict.get());
 
-        if (!pfunc)
-            return retval;
+    if (!pfunc)
+        return retval;
 
-        PyObject* session_dict = NULL;
-        // pass the pointer-to cmd_retobj_sb or watch the underlying object disappear from under you
-        // see comment above for SBCommandReturnObjectReleaser for further details
-        PyObject* pvalue = NULL;
-
-        PyCallable::argc argc = pfunc.GetNumArguments();
-        if (argc.num_args == 5 || argc.varargs == true)
-            pvalue = pfunc(debugger_sb, args, exe_ctx_sb, &cmd_retobj_sb, session_dict = FindSessionDictionary(session_dictionary_name));
-        else
-            pvalue = pfunc(debugger_sb, args, &cmd_retobj_sb, session_dict = FindSessionDictionary(session_dictionary_name));
+    // pass the pointer-to cmd_retobj_sb or watch the underlying object disappear from under you
+    // see comment above for SBCommandReturnObjectReleaser for further details
+    PyObject* pvalue = NULL;
 
-        Py_XINCREF (session_dict);
-        Py_XDECREF (pvalue);
+    PyCallable::argc argc = pfunc.GetNumArguments();
+    if (argc.num_args == 5 || argc.varargs == true)
+        pvalue = pfunc(debugger_sb, args, exe_ctx_sb, &cmd_retobj_sb, dict.get());
+    else
+        pvalue = pfunc(debugger_sb, args, &cmd_retobj_sb, dict.get());
 
-        retval = true;
-    }
+    Py_XDECREF (pvalue);
+
+    retval = true;
 
     return retval;
 }
@@ -908,6 +880,7 @@ LLDBSWIGPythonCreateOSPlugin
     const lldb::ProcessSP& process_sp
 )
 {
+    using namespace lldb_private;
     PyObject* retval = NULL;
 
     if (python_class_name == NULL || python_class_name[0] == '\0' || !session_dictionary_name)
@@ -922,24 +895,19 @@ LLDBSWIGPythonCreateOSPlugin
     if (SBProc_PyObj == NULL)
         Py_RETURN_NONE;
 
-    {
-        PyErr_Cleaner py_err_cleaner(true);
-
-        PyCallable pfunc = PyCallable::FindWithFunctionName(python_class_name,session_dictionary_name);
+    PyErr_Cleaner py_err_cleaner(true);
 
-        if (!pfunc)
-            return retval;
+    PythonDictionary dict = PythonModule::MainModule().ResolveName(session_dictionary_name).AsType<PythonDictionary>();
+    PyCallable pfunc = PyCallable::FindWithFunctionName(python_class_name,dict.get());
 
-        Py_INCREF(SBProc_PyObj);
+    if (!pfunc)
+        return retval;
 
-        PyObject* session_dict = NULL;
-        session_dict = session_dict = FindSessionDictionary(session_dictionary_name);
-        retval = pfunc(SBProc_PyObj);
+    Py_INCREF(SBProc_PyObj);
 
-        Py_XINCREF (session_dict);
+    retval = pfunc(SBProc_PyObj);
 
-        Py_XINCREF(retval);
-    }
+    Py_XINCREF(retval);
 
     if (retval)
         return retval;
@@ -979,6 +947,7 @@ lldb::ProcessSP& process,
 std::string& output)
 
 {
+    using namespace lldb_private;
     bool retval = false;
 
     if (python_function_name == NULL || python_function_name[0] == '\0' || !session_dictionary_name)
@@ -986,25 +955,21 @@ std::string& output)
 
     lldb::SBProcess process_sb(process);
 
-    {
-        PyErr_Cleaner py_err_cleaner(true);
-
-        PyCallable pfunc = PyCallable::FindWithFunctionName(python_function_name,session_dictionary_name);
+    PyErr_Cleaner py_err_cleaner(true);
 
-        if (!pfunc)
-            return retval;
+    PythonDictionary dict = PythonModule::MainModule().ResolveName(session_dictionary_name).AsType<PythonDictionary>();
+    PyCallable pfunc = PyCallable::FindWithFunctionName(python_function_name,dict.get());
 
-        PyObject* session_dict = NULL;
-        PyObject* pvalue = NULL;
-        pvalue = pfunc(process_sb, session_dict = FindSessionDictionary(session_dictionary_name));
+    if (!pfunc)
+        return retval;
 
-        Py_XINCREF (session_dict);
+    PyObject* pvalue = NULL;
+    pvalue = pfunc(process_sb, dict.get());
 
-        if (PyObjectToString(pvalue,output))
-            retval = true;
+    if (PyObjectToString(pvalue,output))
+        retval = true;
 
-        Py_XDECREF(pvalue);
-    }
+    Py_XDECREF(pvalue);
 
     return retval;
 }
@@ -1017,6 +982,7 @@ lldb::ThreadSP& thread,
 std::string& output)
 
 {
+    using namespace lldb_private;
     bool retval = false;
 
     if (python_function_name == NULL || python_function_name[0] == '\0' || !session_dictionary_name)
@@ -1024,25 +990,21 @@ std::string& output)
 
     lldb::SBThread thread_sb(thread);
 
-    {
-        PyErr_Cleaner py_err_cleaner(true);
-
-        PyCallable pfunc = PyCallable::FindWithFunctionName(python_function_name,session_dictionary_name);
+    PyErr_Cleaner py_err_cleaner(true);
 
-        if (!pfunc)
-            return retval;
+    PythonDictionary dict = PythonModule::MainModule().ResolveName(session_dictionary_name).AsType<PythonDictionary>();
+    PyCallable pfunc = PyCallable::FindWithFunctionName(python_function_name,dict.get());
 
-        PyObject* session_dict = NULL;
-        PyObject* pvalue = NULL;
-        pvalue = pfunc(thread_sb, session_dict = FindSessionDictionary(session_dictionary_name));
+    if (!pfunc)
+        return retval;
 
-        Py_XINCREF (session_dict);
+    PyObject* pvalue = NULL;
+    pvalue = pfunc(thread_sb, dict.get());
 
-        if (PyObjectToString(pvalue,output))
-            retval = true;
+    if (PyObjectToString(pvalue,output))
+        retval = true;
 
-        Py_XDECREF(pvalue);
-    }
+    Py_XDECREF(pvalue);
 
     return retval;
 }
@@ -1055,6 +1017,7 @@ lldb::TargetSP& target,
 std::string& output)
 
 {
+    using namespace lldb_private;
     bool retval = false;
 
     if (python_function_name == NULL || python_function_name[0] == '\0' || !session_dictionary_name)
@@ -1062,25 +1025,21 @@ std::string& output)
 
     lldb::SBTarget target_sb(target);
 
-    {
-        PyErr_Cleaner py_err_cleaner(true);
+    PyErr_Cleaner py_err_cleaner(true);
 
-        PyCallable pfunc = PyCallable::FindWithFunctionName(python_function_name,session_dictionary_name);
+    PythonDictionary dict = PythonModule::MainModule().ResolveName(session_dictionary_name).AsType<PythonDictionary>();
+    PyCallable pfunc = PyCallable::FindWithFunctionName(python_function_name,dict.get());
 
-        if (!pfunc)
-            return retval;
-
-        PyObject* session_dict = NULL;
-        PyObject* pvalue = NULL;
-        pvalue = pfunc(target_sb, session_dict = FindSessionDictionary(session_dictionary_name));
+    if (!pfunc)
+        return retval;
 
-        Py_XINCREF (session_dict);
+    PyObject* pvalue = NULL;
+    pvalue = pfunc(target_sb, dict.get());
 
-        if (PyObjectToString(pvalue,output))
-            retval = true;
+    if (PyObjectToString(pvalue,output))
+        retval = true;
 
-        Py_XDECREF(pvalue);
-    }
+    Py_XDECREF(pvalue);
 
     return retval;
 }
@@ -1093,6 +1052,7 @@ lldb::StackFrameSP& frame,
 std::string& output)
 
 {
+    using namespace lldb_private;
     bool retval = false;
 
     if (python_function_name == NULL || python_function_name[0] == '\0' || !session_dictionary_name)
@@ -1100,25 +1060,21 @@ std::string& output)
 
     lldb::SBFrame frame_sb(frame);
 
-    {
-        PyErr_Cleaner py_err_cleaner(true);
-
-        PyCallable pfunc = PyCallable::FindWithFunctionName(python_function_name,session_dictionary_name);
+    PyErr_Cleaner py_err_cleaner(true);
 
-        if (!pfunc)
-            return retval;
+    PythonDictionary dict = PythonModule::MainModule().ResolveName(session_dictionary_name).AsType<PythonDictionary>();
+    PyCallable pfunc = PyCallable::FindWithFunctionName(python_function_name,dict.get());
 
-        PyObject* session_dict = NULL;
-        PyObject* pvalue = NULL;
-        pvalue = pfunc(frame_sb, session_dict = FindSessionDictionary(session_dictionary_name));
+    if (!pfunc)
+        return retval;
 
-        Py_XINCREF (session_dict);
+    PyObject* pvalue = NULL;
+    pvalue = pfunc(frame_sb, dict.get());
 
-        if (PyObjectToString(pvalue,output))
-            retval = true;
+    if (PyObjectToString(pvalue,output))
+        retval = true;
 
-        Py_XDECREF(pvalue);
-    }
+    Py_XDECREF(pvalue);
 
     return retval;
 }
@@ -1131,6 +1087,7 @@ lldb::ValueObjectSP& value,
 std::string& output)
 
 {
+    using namespace lldb_private;
     bool retval = false;
 
     if (python_function_name == NULL || python_function_name[0] == '\0' || !session_dictionary_name)
@@ -1138,25 +1095,21 @@ std::string& output)
 
     lldb::SBValue value_sb(value);
 
-    {
-        PyErr_Cleaner py_err_cleaner(true);
-
-        PyCallable pfunc = PyCallable::FindWithFunctionName(python_function_name,session_dictionary_name);
+    PyErr_Cleaner py_err_cleaner(true);
 
-        if (!pfunc)
-            return retval;
+    PythonDictionary dict = PythonModule::MainModule().ResolveName(session_dictionary_name).AsType<PythonDictionary>();
+    PyCallable pfunc = PyCallable::FindWithFunctionName(python_function_name,dict.get());
 
-        PyObject* session_dict = NULL;
-        PyObject* pvalue = NULL;
-        pvalue = pfunc(value_sb, session_dict = FindSessionDictionary(session_dictionary_name));
+    if (!pfunc)
+        return retval;
 
-        Py_XINCREF (session_dict);
+    PyObject* pvalue = NULL;
+    pvalue = pfunc(value_sb, dict.get());
 
-        if (PyObjectToString(pvalue,output))
-            retval = true;
+    if (PyObjectToString(pvalue,output))
+        retval = true;
 
-        Py_XDECREF(pvalue);
-    }
+    Py_XDECREF(pvalue);
 
     return retval;
 }
@@ -1169,6 +1122,7 @@ LLDBSwigPythonCallModuleInit
     lldb::DebuggerSP& debugger
 )
 {
+    using namespace lldb_private;
     bool retval = false;
 
     lldb::SBDebugger debugger_sb(debugger);
@@ -1177,24 +1131,20 @@ LLDBSwigPythonCallModuleInit
     python_function_name_string += ".__lldb_init_module";
     const char* python_function_name = python_function_name_string.c_str();
 
-    {
-        PyErr_Cleaner py_err_cleaner(true);
+    PyErr_Cleaner py_err_cleaner(true);
 
-        PyCallable pfunc = PyCallable::FindWithFunctionName(python_function_name,session_dictionary_name);
+    PythonDictionary dict = PythonModule::MainModule().ResolveName(session_dictionary_name).AsType<PythonDictionary>();
+    PyCallable pfunc = PyCallable::FindWithFunctionName(python_function_name,dict.get());
 
-        if (!pfunc)
-            return true;
-
-        PyObject* session_dict = NULL;
-        PyObject* pvalue = NULL;
-        pvalue = pfunc(debugger_sb, session_dict = FindSessionDictionary(session_dictionary_name));
+    if (!pfunc)
+        return true;
 
-        Py_XINCREF (session_dict);
+    PyObject* pvalue = NULL;
+    pvalue = pfunc(debugger_sb, dict.get());
 
-        retval = true;
+    retval = true;
 
-        Py_XDECREF(pvalue);
-    }
+    Py_XDECREF(pvalue);
 
     return retval;
 }




More information about the lldb-commits mailing list