diff options
author | Siva Chandra Reddy <sivachandra@sourceware.org> | 2013-02-12 01:47:49 +0000 |
---|---|---|
committer | Siva Chandra Reddy <sivachandra@sourceware.org> | 2013-02-12 01:47:49 +0000 |
commit | b65a2bd9297dcbdb55c0a84e38246553b5255ac7 (patch) | |
tree | 44d8e9cb571ade6e0a968189c2b1d772aa962281 /gdb/ui-out.c | |
parent | 52df48454323793caaf042dd677689f7a71fb997 (diff) | |
download | gdb-b65a2bd9297dcbdb55c0a84e38246553b5255ac7.zip gdb-b65a2bd9297dcbdb55c0a84e38246553b5255ac7.tar.gz gdb-b65a2bd9297dcbdb55c0a84e38246553b5255ac7.tar.bz2 |
Add support for a destructor for ui_out data and use it to
provide a ui_out destructor.
* ui-out.h: Declare the new ui_out destructor.
(ui_out_impl): Add a field for data destructor in ui_out_impl.
* ui-out.c (default_data_destroy): Add a default data destructor
which does nothing.
(default_ui_out_impl): Set the new data_destroy field to
default_data_destroy
(uo_data_destroy): Local function which invokes the data
destructor if present.
(clear_table): Local function which clears the table data of a
ui_out object.
(ui_out_destroy): Public function which frees a ui_out object.
(ui_out_table_end): Use the new clear_table function.
* cli-out.c (cli_ui_out_impl): Set the new data_destroy field to
NULL.
* mi/mi-out.c (mi_ui_out_impl): Set the new data_destroy field
to NULL.
Diffstat (limited to 'gdb/ui-out.c')
-rw-r--r-- | gdb/ui-out.c | 43 |
1 files changed, 39 insertions, 4 deletions
diff --git a/gdb/ui-out.c b/gdb/ui-out.c index cd7e33e..36c4b15 100644 --- a/gdb/ui-out.c +++ b/gdb/ui-out.c @@ -185,6 +185,7 @@ static void default_message (struct ui_out *uiout, int verbosity, va_list args) ATTRIBUTE_PRINTF (3, 0); static void default_wrap_hint (struct ui_out *uiout, char *identstring); static void default_flush (struct ui_out *uiout); +static void default_data_destroy (struct ui_out *uiout); /* This is the default ui-out implementation functions vector. */ @@ -206,6 +207,7 @@ struct ui_out_impl default_ui_out_impl = default_wrap_hint, default_flush, NULL, + default_data_destroy, 0, /* Does not need MI hacks. */ }; @@ -254,6 +256,7 @@ static void uo_message (struct ui_out *uiout, int verbosity, static void uo_wrap_hint (struct ui_out *uiout, char *identstring); static void uo_flush (struct ui_out *uiout); static int uo_redirect (struct ui_out *uiout, struct ui_file *outstream); +static void uo_data_destroy (struct ui_out *uiout); /* Prototypes for local functions */ @@ -264,6 +267,7 @@ static void append_header_to_list (struct ui_out *uiout, int width, static int get_next_header (struct ui_out *uiout, int *colno, int *width, int *alignment, char **colhdr); static void clear_header_list (struct ui_out *uiout); +static void clear_table (struct ui_out *uiout); static void verify_field (struct ui_out *uiout, int *fldno, int *width, int *align); @@ -328,10 +332,7 @@ ui_out_table_end (struct ui_out *uiout) uiout->table.flag = 0; uo_table_end (uiout); - - if (uiout->table.id) - xfree (uiout->table.id); - clear_header_list (uiout); + clear_table (uiout); } void @@ -749,6 +750,11 @@ default_flush (struct ui_out *uiout) { } +static void +default_data_destroy (struct ui_out *uiout) +{ +} + /* Interface to the implementation functions. */ void @@ -787,6 +793,16 @@ uo_table_header (struct ui_out *uiout, int width, enum ui_align align, uiout->impl->table_header (uiout, width, align, col_name, colhdr); } +/* Clear the table associated with UIOUT. */ + +static void +clear_table (struct ui_out *uiout) +{ + if (uiout->table.id) + xfree (uiout->table.id); + clear_header_list (uiout); +} + void uo_begin (struct ui_out *uiout, enum ui_out_type type, @@ -901,6 +917,15 @@ uo_redirect (struct ui_out *uiout, struct ui_file *outstream) return 0; } +void +uo_data_destroy (struct ui_out *uiout) +{ + if (!uiout->impl->data_destroy) + return; + + uiout->impl->data_destroy (uiout); +} + /* local functions */ /* List of column headers manipulation routines. */ @@ -1079,6 +1104,16 @@ ui_out_new (struct ui_out_impl *impl, void *data, return uiout; } +/* Free UIOUT and the memory areas it references. */ + +void +ui_out_destroy (struct ui_out *uiout) +{ + uo_data_destroy (uiout); + clear_table (uiout); + xfree (uiout); +} + /* Standard gdb initialization hook. */ void |