From patchwork Wed Aug 2 15:02:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 21861 Received: (qmail 35682 invoked by alias); 2 Aug 2017 15:03:32 -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 35584 invoked by uid 89); 2 Aug 2017 15:03:32 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: gproxy5-pub.mail.unifiedlayer.com Received: from gproxy5-pub.mail.unifiedlayer.com (HELO gproxy5-pub.mail.unifiedlayer.com) (67.222.38.55) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 02 Aug 2017 15:03:30 +0000 Received: from cmgw4 (unknown [10.0.90.85]) by gproxy5.mail.unifiedlayer.com (Postfix) with ESMTP id 58786140D96 for ; Wed, 2 Aug 2017 09:02:43 -0600 (MDT) Received: from box522.bluehost.com ([74.220.219.122]) by cmgw4 with id sF2g1v00g2f2jeq01F2jf6; Wed, 02 Aug 2017 09:02:43 -0600 X-Authority-Analysis: v=2.2 cv=aJeAkf1m c=1 sm=1 tr=0 a=GsOEXm/OWkKvwdLVJsfwcA==:117 a=GsOEXm/OWkKvwdLVJsfwcA==:17 a=KeKAF7QvOSUA:10 a=zstS-IiYAAAA:8 a=zqyVx-vo9g6DRiZsNNwA:9 a=4G6NA9xxw8l3yy4pmD5M:22 Received: from 174-29-39-24.hlrn.qwest.net ([174.29.39.24]:54692 helo=bapiya.Home) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.87) (envelope-from ) id 1dcvAV-002dpC-Vn; Wed, 02 Aug 2017 09:02:40 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA v3 18/23] Replace do_restore_instream_cleanup with scoped_restore Date: Wed, 2 Aug 2017 09:02:22 -0600 Message-Id: <20170802150227.24460-19-tom@tromey.com> In-Reply-To: <20170802150227.24460-1-tom@tromey.com> References: <20170802150227.24460-1-tom@tromey.com> X-BWhitelist: no X-Exim-ID: 1dcvAV-002dpC-Vn X-Source-Sender: 174-29-39-24.hlrn.qwest.net (bapiya.Home) [174.29.39.24]:54692 X-Source-Auth: tom+tromey.com X-Email-Count: 19 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== X-Local-Domain: yes This changes the users of do_restore_instream_cleanup to use a scoped_restore instead. This patch is broken out because it warrants some additional attention: in particular it's unclear to me whether current_ui can change in the body of these functions -- but if it can, then the cleanup would have modified a different UI's instream member. ChangeLog 2017-08-02 Tom Tromey * top.h (do_restore_instream_cleanup): Remove. * top.c (do_restore_instream_cleanup): Remove. (read_command_file): Use scoped_restore. * cli/cli-script.c (execute_user_command): Use scoped_restore. --- gdb/ChangeLog | 7 +++++++ gdb/cli/cli-script.c | 6 ++---- gdb/top.c | 19 ++----------------- gdb/top.h | 2 -- 4 files changed, 11 insertions(+), 23 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 3c0f0b7..892bf52 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,12 @@ 2017-08-02 Tom Tromey + * top.h (do_restore_instream_cleanup): Remove. + * top.c (do_restore_instream_cleanup): Remove. + (read_command_file): Use scoped_restore. + * cli/cli-script.c (execute_user_command): Use scoped_restore. + +2017-08-02 Tom Tromey + * cli/cli-script.c (execute_user_command) (execute_control_command): Use scoped_restore. diff --git a/gdb/cli/cli-script.c b/gdb/cli/cli-script.c index d8dfbfc..4b8ae0b 100644 --- a/gdb/cli/cli-script.c +++ b/gdb/cli/cli-script.c @@ -377,7 +377,6 @@ execute_user_command (struct cmd_list_element *c, char *args) { struct ui *ui = current_ui; struct command_line *cmdlines; - struct cleanup *old_chain; enum command_control_type ret; extern unsigned int max_user_call_depth; @@ -393,8 +392,8 @@ execute_user_command (struct cmd_list_element *c, char *args) /* Set the instream to 0, indicating execution of a user-defined function. */ - old_chain = make_cleanup (do_restore_instream_cleanup, ui->instream); - ui->instream = NULL; + scoped_restore restore_instream + = make_scoped_restore (&ui->instream, nullptr); scoped_restore save_async = make_scoped_restore (¤t_ui->async, 0); @@ -410,7 +409,6 @@ execute_user_command (struct cmd_list_element *c, char *args) } cmdlines = cmdlines->next; } - do_cleanups (old_chain); } /* This function is called every time GDB prints a prompt. It ensures diff --git a/gdb/top.c b/gdb/top.c index 43bf0d4..6b00c6e 100644 --- a/gdb/top.c +++ b/gdb/top.c @@ -444,27 +444,14 @@ quit_cover (void) event-top.c into this file, top.c. */ /* static */ const char *source_file_name; -/* Clean up on error during a "source" command (or execution of a - user-defined command). */ - -void -do_restore_instream_cleanup (void *stream) -{ - struct ui *ui = current_ui; - - /* Restore the previous input stream. */ - ui->instream = (FILE *) stream; -} - /* Read commands from STREAM. */ void read_command_file (FILE *stream) { struct ui *ui = current_ui; - struct cleanup *cleanups; - cleanups = make_cleanup (do_restore_instream_cleanup, ui->instream); - ui->instream = stream; + scoped_restore save_instream + = make_scoped_restore (&ui->instream, stream); /* Read commands from `instream' and execute them until end of file or error reading instream. */ @@ -479,8 +466,6 @@ read_command_file (FILE *stream) break; command_handler (command); } - - do_cleanups (cleanups); } void (*pre_init_ui_hook) (void); diff --git a/gdb/top.h b/gdb/top.h index 5d7cb1f..4579889 100644 --- a/gdb/top.h +++ b/gdb/top.h @@ -290,8 +290,6 @@ extern void show_history (char *, int); extern void set_verbose (char *, int, struct cmd_list_element *); -extern void do_restore_instream_cleanup (void *stream); - extern char *handle_line_of_input (struct buffer *cmd_line_buffer, char *rl, int repeat, const char *annotation_suffix);