From: Tom Tromey Date: Fri, 11 Dec 2020 16:33:36 +0000 (-0700) Subject: Change varobj_iter::next to return unique_ptr X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=60ee72f6d3bf10b4bd3ef1315c72c4551c459224;p=binutils-gdb.git Change varobj_iter::next to return unique_ptr This changes varobj_iter::next to return a unique_ptr. This fits in with the ongoing theme of trying to express these ownership transfers via the type system. gdb/ChangeLog 2020-12-11 Tom Tromey * varobj.c (update_dynamic_varobj_children): Update. * varobj-iter.h (struct varobj_iter) : Change return type. * python/py-varobj.c (struct py_varobj_iter) : Change return type. (py_varobj_iter::next): Likewise. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 53f87d9b940..d2c902cd4de 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,11 @@ +2020-12-11 Tom Tromey + + * varobj.c (update_dynamic_varobj_children): Update. + * varobj-iter.h (struct varobj_iter) : Change return type. + * python/py-varobj.c (struct py_varobj_iter) : Change return + type. + (py_varobj_iter::next): Likewise. + 2020-12-11 Tom Tromey * varobj.c (update_dynamic_varobj_children, install_visualizer) diff --git a/gdb/python/py-varobj.c b/gdb/python/py-varobj.c index df6f9c5a953..c3fb2e96a9c 100644 --- a/gdb/python/py-varobj.c +++ b/gdb/python/py-varobj.c @@ -26,7 +26,7 @@ struct py_varobj_iter : public varobj_iter py_varobj_iter (struct varobj *var, gdbpy_ref<> &&pyiter); ~py_varobj_iter () override; - varobj_item *next () override; + std::unique_ptr next () override; private: @@ -55,7 +55,7 @@ py_varobj_iter::~py_varobj_iter () /* Implementation of the 'next' method of pretty-printed varobj iterators. */ -varobj_item * +std::unique_ptr py_varobj_iter::next () { PyObject *py_v; @@ -117,7 +117,7 @@ py_varobj_iter::next () vitem->name = name; m_next_raw_index++; - return vitem; + return std::unique_ptr (vitem); } /* Constructor of pretty-printed varobj iterators. VAR is the varobj diff --git a/gdb/varobj-iter.h b/gdb/varobj-iter.h index ed654190ca5..a05f1cbf8f3 100644 --- a/gdb/varobj-iter.h +++ b/gdb/varobj-iter.h @@ -36,7 +36,7 @@ public: virtual ~varobj_iter () = default; - virtual varobj_item *next () = 0; + virtual std::unique_ptr next () = 0; }; #endif /* VAROBJ_ITER_H */ diff --git a/gdb/varobj.c b/gdb/varobj.c index 80de679a607..e9856ea4eb3 100644 --- a/gdb/varobj.c +++ b/gdb/varobj.c @@ -719,12 +719,12 @@ update_dynamic_varobj_children (struct varobj *var, are more children. */ for (; to < 0 || i < to + 1; ++i) { - varobj_item *item; + std::unique_ptr item; /* See if there was a leftover from last time. */ if (var->dynamic->saved_item != NULL) { - item = var->dynamic->saved_item; + item = std::unique_ptr (var->dynamic->saved_item); var->dynamic->saved_item = NULL; } else @@ -753,13 +753,11 @@ update_dynamic_varobj_children (struct varobj *var, can_mention ? newobj : NULL, can_mention ? unchanged : NULL, can_mention ? cchanged : NULL, i, - item); - - delete item; + item.get ()); } else { - var->dynamic->saved_item = item; + var->dynamic->saved_item = item.release (); /* We want to truncate the child list just before this element. */