public inbox for gdb-patches@sourceware.org
 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 cleanups from ser-mingw.c
Date: Thu, 14 Jun 2018 21:21:00 -0000	[thread overview]
Message-ID: <20180614212047.14265-1-tom@tromey.com> (raw)

This removes the only cleanup from ser-mingw.c, replacing it with a
specialization of std::unique_ptr.

Tested by the buildbot.

gdb/ChangeLog
2018-06-14  Tom Tromey  <tom@tromey.com>

	* ser-mingw.c (struct pipe_state_destroyer): New.
	(pipe_state_up): New typedef.
	(cleanup_pipe_state): Remove.
	(pipe_windows_open): Use pipe_state_up.
---
 gdb/ChangeLog   |  7 +++++++
 gdb/ser-mingw.c | 21 +++++++++------------
 2 files changed, 16 insertions(+), 12 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 8150685e5c..d045385d26 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,10 @@
+2018-06-14  Tom Tromey  <tom@tromey.com>
+
+	* ser-mingw.c (struct pipe_state_destroyer): New.
+	(pipe_state_up): New typedef.
+	(cleanup_pipe_state): Remove.
+	(pipe_windows_open): Use pipe_state_up.
+
 2018-06-14  Tom de Vries  <tdevries@suse.de>
 
 	PR cli/22573
diff --git a/gdb/ser-mingw.c b/gdb/ser-mingw.c
index d5e5aabb18..c9c0fff2ef 100644
--- a/gdb/ser-mingw.c
+++ b/gdb/ser-mingw.c
@@ -848,20 +848,20 @@ free_pipe_state (struct pipe_state *ps)
   errno = saved_errno;
 }
 
-static void
-cleanup_pipe_state (void *untyped)
+struct pipe_state_destroyer
 {
-  struct pipe_state *ps = (struct pipe_state *) untyped;
+  void operator() (pipe_state *ps) const
+  {
+    free_pipe_state (ps);
+  }
+};
 
-  free_pipe_state (ps);
-}
+typedef std::unique_ptr<pipe_state, pipe_state_destroyer> pipe_state_up;
 
 static int
 pipe_windows_open (struct serial *scb, const char *name)
 {
-  struct pipe_state *ps;
   FILE *pex_stderr;
-  struct cleanup *back_to;
 
   if (name == NULL)
     error_no_arg (_("child command"));
@@ -871,8 +871,7 @@ pipe_windows_open (struct serial *scb, const char *name)
   if (! argv[0] || argv[0][0] == '\0')
     error (_("missing child command"));
 
-  ps = make_pipe_state ();
-  back_to = make_cleanup (cleanup_pipe_state, ps);
+  pipe_state_up ps (make_pipe_state ());
 
   ps->pex = pex_init (PEX_USE_PIPES, "target remote pipe", NULL);
   if (! ps->pex)
@@ -914,14 +913,12 @@ pipe_windows_open (struct serial *scb, const char *name)
     goto fail;
   scb->error_fd = fileno (pex_stderr);
 
-  scb->state = (void *) ps;
+  scb->state = (void *) ps.release ();
 
   argv.release ();
-  discard_cleanups (back_to);
   return 0;
 
  fail:
-  do_cleanups (back_to);
   return -1;
 }
 
-- 
2.14.4

             reply	other threads:[~2018-06-14 21:21 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-14 21:21 Tom Tromey [this message]
2018-06-18  3:16 ` Simon Marchi
2018-06-18 14:17   ` 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=20180614212047.14265-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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).