From patchwork Fri Jun 8 02:55:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 27703 Received: (qmail 54983 invoked by alias); 8 Jun 2018 02:55:33 -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 54933 invoked by uid 89); 8 Jun 2018 02:55:32 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.2 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: gateway21.websitewelcome.com Received: from gateway21.websitewelcome.com (HELO gateway21.websitewelcome.com) (192.185.45.43) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 08 Jun 2018 02:55:30 +0000 Received: from cm15.websitewelcome.com (cm15.websitewelcome.com [100.42.49.9]) by gateway21.websitewelcome.com (Postfix) with ESMTP id 1FC40400C97FA for ; Thu, 7 Jun 2018 21:55:29 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id R7YmfQt4HbXuJR7YnfflhZ; Thu, 07 Jun 2018 21:55:29 -0500 X-Authority-Reason: nr=8 Received: from 75-166-19-45.hlrn.qwest.net ([75.166.19.45]:34912 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1fR7Ym-002GTB-LZ; Thu, 07 Jun 2018 21:55:28 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA] Remove two more uses of make_cleanup_close Date: Thu, 7 Jun 2018 20:55:21 -0600 Message-Id: <20180608025521.14467-1-tom@tromey.com> X-BWhitelist: no X-Source-L: No X-Exim-ID: 1fR7Ym-002GTB-LZ X-Source-Sender: 75-166-19-45.hlrn.qwest.net (bapiya.Home) [75.166.19.45]:34912 X-Source-Auth: tom+tromey.com X-Email-Count: 1 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes This removes two more uses of make_cleanup_close, replacing them with relatively straightforward uses of scoped_fd. Tested by the buildbot. gdb/ChangeLog 2018-06-07 Tom Tromey * source.c (reverse_search_command, forward_search_command): Use scoped_fd. --- gdb/ChangeLog | 5 +++++ gdb/source.c | 30 ++++++++++++------------------ 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/gdb/source.c b/gdb/source.c index 5e50f425f3b..cc5c46d0a7b 100644 --- a/gdb/source.c +++ b/gdb/source.c @@ -1539,10 +1539,8 @@ static void forward_search_command (const char *regex, int from_tty) { int c; - int desc; int line; char *msg; - struct cleanup *cleanups; line = last_line_listed + 1; @@ -1553,22 +1551,21 @@ forward_search_command (const char *regex, int from_tty) if (current_source_symtab == 0) select_source_symtab (0); - desc = open_source_file (current_source_symtab); - if (desc < 0) + scoped_fd desc (open_source_file (current_source_symtab)); + if (desc.get () < 0) perror_with_name (symtab_to_filename_for_display (current_source_symtab)); - cleanups = make_cleanup_close (desc); if (current_source_symtab->line_charpos == 0) - find_source_lines (current_source_symtab, desc); + find_source_lines (current_source_symtab, desc.get ()); if (line < 1 || line > current_source_symtab->nlines) error (_("Expression not found")); - if (lseek (desc, current_source_symtab->line_charpos[line - 1], 0) < 0) + if (lseek (desc.get (), current_source_symtab->line_charpos[line - 1], 0) + < 0) perror_with_name (symtab_to_filename_for_display (current_source_symtab)); - discard_cleanups (cleanups); - gdb_file_up stream (fdopen (desc, FDOPEN_MODE)); + gdb_file_up stream (fdopen (desc.release (), FDOPEN_MODE)); clearerr (stream.get ()); while (1) { @@ -1624,10 +1621,8 @@ static void reverse_search_command (const char *regex, int from_tty) { int c; - int desc; int line; char *msg; - struct cleanup *cleanups; line = last_line_listed - 1; @@ -1638,22 +1633,21 @@ reverse_search_command (const char *regex, int from_tty) if (current_source_symtab == 0) select_source_symtab (0); - desc = open_source_file (current_source_symtab); - if (desc < 0) + scoped_fd desc (open_source_file (current_source_symtab)); + if (desc.get () < 0) perror_with_name (symtab_to_filename_for_display (current_source_symtab)); - cleanups = make_cleanup_close (desc); if (current_source_symtab->line_charpos == 0) - find_source_lines (current_source_symtab, desc); + find_source_lines (current_source_symtab, desc.get ()); if (line < 1 || line > current_source_symtab->nlines) error (_("Expression not found")); - if (lseek (desc, current_source_symtab->line_charpos[line - 1], 0) < 0) + if (lseek (desc.get (), current_source_symtab->line_charpos[line - 1], 0) + < 0) perror_with_name (symtab_to_filename_for_display (current_source_symtab)); - discard_cleanups (cleanups); - gdb_file_up stream (fdopen (desc, FDOPEN_MODE)); + gdb_file_up stream (fdopen (desc.release (), FDOPEN_MODE)); clearerr (stream.get ()); while (line > 1) {