From d1fd3ce42e817e9177b173f2830fb1ab595c6634 Mon Sep 17 00:00:00 2001 From: Enrico Granata Date: Wed, 1 Oct 2014 20:51:50 +0000 Subject: Add an accessor to PyCallable that allows one to determine the count of arguments that a Python function allows, and whether varargs/kwargs are also accepted by the same function llvm-svn: 218812 --- lldb/scripts/Python/python-wrapper.swig | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'lldb/scripts/Python/python-wrapper.swig') diff --git a/lldb/scripts/Python/python-wrapper.swig b/lldb/scripts/Python/python-wrapper.swig index c3812df..0c63824 100644 --- a/lldb/scripts/Python/python-wrapper.swig +++ b/lldb/scripts/Python/python-wrapper.swig @@ -105,7 +105,32 @@ FindSessionDictionary(const char *session_dictionary_name) class PyCallable { public: - + struct argc { + size_t num_args; + bool varargs : 1; + bool kwargs : 1; + }; + + argc + GetNumArguments () + { + if (m_callable && PyFunction_Check(m_callable)) + { + PyCodeObject* code = (PyCodeObject*)PyFunction_GET_CODE(m_callable); + if (code) + { + size_t args = code->co_argcount; + bool va=false,kw=false; + if ((code->co_flags & 4) == 4) + va = true; + if ((code->co_flags & 8) == 8) + kw = true; + return {args,va,kw}; + } + } + return {SIZE_MAX,false,false}; + } + operator bool () { -- cgit v1.1