[PATCH 09/66] Split the tui_win_info destructor

Tom Tromey
2019-06-23T22:43:45Z

This patch adds destructors to tui_source_window and tui_data_window,
and splits ~tui_win_info as appropriate.

gdb/ChangeLog
2019-06-23 Tom Tromey <tom@tromey.com>

* tui/tui-data.h (struct tui_source_window)
(struct tui_data_window): Declare destructors.
* tui/tui-data.c (~tui_source_window, ~tui_data_window): New
destructors.
(tui_win_info): Simplify.
---
gdb/ChangeLog | 8 ++++++
gdb/tui/tui-data.c | 70 ++++++++++++++++++++++------------------------
gdb/tui/tui-data.h | 2 ++
3 files changed, 43 insertions(+), 37 deletions(-)

diff --git a/gdb/tui/tui-data.c b/gdb/tui/tui-data.c
index d98f916ac5b..8993bfe5d47 100644
--- a/gdb/tui/tui-data.c
+++ b/gdb/tui/tui-data.c
@@ -617,47 +617,43 @@ tui_add_content_elements (struct tui_gen_win_info *win_info,
return index_start;
}

-tui_win_info::~tui_win_info ()
+tui_source_window::~tui_source_window ()
{
- struct tui_gen_win_info *generic_win;
+ if (detail.source_info.fullname)
+ {
+ xfree (detail.source_info.fullname);
+ detail.source_info.fullname = NULL;
+ }
+ struct tui_gen_win_info *generic_win = detail.source_info.execution_info;
+ if (generic_win != NULL)
+ {
+ tui_delete_win (generic_win->handle);
+ generic_win->handle = NULL;
+ tui_free_win_content (generic_win);
+ }
+}

- switch (generic.type)
+tui_data_window::~tui_data_window ()
+{
+ if (generic.content != NULL)
{
- case SRC_WIN:
- case DISASSEM_WIN:
- if (detail.source_info.fullname)
- {
- xfree (detail.source_info.fullname);
- detail.source_info.fullname = NULL;
- }
- generic_win = detail.source_info.execution_info;
- if (generic_win != NULL)
- {
- tui_delete_win (generic_win->handle);
- generic_win->handle = NULL;
- tui_free_win_content (generic_win);
- }
- break;
- case DATA_WIN:
- if (generic.content != NULL)
- {
- tui_free_data_content (detail.data_display_info.regs_content,
- detail.data_display_info.regs_content_count);
- detail.data_display_info.regs_content = NULL;
- detail.data_display_info.regs_content_count = 0;
- tui_free_data_content (detail.data_display_info.data_content,
- detail.data_display_info.data_content_count);
- detail.data_display_info.data_content = NULL;
- detail.data_display_info.data_content_count = 0;
- detail.data_display_info.regs_column_count = 1;
- detail.data_display_info.display_regs = FALSE;
- generic.content = NULL;
- generic.content_size = 0;
- }
- break;
- default:
- break;
+ tui_free_data_content (detail.data_display_info.regs_content,
+ detail.data_display_info.regs_content_count);
+ detail.data_display_info.regs_content = NULL;
+ detail.data_display_info.regs_content_count = 0;
+ tui_free_data_content (detail.data_display_info.data_content,
+ detail.data_display_info.data_content_count);
+ detail.data_display_info.data_content = NULL;
+ detail.data_display_info.data_content_count = 0;
+ detail.data_display_info.regs_column_count = 1;
+ detail.data_display_info.display_regs = FALSE;
+ generic.content = NULL;
+ generic.content_size = 0;
}
+}
+
+tui_win_info::~tui_win_info ()
+{
if (generic.handle != NULL)
{
tui_delete_win (generic.handle);
diff --git a/gdb/tui/tui-data.h b/gdb/tui/tui-data.h
index d07862f29f8..2a775a42be8 100644
--- a/gdb/tui/tui-data.h
+++ b/gdb/tui/tui-data.h
@@ -294,6 +294,7 @@ public:
struct tui_source_window : public tui_win_info
{
tui_source_window (enum tui_win_type type);
+ ~tui_source_window () override;
DISABLE_COPY_AND_ASSIGN (tui_source_window);

void clear_detail () override;
@@ -302,6 +303,7 @@ struct tui_source_window : public tui_win_info
struct tui_data_window : public tui_win_info
{
tui_data_window ();
+ ~tui_data_window () override;
DISABLE_COPY_AND_ASSIGN (tui_data_window);

void clear_detail () override;
--
2.17.2