summaryrefslogtreecommitdiffstats
path: root/lldb/scripts/Python/python-wrapper.swig
diff options
context:
space:
mode:
authorSiva Chandra <sivachandra@google.com>2015-10-21 19:28:08 +0000
committerSiva Chandra <sivachandra@google.com>2015-10-21 19:28:08 +0000
commit9ac7a6c51f8643e8a44af41efca0c8c148315bc5 (patch)
tree1f324c41d38d5d3bda6279345a245865e17b3506 /lldb/scripts/Python/python-wrapper.swig
parentc8a8a5e2aeb82403fd93053bef0124d3e82f186e (diff)
downloadbcm5719-llvm-9ac7a6c51f8643e8a44af41efca0c8c148315bc5.tar.gz
bcm5719-llvm-9ac7a6c51f8643e8a44af41efca0c8c148315bc5.zip
[SBValue] Add a method GetNumChildren(uint32_t max)
Summary: Along with this, support for an optional argument to the "num_children" method of a Python synthetic child provider has also been added. These have been added with the following use case in mind: Synthetic child providers currently have a method "has_children" and "num_children". While the former is good enough to know if there are children, it does not give any insight into how many children there are. Though the latter serves this purpose, calculating the number for children of a data structure could be an O(N) operation if the data structure has N children. The new method added in this change provide a middle ground. One can call GetNumChildren(K) to know if a child exists at an index K which can be as large as the callers tolerance can be. If the caller wants to know about children beyond K, it can make an other call with 2K. If the synthetic child provider maintains state about it counting till K previosly, then the next call is only an O(K) operation. Infact, all calls made progressively with steps of K will be O(K) operations. Reviewers: vharron, clayborg, granata.enrico Subscribers: labath, lldb-commits Differential Revision: http://reviews.llvm.org/D13778 llvm-svn: 250930
Diffstat (limited to 'lldb/scripts/Python/python-wrapper.swig')
-rw-r--r--lldb/scripts/Python/python-wrapper.swig33
1 files changed, 27 insertions, 6 deletions
diff --git a/lldb/scripts/Python/python-wrapper.swig b/lldb/scripts/Python/python-wrapper.swig
index a4d982609cb..a2ea16abdab 100644
--- a/lldb/scripts/Python/python-wrapper.swig
+++ b/lldb/scripts/Python/python-wrapper.swig
@@ -113,9 +113,18 @@ public:
argc
GetNumArguments ()
{
- if (m_callable && PyFunction_Check(m_callable))
+ PyObject *py_func_obj = NULL;
+ if (m_callable)
{
- PyCodeObject* code = (PyCodeObject*)PyFunction_GET_CODE(m_callable);
+ if (PyMethod_Check(m_callable))
+ py_func_obj = PyMethod_GET_FUNCTION(m_callable);
+ else
+ py_func_obj = m_callable;
+ }
+
+ if (py_func_obj)
+ {
+ PyCodeObject* code = (PyCodeObject*)PyFunction_GET_CODE(py_func_obj);
if (code)
{
size_t args = code->co_argcount;
@@ -632,15 +641,24 @@ LLDBSwigPython_CallOptionalMember
SWIGEXPORT size_t
LLDBSwigPython_CalculateNumChildren
(
- PyObject *implementor
+ PyObject *implementor,
+ uint32_t max
)
{
- size_t ret_val = UINT32_MAX;
+ size_t ret_val = 0;
bool int_match = false;
- static char callee_name[] = "num_children";
+ PyCallable pfunc = PyCallable::FindWithMemberFunction(implementor, "num_children");
- PyObject* py_return = LLDBSwigPython_CallOptionalMember(implementor,callee_name, NULL);
+ if (!pfunc)
+ return ret_val;
+
+ PyObject* py_return = NULL;
+ auto argc = pfunc.GetNumArguments();
+ if (argc.num_args == 1)
+ py_return = pfunc();
+ else if (argc.num_args == 2)
+ py_return = pfunc(max);
if (!py_return)
return ret_val;
@@ -675,6 +693,9 @@ LLDBSwigPython_CalculateNumChildren
PyErr_Clear();
}
+ if (argc.num_args == 1 && ret_val > max)
+ ret_val = max;
+
return ret_val;
}
OpenPOWER on IntegriCloud