summaryrefslogtreecommitdiffstats
path: root/lldb/source/Plugins/ScriptInterpreter/Python
diff options
context:
space:
mode:
Diffstat (limited to 'lldb/source/Plugins/ScriptInterpreter/Python')
-rw-r--r--lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp30
-rw-r--r--lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h34
2 files changed, 49 insertions, 15 deletions
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
index 0c5ba7d343a..abcf71b8663 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
@@ -904,31 +904,35 @@ PythonCallable::Reset(PyRefType type, PyObject *py_obj)
}
-void
-PythonCallable::GetNumArguments(size_t &num_args, bool &has_varargs, bool &has_kwargs) const
+PythonCallable::ArgInfo
+PythonCallable::GetNumArguments() const
{
- num_args = 0;
- has_varargs = false;
- has_kwargs = false;
+ ArgInfo result = { 0, false, false };
if (!IsValid())
- return;
+ return result;
PyObject *py_func_obj = m_py_obj;
if (PyMethod_Check(py_func_obj))
py_func_obj = PyMethod_GET_FUNCTION(py_func_obj);
if (!py_func_obj)
- return;
+ return result;
PyCodeObject* code = (PyCodeObject*)PyFunction_GET_CODE(py_func_obj);
if (!code)
- return;
+ return result;
- num_args = code->co_argcount;
- if (code->co_flags & CO_VARARGS)
- has_varargs = true;
- if (code->co_flags & CO_VARKEYWORDS)
- has_kwargs = true;
+ result.count = code->co_argcount;
+ result.has_varargs = !!(code->co_flags & CO_VARARGS);
+ result.has_kwargs = !!(code->co_flags & CO_VARKEYWORDS);
+ return result;
+}
+
+PythonObject
+PythonCallable::operator ()()
+{
+ return PythonObject(PyRefType::Owned,
+ PyObject_CallObject(m_py_obj, nullptr));
}
PythonObject
diff --git a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
index 22c86fd4c35..3794cc04a65 100644
--- a/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
+++ b/lldb/source/Plugins/ScriptInterpreter/Python/PythonDataObjects.h
@@ -207,9 +207,23 @@ public:
static PythonObject
ResolveNameWithDictionary(llvm::StringRef name, PythonDictionary dict);
+ template<typename T>
+ static T
+ ResolveNameWithDictionary(llvm::StringRef name, PythonDictionary dict)
+ {
+ return ResolveNameWithDictionary(name, dict).AsType<T>();
+ }
+
PythonObject
ResolveName(llvm::StringRef name) const;
+ template<typename T>
+ T
+ ResolveName(llvm::StringRef name) const
+ {
+ return ResolveName(name).AsType<T>();
+ }
+
bool
HasAttribute(llvm::StringRef attribute) const;
@@ -410,6 +424,12 @@ class PythonModule : public PythonObject
class PythonCallable : public PythonObject
{
public:
+ struct ArgInfo {
+ size_t count;
+ bool has_varargs : 1;
+ bool has_kwargs : 1;
+ };
+
PythonCallable();
PythonCallable(PyRefType type, PyObject *o);
PythonCallable(const PythonCallable &dict);
@@ -425,14 +445,24 @@ public:
void
Reset(PyRefType type, PyObject *py_obj) override;
- void
- GetNumArguments(size_t &num_args, bool &has_varargs, bool &has_kwargs) const;
+ ArgInfo
+ GetNumArguments() const;
+
+ PythonObject
+ operator ()();
PythonObject
operator ()(std::initializer_list<PyObject*> args);
PythonObject
operator ()(std::initializer_list<PythonObject> args);
+
+ template<typename Arg, typename... Args>
+ PythonObject
+ operator ()(const Arg &arg, Args... args)
+ {
+ return operator()({ arg, args... });
+ }
};
OpenPOWER on IntegriCloud