diff options
Diffstat (limited to 'gdb/python')
-rw-r--r-- | gdb/python/py-varobj.c | 20 | ||||
-rw-r--r-- | gdb/python/python-internal.h | 12 |
2 files changed, 19 insertions, 13 deletions
diff --git a/gdb/python/py-varobj.c b/gdb/python/py-varobj.c index c8684bd..ffdfa30 100644 --- a/gdb/python/py-varobj.c +++ b/gdb/python/py-varobj.c @@ -17,6 +17,7 @@ #include "python-internal.h" #include "varobj.h" #include "varobj-iter.h" +#include "py-ref.h" /* A dynamic varobj iterator "class" for python pretty-printed varobjs. This inherits struct varobj_iter. */ @@ -167,28 +168,23 @@ py_varobj_iter_new (struct varobj *var, PyObject *pyiter) struct varobj_iter * py_varobj_get_iterator (struct varobj *var, PyObject *printer) { - PyObject *children; PyObject *iter; struct py_varobj_iter *py_iter; - struct cleanup *back_to = varobj_ensure_python_env (var); + + gdbpy_enter_varobj enter_py (var); if (!PyObject_HasAttr (printer, gdbpy_children_cst)) - { - do_cleanups (back_to); - return NULL; - } + return NULL; - children = PyObject_CallMethodObjArgs (printer, gdbpy_children_cst, - NULL); + gdbpy_ref children (PyObject_CallMethodObjArgs (printer, gdbpy_children_cst, + NULL)); if (children == NULL) { gdbpy_print_stack (); error (_("Null value returned for children")); } - make_cleanup_py_decref (children); - - iter = PyObject_GetIter (children); + iter = PyObject_GetIter (children.get ()); if (iter == NULL) { gdbpy_print_stack (); @@ -197,7 +193,5 @@ py_varobj_get_iterator (struct varobj *var, PyObject *printer) py_iter = py_varobj_iter_new (var, iter); - do_cleanups (back_to); - return &py_iter->base; } diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h index a3b9b74..41275bb 100644 --- a/gdb/python/python-internal.h +++ b/gdb/python/python-internal.h @@ -526,6 +526,18 @@ class gdbpy_enter PyObject *m_error_type, *m_error_value, *m_error_traceback; }; +/* Like gdbpy_enter, but takes a varobj. This is a subclass just to + make constructor delegation a little nicer. */ +class gdbpy_enter_varobj : public gdbpy_enter +{ + public: + + /* This is defined in varobj.c, where it can access varobj + internals. */ + gdbpy_enter_varobj (const struct varobj *var); + +}; + struct cleanup *ensure_python_env (struct gdbarch *gdbarch, const struct language_defn *language); |