From: Tom Tromey Date: Fri, 11 Dec 2020 16:33:36 +0000 (-0700) Subject: Change varobj_item::value to a value_ref_ptr X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=11106495078658246feda85cb7566c1a6aacb1e1;p=binutils-gdb.git Change varobj_item::value to a value_ref_ptr This changes varobj_item::value to be a value_ref_ptr, removing some manual management. gdb/ChangeLog 2020-12-11 Tom Tromey * varobj.c (install_dynamic_child, varobj_clear_saved_item) (update_dynamic_varobj_children, create_child) (create_child_with_value): Update. * varobj-iter.h (struct varobj_item) : Now a value_ref_ptr. * python/py-varobj.c (py_varobj_iter::next): Call release_value. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index dc369546d1f..3b6569a3087 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,12 @@ +2020-12-11 Tom Tromey + + * varobj.c (install_dynamic_child, varobj_clear_saved_item) + (update_dynamic_varobj_children, create_child) + (create_child_with_value): Update. + * varobj-iter.h (struct varobj_item) : Now a + value_ref_ptr. + * python/py-varobj.c (py_varobj_iter::next): Call release_value. + 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 dfc9e2baf6c..e550c7bf785 100644 --- a/gdb/python/py-varobj.c +++ b/gdb/python/py-varobj.c @@ -111,7 +111,7 @@ py_varobj_iter::next () } vitem = new varobj_item (); - vitem->value = convert_value_from_python (py_v); + vitem->value = release_value (convert_value_from_python (py_v)); if (vitem->value == NULL) gdbpy_print_stack (); vitem->name = name; diff --git a/gdb/varobj-iter.h b/gdb/varobj-iter.h index a05f1cbf8f3..fea14d6c1c6 100644 --- a/gdb/varobj-iter.h +++ b/gdb/varobj-iter.h @@ -25,7 +25,7 @@ struct varobj_item std::string name; /* Value of this item. */ - struct value *value; + value_ref_ptr value; }; /* A dynamic varobj iterator "class". */ diff --git a/gdb/varobj.c b/gdb/varobj.c index 53e33b5d377..4cbf0078459 100644 --- a/gdb/varobj.c +++ b/gdb/varobj.c @@ -625,14 +625,15 @@ install_dynamic_child (struct varobj *var, else { varobj *existing = var->children[index]; - bool type_updated = update_type_if_necessary (existing, item->value); + bool type_updated = update_type_if_necessary (existing, + item->value.get ()); if (type_updated) { if (type_changed != NULL) type_changed->push_back (existing); } - if (install_new_value (existing, item->value, 0)) + if (install_new_value (existing, item->value.get (), 0)) { if (!type_updated && changed != NULL) changed->push_back (existing); @@ -678,10 +679,7 @@ static void varobj_clear_saved_item (struct varobj_dynamic *var) { if (var->saved_item != NULL) - { - value_decref (var->saved_item->value); - var->saved_item.reset (nullptr); - } + var->saved_item.reset (nullptr); } static bool @@ -723,13 +721,7 @@ update_dynamic_varobj_children (struct varobj *var, if (var->dynamic->saved_item != NULL) item = std::move (var->dynamic->saved_item); else - { - item = var->dynamic->child_iter->next (); - /* Release vitem->value so its lifetime is not bound to the - execution of a command. */ - if (item != NULL && item->value != NULL) - item->value = release_value (item->value).release (); - } + item = var->dynamic->child_iter->next (); if (item == NULL) { @@ -1804,7 +1796,7 @@ create_child (struct varobj *parent, int index, std::string &name) struct varobj_item item; std::swap (item.name, name); - item.value = value_of_child (parent, index); + item.value = release_value (value_of_child (parent, index)); return create_child_with_value (parent, index, &item); } @@ -1835,12 +1827,12 @@ create_child_with_value (struct varobj *parent, int index, if (item->value != NULL) /* If the child had no evaluation errors, var->value will be non-NULL and contain a valid type. */ - child->type = value_actual_type (item->value, 0, NULL); + child->type = value_actual_type (item->value.get (), 0, NULL); else /* Otherwise, we must compute the type. */ child->type = (*child->root->lang_ops->type_of_child) (child->parent, child->index); - install_new_value (child, item->value, 1); + install_new_value (child, item->value.get (), 1); return child; }