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
This commit is contained in:
@@ -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<PythonCallable>();
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user