From a5d6765cb04214b10b5b5b550e554c5411c03b43 Mon Sep 17 00:00:00 2001 From: Enrico Granata Date: Fri, 24 Jun 2016 02:07:15 +0000 Subject: Fix an issue where the @lldb.command marker would not work with the new 5-argument version of the Python command function This: a) teaches PythonCallable to look inside a callable object b) teaches PythonCallable to discover whether a callable method is bound c) teaches lldb.command to dispatch to either the older 4 argument version or the newer 5 argument version llvm-svn: 273640 --- .../ScriptInterpreter/Python/PythonDataObjects.cpp | 26 +++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp') diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp index 02228df5147..1fdf4c70a5d 100644 --- a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp +++ b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp @@ -1109,13 +1109,37 @@ PythonCallable::Reset(PyRefType type, PyObject *py_obj) PythonCallable::ArgInfo PythonCallable::GetNumArguments() const { - ArgInfo result = { 0, false, false }; + ArgInfo result = { 0, false, false, false }; if (!IsValid()) return result; PyObject *py_func_obj = m_py_obj; if (PyMethod_Check(py_func_obj)) + { py_func_obj = PyMethod_GET_FUNCTION(py_func_obj); + PythonObject im_self = GetAttributeValue("im_self"); + if (im_self.IsValid() && !im_self.IsNone()) + result.is_bound_method = true; + } + else + { + // see if this is a callable object with an __call__ method + if (!PyFunction_Check(py_func_obj)) + { + PythonObject __call__ = GetAttributeValue("__call__"); + if (__call__.IsValid()) + { + auto __callable__ = __call__.AsType(); + if (__callable__.IsValid()) + { + py_func_obj = PyMethod_GET_FUNCTION(__callable__.get()); + PythonObject im_self = GetAttributeValue("im_self"); + if (im_self.IsValid() && !im_self.IsNone()) + result.is_bound_method = true; + } + } + } + } if (!py_func_obj) return result; -- cgit v1.2.3