From patchwork Thu Jun 14 21:20:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 27860 Received: (qmail 115615 invoked by alias); 14 Jun 2018 21:21:01 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 115600 invoked by uid 89); 14 Jun 2018 21:21:00 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.8 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= X-HELO: gateway31.websitewelcome.com Received: from gateway31.websitewelcome.com (HELO gateway31.websitewelcome.com) (192.185.144.91) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 14 Jun 2018 21:20:59 +0000 Received: from cm17.websitewelcome.com (cm17.websitewelcome.com [100.42.49.20]) by gateway31.websitewelcome.com (Postfix) with ESMTP id C0EC02C500 for ; Thu, 14 Jun 2018 16:20:57 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id TZflfb20iPvAdTZfrfmR8Q; Thu, 14 Jun 2018 16:20:57 -0500 X-Authority-Reason: nr=8 Received: from [12.176.89.6] (port=44774 helo=localhost.localdomain) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1fTZfl-001xxs-DP; Thu, 14 Jun 2018 16:20:49 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA] Remove cleanups from ser-mingw.c Date: Thu, 14 Jun 2018 14:20:47 -0700 Message-Id: <20180614212047.14265-1-tom@tromey.com> X-BWhitelist: no X-Source-L: No X-Exim-ID: 1fTZfl-001xxs-DP X-Source-Sender: (localhost.localdomain) [12.176.89.6]:44774 X-Source-Auth: tom+tromey.com X-Email-Count: 1 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes 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 * 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 + + * 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 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_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; }