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  <tom@tromey.com>

	* varobj.c (update_dynamic_varobj_children): Update.
	* varobj-iter.h (struct varobj_iter) <next>: Change return type.
	* python/py-varobj.c (struct py_varobj_iter) <next>: Change return
	type.
	(py_varobj_iter::next): Likewise.
This commit is contained in:
Tom Tromey 2020-12-11 09:33:36 -07:00
parent 54746ce37a
commit 60ee72f6d3
4 changed files with 16 additions and 10 deletions

View file

@ -1,3 +1,11 @@
2020-12-11 Tom Tromey <tom@tromey.com>
* varobj.c (update_dynamic_varobj_children): Update.
* varobj-iter.h (struct varobj_iter) <next>: Change return type.
* python/py-varobj.c (struct py_varobj_iter) <next>: Change return
type.
(py_varobj_iter::next): Likewise.
2020-12-11 Tom Tromey <tom@tromey.com> 2020-12-11 Tom Tromey <tom@tromey.com>
* varobj.c (update_dynamic_varobj_children, install_visualizer) * varobj.c (update_dynamic_varobj_children, install_visualizer)

View file

@ -26,7 +26,7 @@ struct py_varobj_iter : public varobj_iter
py_varobj_iter (struct varobj *var, gdbpy_ref<> &&pyiter); py_varobj_iter (struct varobj *var, gdbpy_ref<> &&pyiter);
~py_varobj_iter () override; ~py_varobj_iter () override;
varobj_item *next () override; std::unique_ptr<varobj_item> next () override;
private: private:
@ -55,7 +55,7 @@ py_varobj_iter::~py_varobj_iter ()
/* Implementation of the 'next' method of pretty-printed varobj /* Implementation of the 'next' method of pretty-printed varobj
iterators. */ iterators. */
varobj_item * std::unique_ptr<varobj_item>
py_varobj_iter::next () py_varobj_iter::next ()
{ {
PyObject *py_v; PyObject *py_v;
@ -117,7 +117,7 @@ py_varobj_iter::next ()
vitem->name = name; vitem->name = name;
m_next_raw_index++; m_next_raw_index++;
return vitem; return std::unique_ptr<varobj_item> (vitem);
} }
/* Constructor of pretty-printed varobj iterators. VAR is the varobj /* Constructor of pretty-printed varobj iterators. VAR is the varobj

View file

@ -36,7 +36,7 @@ public:
virtual ~varobj_iter () = default; virtual ~varobj_iter () = default;
virtual varobj_item *next () = 0; virtual std::unique_ptr<varobj_item> next () = 0;
}; };
#endif /* VAROBJ_ITER_H */ #endif /* VAROBJ_ITER_H */

View file

@ -719,12 +719,12 @@ update_dynamic_varobj_children (struct varobj *var,
are more children. */ are more children. */
for (; to < 0 || i < to + 1; ++i) for (; to < 0 || i < to + 1; ++i)
{ {
varobj_item *item; std::unique_ptr<varobj_item> item;
/* See if there was a leftover from last time. */ /* See if there was a leftover from last time. */
if (var->dynamic->saved_item != NULL) if (var->dynamic->saved_item != NULL)
{ {
item = var->dynamic->saved_item; item = std::unique_ptr<varobj_item> (var->dynamic->saved_item);
var->dynamic->saved_item = NULL; var->dynamic->saved_item = NULL;
} }
else else
@ -753,13 +753,11 @@ update_dynamic_varobj_children (struct varobj *var,
can_mention ? newobj : NULL, can_mention ? newobj : NULL,
can_mention ? unchanged : NULL, can_mention ? unchanged : NULL,
can_mention ? cchanged : NULL, i, can_mention ? cchanged : NULL, i,
item); item.get ());
delete item;
} }
else else
{ {
var->dynamic->saved_item = item; var->dynamic->saved_item = item.release ();
/* We want to truncate the child list just before this /* We want to truncate the child list just before this
element. */ element. */