diff options
Diffstat (limited to 'lldb/scripts')
-rw-r--r-- | lldb/scripts/Python/python-wrapper.swig | 162 |
1 files changed, 97 insertions, 65 deletions
diff --git a/lldb/scripts/Python/python-wrapper.swig b/lldb/scripts/Python/python-wrapper.swig index a3aeefb1f77..199cc639cb2 100644 --- a/lldb/scripts/Python/python-wrapper.swig +++ b/lldb/scripts/Python/python-wrapper.swig @@ -418,46 +418,104 @@ LLDBSwigPythonCreateSyntheticProvider Py_RETURN_NONE; } -/* -these four calls below are meant to support -Python-based synthetic children providers -they essentially mimic the four pure virtual -method calls provided by the frontend class -*/ - -SWIGEXPORT uint32_t -LLDBSwigPython_CalculateNumChildren +// wrapper that calls an optional instance member of an object taking no arguments +static PyObject* +LLDBSwigPython_CallOptionalMember ( - PyObject *implementor + PyObject* self, + char* callee_name, + PyObject* ret_if_not_found = Py_None, + bool* was_found = NULL ) { + if (self == NULL || self == Py_None) + { + if (was_found) + *was_found = false; + Py_XINCREF(ret_if_not_found); + return ret_if_not_found; + } - static char callee_name[] = "num_children"; + PyObject* pmeth = PyObject_GetAttrString(self, callee_name); - if (implementor == NULL || implementor == Py_None) - return 0; - PyObject* py_return = PyObject_CallMethod(implementor, callee_name, NULL); if (PyErr_Occurred()) { - PyErr_Print(); PyErr_Clear(); } - if (py_return == NULL || py_return == Py_None) + if (pmeth == NULL || pmeth == Py_None) { - Py_XDECREF(py_return); - return UINT32_MAX; + if (was_found) + *was_found = false; + Py_XDECREF(pmeth); + Py_XINCREF(ret_if_not_found); + return ret_if_not_found; } - long retval = PyInt_AsLong(py_return); - Py_DECREF(py_return); - if (retval >= 0) - return (uint32_t)retval; + + if (PyCallable_Check(pmeth) == 0) + { + if (PyErr_Occurred()) + { + PyErr_Clear(); + } + + Py_XDECREF(pmeth); + if (was_found) + *was_found = false; + Py_XINCREF(ret_if_not_found); + return ret_if_not_found; + } + + if (was_found) + *was_found = true; + + if (PyErr_Occurred()) + { + PyErr_Clear(); + } + + Py_XDECREF(pmeth); + + // right now we know this function exists and is callable.. + PyObject* py_return = PyObject_CallMethod(self, callee_name, NULL); + + // if it fails, print the error but otherwise go on if (PyErr_Occurred()) { PyErr_Print(); PyErr_Clear(); } - return 0; + + return py_return; +} + +SWIGEXPORT uint32_t +LLDBSwigPython_CalculateNumChildren +( + PyObject *implementor +) +{ + uint32_t ret_val = UINT32_MAX; + + static char callee_name[] = "num_children"; + + PyObject* py_return = LLDBSwigPython_CallOptionalMember(implementor,callee_name, NULL); + + if (!py_return) + return ret_val; + + if (PyInt_Check(py_return)) + ret_val = PyInt_AsLong(py_return); + + Py_XDECREF(py_return); + + if (PyErr_Occurred()) + { + PyErr_Print(); + PyErr_Clear(); + } + + return ret_val; } SWIGEXPORT PyObject* @@ -542,64 +600,38 @@ LLDBSwigPython_UpdateSynthProviderInstance PyObject *implementor ) { - bool ret_val = false; static char callee_name[] = "update"; - if (implementor == NULL || implementor == Py_None) - return ret_val; - - // all this code is here because update is optional, so we don't want to bother trying to call it unless it's been def:ined for us - // other synth provider calls are mandatory, so we want to fail in a very obvious way if they are missing! - PyObject* pmeth = PyObject_GetAttrString(implementor, callee_name); - - if (PyErr_Occurred()) - { - PyErr_Clear(); - } + PyObject* py_return = LLDBSwigPython_CallOptionalMember(implementor,callee_name); - if (pmeth == NULL || pmeth == Py_None) - { - Py_XDECREF(pmeth); - return ret_val; - } + if (py_return == Py_True) + ret_val = true; - if (PyCallable_Check(pmeth) == 0) - { - if (PyErr_Occurred()) - { - PyErr_Clear(); - } + Py_XDECREF(py_return); + + return ret_val; +} - Py_XDECREF(pmeth); - return ret_val; - } +SWIGEXPORT bool +LLDBSwigPython_MightHaveChildrenSynthProviderInstance +( + PyObject *implementor +) +{ + bool ret_val = false; - if (PyErr_Occurred()) - { - PyErr_Clear(); - } + static char callee_name[] = "has_children"; - Py_XDECREF(pmeth); + PyObject* py_return = LLDBSwigPython_CallOptionalMember(implementor,callee_name, Py_True); - // right now we know this function exists and is callable.. - PyObject* py_return = PyObject_CallMethod(implementor, callee_name, NULL); - - // if it fails, print the error but otherwise go on - if (PyErr_Occurred()) - { - PyErr_Print(); - PyErr_Clear(); - } - if (py_return == Py_True) ret_val = true; Py_XDECREF(py_return); return ret_val; - } SWIGEXPORT void* |