From patchwork Sun Oct 1 04:06:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 23267 Received: (qmail 100307 invoked by alias); 1 Oct 2017 04:06:56 -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 100119 invoked by uid 89); 1 Oct 2017 04:06:54 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=H*MI:sk:2017100, 3346, 2096, H*Ad:U*tom X-HELO: gproxy2-pub.mail.unifiedlayer.com Received: from gproxy2-pub.mail.unifiedlayer.com (HELO gproxy2-pub.mail.unifiedlayer.com) (69.89.18.3) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 01 Oct 2017 04:06:52 +0000 Received: from cmgw3 (unknown [10.0.90.84]) by gproxy2.mail.unifiedlayer.com (Postfix) with ESMTP id E48EE1E0639 for ; Sat, 30 Sep 2017 22:06:50 -0600 (MDT) Received: from box522.bluehost.com ([74.220.219.122]) by cmgw3 with id G46n1w00Q2f2jeq0146qTj; Sat, 30 Sep 2017 22:06:50 -0600 X-Authority-Analysis: v=2.2 cv=K/VSJ2eI c=1 sm=1 tr=0 a=GsOEXm/OWkKvwdLVJsfwcA==:117 a=GsOEXm/OWkKvwdLVJsfwcA==:17 a=2JCJgTwv5E4A:10 a=zstS-IiYAAAA:8 a=aXj6tqUyHhQ7XA_0X08A:9 a=4iQ9nY8BLlayujIa:21 a=wVBRi040zkMEos4x:21 a=4G6NA9xxw8l3yy4pmD5M:22 Received: from 75-166-0-208.hlrn.qwest.net ([75.166.0.208]:43148 helo=pokyo.Home) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.87) (envelope-from ) id 1dyVWh-002l9R-JT; Sat, 30 Sep 2017 22:06:47 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 6/8] Remove make_delete_ui_cleanup Date: Sat, 30 Sep 2017 22:06:41 -0600 Message-Id: <20171001040643.25162-7-tom@tromey.com> In-Reply-To: <20171001040643.25162-1-tom@tromey.com> References: <20171001040643.25162-1-tom@tromey.com> X-BWhitelist: no X-Exim-ID: 1dyVWh-002l9R-JT X-Source-Sender: 75-166-0-208.hlrn.qwest.net (pokyo.Home) [75.166.0.208]:43148 X-Source-Auth: tom+tromey.com X-Email-Count: 7 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== X-Local-Domain: yes This removes new_ui and delete_ui in favor of ordinary 'new' and 'delete', and then removes make_delete_ui_cleanup in favor of std::unique_ptr. 2017-09-30 Tom Tromey * event-top.c (stdin_event_handler): Update. * main.c (captured_main_1): Update. * top.h (make_delete_ui_cleanup): Remove. (struct ui): Add constructor and destructor. (new_ui, delete_ui): Remove. * top.c (make_delete_ui_cleanup): Remove. (new_ui_command): Use std::unique_ptr. (delete_ui_cleanup): Remove. (ui::ui): Rename from new_ui. Update. (free_ui): Remove. (ui::~ui): Rename from delete_ui. Update. --- gdb/ChangeLog | 14 ++++++++ gdb/event-top.c | 2 +- gdb/main.c | 2 +- gdb/top.c | 101 ++++++++++++++++++++------------------------------------ gdb/top.h | 13 ++++---- 5 files changed, 57 insertions(+), 75 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index f3faf73..ad6da2d 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,19 @@ 2017-09-30 Tom Tromey + * event-top.c (stdin_event_handler): Update. + * main.c (captured_main_1): Update. + * top.h (make_delete_ui_cleanup): Remove. + (struct ui): Add constructor and destructor. + (new_ui, delete_ui): Remove. + * top.c (make_delete_ui_cleanup): Remove. + (new_ui_command): Use std::unique_ptr. + (delete_ui_cleanup): Remove. + (ui::ui): Rename from new_ui. Update. + (free_ui): Remove. + (ui::~ui): Rename from delete_ui. Update. + +2017-09-30 Tom Tromey + * symfile.c (load_progress): Use gdb::byte_vector. 2017-09-30 Tom Tromey diff --git a/gdb/event-top.c b/gdb/event-top.c index 54fe471..43e2a27 100644 --- a/gdb/event-top.c +++ b/gdb/event-top.c @@ -487,7 +487,7 @@ stdin_event_handler (int error, gdb_client_data client_data) else { /* Simply delete the UI. */ - delete_ui (ui); + delete ui; } } else diff --git a/gdb/main.c b/gdb/main.c index f174a24..79f14b7 100644 --- a/gdb/main.c +++ b/gdb/main.c @@ -528,7 +528,7 @@ captured_main_1 (struct captured_main_args *context) setvbuf (stderr, NULL, _IONBF, BUFSIZ); #endif - main_ui = new_ui (stdin, stdout, stderr); + main_ui = new ui (stdin, stdout, stderr); current_ui = main_ui; gdb_stdtargerr = gdb_stderr; /* for moment */ diff --git a/gdb/top.c b/gdb/top.c index 56117a3..7efc3d5 100644 --- a/gdb/top.c +++ b/gdb/top.c @@ -249,91 +249,62 @@ static int highest_ui_num; /* See top.h. */ -struct ui * -new_ui (FILE *instream, FILE *outstream, FILE *errstream) +ui::ui (FILE *instream_, FILE *outstream_, FILE *errstream_) + : next (nullptr), + num (++highest_ui_num), + call_readline (nullptr), + input_handler (nullptr), + command_editing (0), + interp_info (nullptr), + async (0), + secondary_prompt_depth (0), + stdin_stream (instream_), + instream (instream_), + outstream (outstream_), + errstream (errstream_), + input_fd (fileno (instream)), + input_interactive_p (ISATTY (instream)), + prompt_state (PROMPT_NEEDED), + m_gdb_stdout (new stdio_file (outstream)), + m_gdb_stdin (new stdio_file (instream)), + m_gdb_stderr (new stderr_file (errstream)), + m_gdb_stdlog (m_gdb_stderr), + m_current_uiout (nullptr) { - struct ui *ui; - - ui = XCNEW (struct ui); - - ui->num = ++highest_ui_num; - ui->stdin_stream = instream; - ui->instream = instream; - ui->outstream = outstream; - ui->errstream = errstream; - - ui->input_fd = fileno (ui->instream); - - ui->input_interactive_p = ISATTY (ui->instream); - - ui->m_gdb_stdin = new stdio_file (ui->instream); - ui->m_gdb_stdout = new stdio_file (ui->outstream); - ui->m_gdb_stderr = new stderr_file (ui->errstream); - ui->m_gdb_stdlog = ui->m_gdb_stderr; - - ui->prompt_state = PROMPT_NEEDED; + buffer_init (&line_buffer); if (ui_list == NULL) - ui_list = ui; + ui_list = this; else { struct ui *last; for (last = ui_list; last->next != NULL; last = last->next) ; - last->next = ui; + last->next = this; } - - return ui; -} - -static void -free_ui (struct ui *ui) -{ - delete ui->m_gdb_stdin; - delete ui->m_gdb_stdout; - delete ui->m_gdb_stderr; - - xfree (ui); } -void -delete_ui (struct ui *todel) +ui::~ui () { struct ui *ui, *uiprev; uiprev = NULL; for (ui = ui_list; ui != NULL; uiprev = ui, ui = ui->next) - if (ui == todel) + if (ui == this) break; gdb_assert (ui != NULL); if (uiprev != NULL) - uiprev->next = ui->next; + uiprev->next = next; else - ui_list = ui->next; - - free_ui (ui); -} - -/* Cleanup that deletes a UI. */ - -static void -delete_ui_cleanup (void *void_ui) -{ - struct ui *ui = (struct ui *) void_ui; + ui_list = next; - delete_ui (ui); -} - -/* See top.h. */ - -struct cleanup * -make_delete_ui_cleanup (struct ui *ui) -{ - return make_cleanup (delete_ui_cleanup, ui); + delete m_gdb_stdin; + delete m_gdb_stdout; + delete m_gdb_stderr; } /* Open file named NAME for read/write, making sure not to make it the @@ -356,7 +327,6 @@ open_terminal_stream (const char *name) static void new_ui_command (const char *args, int from_tty) { - struct ui *ui; struct interp *interp; gdb_file_up stream[3]; int i; @@ -364,7 +334,6 @@ new_ui_command (const char *args, int from_tty) int argc; const char *interpreter_name; const char *tty_name; - struct cleanup *failure_chain; dont_repeat (); @@ -385,12 +354,12 @@ new_ui_command (const char *args, int from_tty) for (i = 0; i < 3; i++) stream[i] = open_terminal_stream (tty_name); - ui = new_ui (stream[0].get (), stream[1].get (), stream[2].get ()); - failure_chain = make_cleanup (delete_ui_cleanup, ui); + std::unique_ptr ui + (new struct ui (stream[0].get (), stream[1].get (), stream[2].get ())); ui->async = 1; - current_ui = ui; + current_ui = ui.get (); set_top_level_interpreter (interpreter_name); @@ -401,7 +370,7 @@ new_ui_command (const char *args, int from_tty) stream[1].release (); stream[2].release (); - discard_cleanups (failure_chain); + ui.release (); } printf_unfiltered ("New UI allocated\n"); diff --git a/gdb/top.h b/gdb/top.h index 6b66083..99ba010 100644 --- a/gdb/top.h +++ b/gdb/top.h @@ -54,6 +54,12 @@ enum prompt_state struct ui { + /* Create a new UI. */ + ui (FILE *instream, FILE *outstream, FILE *errstream); + ~ui (); + + DISABLE_COPY_AND_ASSIGN (ui); + /* Pointer to next in singly-linked list. */ struct ui *next; @@ -203,13 +209,6 @@ public: #define ALL_UIS(UI) \ for (UI = ui_list; UI; UI = UI->next) \ -/* Create a new UI. */ -extern struct ui *new_ui (FILE *instream, FILE *outstream, FILE *errstream); -extern void delete_ui (struct ui *todel); - -/* Cleanup that deletes a UI. */ -extern struct cleanup *make_delete_ui_cleanup (struct ui *ui); - /* Register the UI's input file descriptor in the event loop. */ extern void ui_register_input_event_handler (struct ui *ui);