From 24fd95b4cd40f0108299c02f31f2d2a129f83769 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Fri, 11 Dec 2020 09:33:36 -0700 Subject: [PATCH] Change varobj_dynamic::child_iter to unique_ptr This changes varobj_dynamic::child_iter to be a unique_ptr, removing some manual management. gdb/ChangeLog 2020-12-11 Tom Tromey * varobj.c (struct varobj_dynamic) : Now unique_ptr. (varobj_get_iterator): Return unique_ptr. (update_dynamic_varobj_children, install_visualizer) (varobj::~varobj): Update. * python/python-internal.h (py_varobj_get_iterator): Return unique_ptr. * python/py-varobj.c (py_varobj_get_iterator): Return unique_ptr. --- gdb/ChangeLog | 10 ++++++++++ gdb/python/py-varobj.c | 5 +++-- gdb/python/python-internal.h | 4 ++-- gdb/varobj.c | 12 ++++-------- 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 6e6fcfb7be3..dc369546d1f 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,13 @@ +2020-12-11 Tom Tromey + + * varobj.c (struct varobj_dynamic) : Now unique_ptr. + (varobj_get_iterator): Return unique_ptr. + (update_dynamic_varobj_children, install_visualizer) + (varobj::~varobj): Update. + * python/python-internal.h (py_varobj_get_iterator): Return + unique_ptr. + * python/py-varobj.c (py_varobj_get_iterator): Return unique_ptr. + 2020-12-11 Tom Tromey * varobj.c (struct varobj_dynamic) : Now unique_ptr. diff --git a/gdb/python/py-varobj.c b/gdb/python/py-varobj.c index c3fb2e96a9c..dfc9e2baf6c 100644 --- a/gdb/python/py-varobj.c +++ b/gdb/python/py-varobj.c @@ -133,7 +133,7 @@ py_varobj_iter::py_varobj_iter (struct varobj *var, gdbpy_ref<> &&pyiter) /* Return a new pretty-printed varobj iterator suitable to iterate over VAR's children. */ -struct varobj_iter * +std::unique_ptr py_varobj_get_iterator (struct varobj *var, PyObject *printer) { gdbpy_enter_varobj enter_py (var); @@ -156,5 +156,6 @@ py_varobj_get_iterator (struct varobj *var, PyObject *printer) error (_("Could not get children iterator")); } - return new py_varobj_iter (var, std::move (iter)); + return std::unique_ptr (new py_varobj_iter (var, + std::move (iter))); } diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h index 3fdfedefbea..f7e1edc5b28 100644 --- a/gdb/python/python-internal.h +++ b/gdb/python/python-internal.h @@ -754,8 +754,8 @@ int gdb_pymodule_addobject (PyObject *module, const char *name, struct varobj_iter; struct varobj; -struct varobj_iter *py_varobj_get_iterator (struct varobj *var, - PyObject *printer); +std::unique_ptr py_varobj_get_iterator (struct varobj *var, + PyObject *printer); /* Deleter for Py_buffer unique_ptr specialization. */ diff --git a/gdb/varobj.c b/gdb/varobj.c index 92bb60fd9d8..53e33b5d377 100644 --- a/gdb/varobj.c +++ b/gdb/varobj.c @@ -124,7 +124,7 @@ struct varobj_dynamic /* The iterator returned by the printer's 'children' method, or NULL if not available. */ - struct varobj_iter *child_iter = NULL; + std::unique_ptr child_iter; /* We request one extra item from the iterator, so that we can report to the caller whether there are more items than we have @@ -660,7 +660,7 @@ dynamic_varobj_has_child_method (const struct varobj *var) /* A factory for creating dynamic varobj's iterators. Returns an iterator object suitable for iterating over VAR's children. */ -static struct varobj_iter * +static std::unique_ptr varobj_get_iterator (struct varobj *var) { #if HAVE_PYTHON @@ -701,7 +701,6 @@ update_dynamic_varobj_children (struct varobj *var, if (update_children || var->dynamic->child_iter == NULL) { - delete var->dynamic->child_iter; var->dynamic->child_iter = varobj_get_iterator (var); varobj_clear_saved_item (var->dynamic); @@ -735,8 +734,7 @@ update_dynamic_varobj_children (struct varobj *var, if (item == NULL) { /* Iteration is done. Remove iterator from VAR. */ - delete var->dynamic->child_iter; - var->dynamic->child_iter = NULL; + var->dynamic->child_iter.reset (nullptr); break; } /* We don't want to push the extra child on any report list. */ @@ -1064,8 +1062,7 @@ install_visualizer (struct varobj_dynamic *var, PyObject *constructor, Py_XDECREF (var->pretty_printer); var->pretty_printer = visualizer; - delete var->child_iter; - var->child_iter = NULL; + var->child_iter.reset (nullptr); } /* Install the default visualizer for VAR. */ @@ -1875,7 +1872,6 @@ varobj::~varobj () } #endif - delete var->dynamic->child_iter; varobj_clear_saved_item (var->dynamic); if (is_root_p (var)) -- 2.30.2