aboutsummaryrefslogtreecommitdiff
path: root/gdb/top.c
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2017-09-29 22:35:58 -0600
committerTom Tromey <tom@tromey.com>2017-10-03 05:33:47 -0600
commit895b8f306b1f54d85915ca0d24368f40b2e42554 (patch)
tree4f7e798e0c0cd0bab6dbe2adb72bdd06d4efaa8f /gdb/top.c
parent0efef6405493c0bf438486819bec70b304276e16 (diff)
downloadgdb-895b8f306b1f54d85915ca0d24368f40b2e42554.zip
gdb-895b8f306b1f54d85915ca0d24368f40b2e42554.tar.gz
gdb-895b8f306b1f54d85915ca0d24368f40b2e42554.tar.bz2
Remove make_delete_ui_cleanup
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-10-03 Tom Tromey <tom@tromey.com> * 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.
Diffstat (limited to 'gdb/top.c')
-rw-r--r--gdb/top.c101
1 files changed, 35 insertions, 66 deletions
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> 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");