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
This commit is contained in:
Enrico Granata committed 2014-10-01 20:51:50 +00:00
1 parent b4b09c7a6c
commit d1fd3ce42e
1 file changed
+26 -1
+26 -1
View File
@@ -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 ()
{