diff options
author | Enrico Granata <egranata@apple.com> | 2014-10-01 20:51:50 +0000 |
---|---|---|
committer | Enrico Granata <egranata@apple.com> | 2014-10-01 20:51:50 +0000 |
commit | d1fd3ce42e817e9177b173f2830fb1ab595c6634 (patch) | |
tree | 41feb4f90b29cf0587a5e884848962da56d303b9 /lldb/scripts/Python/python-wrapper.swig | |
parent | b4b09c7a6c90c665def61033a3c2c34d10c7d2ba (diff) | |
download | bcm5719-llvm-d1fd3ce42e817e9177b173f2830fb1ab595c6634.tar.gz bcm5719-llvm-d1fd3ce42e817e9177b173f2830fb1ab595c6634.zip |
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
Diffstat (limited to 'lldb/scripts/Python/python-wrapper.swig')
-rw-r--r-- | lldb/scripts/Python/python-wrapper.swig | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/lldb/scripts/Python/python-wrapper.swig b/lldb/scripts/Python/python-wrapper.swig index c3812df8110..0c6382482c3 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 () { |