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: [PATCH 2/4] Remove cleanup from procfs.c
Date: Mon, 03 Sep 2018 19:03:00 -0000	[thread overview]
Message-ID: <20180903190250.11599-3-tom@tromey.com> (raw)
In-Reply-To: <20180903190250.11599-1-tom@tromey.com>

This removes the last remaining cleanup from procfs.c, replacing it
with a unique_ptr specialization.

gdb/ChangeLog
2018-09-03  Tom Tromey  <tom@tromey.com>

	* procfs.c (struct procinfo_deleter): New.
	(procinfo_up): New typedef.
	(do_destroy_procinfo_cleanup): Remove.
	(procfs_target::info_proc): Use procinfo_up.  Remove cleanups.
---
 gdb/ChangeLog |  7 +++++++
 gdb/procfs.c  | 21 ++++++++++++---------
 2 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/gdb/procfs.c b/gdb/procfs.c
index ec346503487..7d41907c4aa 100644
--- a/gdb/procfs.c
+++ b/gdb/procfs.c
@@ -549,11 +549,16 @@ destroy_procinfo (procinfo *pi)
     }
 }
 
-static void
-do_destroy_procinfo_cleanup (void *pi)
+/* A deleter that calls destroy_procinfo.  */
+struct procinfo_deleter
 {
-  destroy_procinfo ((procinfo *) pi);
-}
+  void operator() (procinfo *pi) const
+  {
+    destroy_procinfo (pi);
+  }
+};
+
+typedef std::unique_ptr<procinfo, procinfo_deleter> procinfo_up;
 
 enum { NOKILL, KILL };
 
@@ -3545,7 +3550,6 @@ info_proc_mappings (procinfo *pi, int summary)
 bool
 procfs_target::info_proc (const char *args, enum info_proc_what what)
 {
-  struct cleanup *old_chain;
   procinfo *process  = NULL;
   procinfo *thread   = NULL;
   char     *tmp      = NULL;
@@ -3567,7 +3571,6 @@ procfs_target::info_proc (const char *args, enum info_proc_what what)
       error (_("Not supported on this target."));
     }
 
-  old_chain = make_cleanup (null_cleanup, 0);
   gdb_argv built_argv (args);
   for (char *arg : built_argv)
     {
@@ -3582,6 +3585,8 @@ procfs_target::info_proc (const char *args, enum info_proc_what what)
 	  tid = strtoul (arg + 1, NULL, 10);
 	}
     }
+
+  procinfo_up temporary_procinfo;
   if (pid == 0)
     pid = inferior_ptid.pid ();
   if (pid == 0)
@@ -3596,7 +3601,7 @@ procfs_target::info_proc (const char *args, enum info_proc_what what)
 	   /* No.  So open a procinfo for it, but
 	      remember to close it again when finished.  */
 	   process = create_procinfo (pid, 0);
-	   make_cleanup (do_destroy_procinfo_cleanup, process);
+	   temporary_procinfo.reset (process);
 	   if (!open_procinfo_files (process, FD_CTL))
 	     proc_error (process, "info proc, open_procinfo_files", __LINE__);
 	 }
@@ -3627,8 +3632,6 @@ procfs_target::info_proc (const char *args, enum info_proc_what what)
       info_proc_mappings (process, 0);
     }
 
-  do_cleanups (old_chain);
-
   return true;
 }
 
-- 
2.13.6


  parent reply	other threads:[~2018-09-03 19:03 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-03 19:03 [PATCH 0/4] Some cleanup removal Tom Tromey
2018-09-03 19:02 ` [PATCH 1/4] Remove cleanup from add_path Tom Tromey
2018-09-03 19:03 ` Tom Tromey [this message]
2018-09-04 10:50   ` [PATCH 2/4] Remove cleanup from procfs.c Rainer Orth
2018-09-04 16:56     ` Tom Tromey
2018-09-03 19:03 ` [PATCH 3/4] Return std::string from gdb_bfd_errmsg Tom Tromey
2018-09-03 19:03 ` [PATCH 4/4] Remove cleanup from try_open_exec_file Tom Tromey
2018-09-04  9:37 ` [PATCH 0/4] Some cleanup removal Rainer Orth
2018-09-04 16:58   ` Tom Tromey
2018-09-04 18:30     ` Rainer Orth
2018-09-13 22:41 ` Tom Tromey

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=20180903190250.11599-3-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