From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 47479 invoked by alias); 30 Jul 2017 19:04:31 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 47457 invoked by uid 89); 30 Jul 2017 19:04:29 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.8 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RP_MATCHES_RCVD,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: smtp.polymtl.ca Received: from smtp.polymtl.ca (HELO smtp.polymtl.ca) (132.207.4.11) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 30 Jul 2017 19:04:28 +0000 Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id v6UJ4Lbd031231 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Sun, 30 Jul 2017 15:04:26 -0400 Received: by simark.ca (Postfix, from userid 112) id BD6B31EA05; Sun, 30 Jul 2017 15:04:21 -0400 (EDT) Received: from simark.ca (localhost [127.0.0.1]) by simark.ca (Postfix) with ESMTP id 706C71E043; Sun, 30 Jul 2017 15:04:10 -0400 (EDT) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Sun, 30 Jul 2017 19:04:00 -0000 From: Simon Marchi To: Tom Tromey Cc: gdb-patches@sourceware.org Subject: Re: [RFA v2 06/24] Change open_terminal_stream to return a gdb_file_up In-Reply-To: <20170725172107.9799-7-tom@tromey.com> References: <20170725172107.9799-1-tom@tromey.com> <20170725172107.9799-7-tom@tromey.com> Message-ID: X-Sender: simon.marchi@polymtl.ca User-Agent: Roundcube Webmail/1.3.0 X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Sun, 30 Jul 2017 19:04:21 +0000 X-IsSubscribed: yes X-SW-Source: 2017-07/txt/msg00445.txt.bz2 On 2017-07-25 19:20, Tom Tromey wrote: > This changes open_terminal_stream to return a gdb_file_up, eliminating > another use of make_cleanup_fclose. Arguably perhaps new_ui should > take ownership of the files using a move, but there is at least one > spot where this isn't appropriate (or at least not currently done), so > I elected to use a more minimal approach. > > ChangeLog > 2017-07-25 Tom Tromey > > * top.c (open_terminal_stream): Return gdb_file_up. > (new_ui_command): Update. > --- > gdb/ChangeLog | 5 +++++ > gdb/top.c | 24 ++++++++++++------------ > 2 files changed, 17 insertions(+), 12 deletions(-) > > diff --git a/gdb/ChangeLog b/gdb/ChangeLog > index 4c23f79..c1730dd 100644 > --- a/gdb/ChangeLog > +++ b/gdb/ChangeLog > @@ -1,5 +1,10 @@ > 2017-07-25 Tom Tromey > > + * top.c (open_terminal_stream): Return gdb_file_up. > + (new_ui_command): Update. > + > +2017-07-25 Tom Tromey > + > * source.c (print_source_lines_base, forward_search_command) > (reverse_search_command): Use gdb_file_up. > > diff --git a/gdb/top.c b/gdb/top.c > index 4c53efd..2504eb6 100644 > --- a/gdb/top.c > +++ b/gdb/top.c > @@ -346,16 +346,16 @@ make_delete_ui_cleanup (struct ui *ui) > /* Open file named NAME for read/write, making sure not to make it the > controlling terminal. */ > > -static FILE * > +static gdb_file_up > open_terminal_stream (const char *name) > { > int fd; > > - fd = open (name, O_RDWR | O_NOCTTY); > + fd = gdb_open_cloexec (name, O_RDWR | O_NOCTTY, 0); > if (fd < 0) > perror_with_name (_("opening terminal failed")); > > - return fdopen (fd, "w+"); > + return gdb_file_up (fdopen (fd, "w+")); > } > > /* Implementation of the "new-ui" command. */ > @@ -365,7 +365,7 @@ new_ui_command (char *args, int from_tty) > { > struct ui *ui; > struct interp *interp; > - FILE *stream[3] = { NULL, NULL, NULL }; > + gdb_file_up stream[3]; > int i; > int res; > int argc; > @@ -390,18 +390,13 @@ new_ui_command (char *args, int from_tty) > { > scoped_restore save_ui = make_scoped_restore (¤t_ui); > > - failure_chain = make_cleanup (null_cleanup, NULL); > - > /* Open specified terminal, once for each of > stdin/stdout/stderr. */ > for (i = 0; i < 3; i++) > - { > - stream[i] = open_terminal_stream (tty_name); > - make_cleanup_fclose (stream[i]); > - } > + stream[i] = open_terminal_stream (tty_name); > > - ui = new_ui (stream[0], stream[1], stream[2]); > - make_cleanup (delete_ui_cleanup, ui); > + ui = new_ui (stream[0].get (), stream[1].get (), stream[2].get > ()); > + failure_chain = make_cleanup (delete_ui_cleanup, ui); > > ui->async = 1; > > @@ -411,6 +406,11 @@ new_ui_command (char *args, int from_tty) > > interp_pre_command_loop (top_level_interpreter ()); > > + /* Make sure the files are not closed. */ > + stream[0].release (); > + stream[1].release (); > + stream[2].release (); > + > discard_cleanups (failure_chain); > > /* This restores the previous UI and frees argv. */ LGTM.