From 7446266408f6c8cdf890c23c391c0c803c7077ca Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Fri, 11 Dec 2020 09:33:36 -0700 Subject: [PATCH] Change varobj_dynamic::saved_item to unique_ptr This changes varobj_dynamic::saved_item to be a unique_ptr. gdb/ChangeLog 2020-12-11 Tom Tromey * varobj.c (struct varobj_dynamic) : Now unique_ptr. (varobj_clear_saved_item, update_dynamic_varobj_children): Update. --- gdb/ChangeLog | 6 ++++++ gdb/varobj.c | 12 ++++-------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index d2c902cd4de..6e6fcfb7be3 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,9 @@ +2020-12-11 Tom Tromey + + * varobj.c (struct varobj_dynamic) : Now unique_ptr. + (varobj_clear_saved_item, update_dynamic_varobj_children): + Update. + 2020-12-11 Tom Tromey * varobj.c (update_dynamic_varobj_children): Update. diff --git a/gdb/varobj.c b/gdb/varobj.c index e9856ea4eb3..92bb60fd9d8 100644 --- a/gdb/varobj.c +++ b/gdb/varobj.c @@ -131,7 +131,7 @@ struct varobj_dynamic already reported. However, we don't want to install this value when we read it, because that will mess up future updates. So, we stash it here instead. */ - varobj_item *saved_item = NULL; + std::unique_ptr saved_item; }; /* Private function prototypes */ @@ -680,8 +680,7 @@ varobj_clear_saved_item (struct varobj_dynamic *var) if (var->saved_item != NULL) { value_decref (var->saved_item->value); - delete var->saved_item; - var->saved_item = NULL; + var->saved_item.reset (nullptr); } } @@ -723,10 +722,7 @@ update_dynamic_varobj_children (struct varobj *var, /* See if there was a leftover from last time. */ if (var->dynamic->saved_item != NULL) - { - item = std::unique_ptr (var->dynamic->saved_item); - var->dynamic->saved_item = NULL; - } + item = std::move (var->dynamic->saved_item); else { item = var->dynamic->child_iter->next (); @@ -757,7 +753,7 @@ update_dynamic_varobj_children (struct varobj *var, } else { - var->dynamic->saved_item = item.release (); + var->dynamic->saved_item = std::move (item); /* We want to truncate the child list just before this element. */ -- 2.30.2