Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [RFA] Remove make_cleanup_value_free
Date: Sun, 08 Oct 2017 22:52:00 -0000	[thread overview]
Message-ID: <20171008225225.21838-1-tom@tromey.com> (raw)

This removes make_cleanup_value_free, in favor of a unique_ptr
specialization.

Regression tested by the buildbot.

gdb/ChangeLog
2017-10-08  Tom Tromey  <tom@tromey.com>

	* utils.h (make_cleanup_value_free): Remove.
	* utils.c (do_value_free, struct cleanup): Remove.
	* dwarf2loc.c (dwarf2_evaluate_loc_desc_full) <DWARF_VALUE_STACK>:
	Use gdb_value_up.
	* value.h (struct value_deleter): New.
	(gdb_value_up): New typedef.
---
 gdb/ChangeLog   |  9 +++++++++
 gdb/dwarf2loc.c |  5 +----
 gdb/utils.c     | 16 ----------------
 gdb/utils.h     |  1 -
 gdb/value.h     | 15 +++++++++++++++
 5 files changed, 25 insertions(+), 21 deletions(-)

diff --git a/gdb/dwarf2loc.c b/gdb/dwarf2loc.c
index c485eaf8b0..fe2fea0d0e 100644
--- a/gdb/dwarf2loc.c
+++ b/gdb/dwarf2loc.c
@@ -2478,7 +2478,6 @@ dwarf2_evaluate_loc_desc_full (struct type *type, struct frame_info *frame,
 	    size_t len = TYPE_LENGTH (subobj_type);
 	    size_t max = TYPE_LENGTH (type);
 	    struct gdbarch *objfile_gdbarch = get_objfile_arch (objfile);
-	    struct cleanup *cleanup;
 
 	    if (subobj_byte_offset + len > max)
 	      invalid_synthetic_pointer ();
@@ -2488,7 +2487,7 @@ dwarf2_evaluate_loc_desc_full (struct type *type, struct frame_info *frame,
 	       below.  */
 	    value_incref (value);
 	    free_values.free_to_mark ();
-	    cleanup = make_cleanup_value_free (value);
+	    gdb_value_up value_holder (value);
 
 	    retval = allocate_value (subobj_type);
 
@@ -2498,8 +2497,6 @@ dwarf2_evaluate_loc_desc_full (struct type *type, struct frame_info *frame,
 
 	    memcpy (value_contents_raw (retval),
 		    value_contents_all (value) + subobj_byte_offset, len);
-
-	    do_cleanups (cleanup);
 	  }
 	  break;
 
diff --git a/gdb/utils.c b/gdb/utils.c
index 118fcc3e6d..07841afb8f 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -185,22 +185,6 @@ make_cleanup_value_free_to_mark (struct value *mark)
   return make_cleanup (do_value_free_to_mark, mark);
 }
 
-/* Helper for make_cleanup_value_free.  */
-
-static void
-do_value_free (void *value)
-{
-  value_free ((struct value *) value);
-}
-
-/* Free VALUE.  */
-
-struct cleanup *
-make_cleanup_value_free (struct value *value)
-{
-  return make_cleanup (do_value_free, value);
-}
-
 /* This function is useful for cleanups.
    Do
 
diff --git a/gdb/utils.h b/gdb/utils.h
index 022af5116c..7af0a5f5ae 100644
--- a/gdb/utils.h
+++ b/gdb/utils.h
@@ -215,7 +215,6 @@ struct target_ops;
 extern struct cleanup *make_cleanup_unpush_target (struct target_ops *ops);
 
 extern struct cleanup *make_cleanup_value_free_to_mark (struct value *);
-extern struct cleanup *make_cleanup_value_free (struct value *);
 
 /* A deleter for a hash table.  */
 struct htab_deleter
diff --git a/gdb/value.h b/gdb/value.h
index 6dee80af33..bc97ec0728 100644
--- a/gdb/value.h
+++ b/gdb/value.h
@@ -1018,6 +1018,21 @@ extern void value_incref (struct value *val);
 
 extern void value_free (struct value *val);
 
+/* A free policy class to interface std::unique_ptr with
+   value_free.  */
+
+struct value_deleter
+{
+  void operator() (struct value *value) const
+  {
+    value_free (value);
+  }
+};
+
+/* A unique pointer to a struct value.  */
+
+typedef std::unique_ptr<struct value, value_deleter> gdb_value_up;
+
 extern void free_all_values (void);
 
 extern void free_value_chain (struct value *v);
-- 
2.13.6


             reply	other threads:[~2017-10-08 22:52 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-08 22:52 Tom Tromey [this message]
2017-10-09  1:55 ` Simon Marchi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171008225225.21838-1-tom@tromey.com \
    --to=tom@tromey.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox