Add support for a destructor for ui_out data and use it to
authorSiva Chandra Reddy <sivachandra@sourceware.org>
Tue, 12 Feb 2013 01:47:49 +0000 (01:47 +0000)
committerSiva Chandra Reddy <sivachandra@sourceware.org>
Tue, 12 Feb 2013 01:47:49 +0000 (01:47 +0000)
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.

gdb/ChangeLog
gdb/cli-out.c
gdb/mi/mi-out.c
gdb/ui-out.c
gdb/ui-out.h

index 80d4898e5f677438a9b45bc0102f7abb649ee638..a40756cbc8ec4f6d541a71986a46037275259346 100644 (file)
@@ -1,3 +1,24 @@
+2013-02-11  Siva Chandra Reddy  <sivachandra@google.com>
+
+       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.
+
 2013-02-11  Doug Evans  <dje@google.com>
 
        * printcmd.c (printf_c_string,printf_wide_c_string): New functions.
index 58b7e11b3949f0cfaa4d67d6f727dab28c90e110..380352bd3728c83dda2adc5d020f3d60f4ed3b4d 100644 (file)
@@ -370,6 +370,7 @@ struct ui_out_impl cli_ui_out_impl =
   cli_wrap_hint,
   cli_flush,
   cli_redirect,
+  0,
   0, /* Does not need MI hacks (i.e. needs CLI hacks).  */
 };
 
index c96a74e75c5520270e3e562098653b83bcff97df..90a4c1ce251907a8f619f4388954c60fa5aacaf5 100644 (file)
@@ -88,6 +88,7 @@ struct ui_out_impl mi_ui_out_impl =
   mi_wrap_hint,
   mi_flush,
   mi_redirect,
+  0,
   1, /* Needs MI hacks.  */
 };
 
index cd7e33efa59977de3a32a56895ee2445e9962f99..36c4b156f5815082e2b2eb0225ff77e254a5d48c 100644 (file)
@@ -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
index 3de567a68dcf06fa633d83531381e9461ae23a90..b07496e8b7aa5045c1cf9ea9415285ee601378d2 100644 (file)
@@ -197,6 +197,7 @@ typedef void (wrap_hint_ftype) (struct ui_out * uiout, char *identstring);
 typedef void (flush_ftype) (struct ui_out * uiout);
 typedef int (redirect_ftype) (struct ui_out * uiout,
                              struct ui_file * outstream);
+typedef void (data_destroy_ftype) (struct ui_out *uiout);
 
 /* ui-out-impl */
 
@@ -221,6 +222,7 @@ struct ui_out_impl
     wrap_hint_ftype *wrap_hint;
     flush_ftype *flush;
     redirect_ftype *redirect;
+    data_destroy_ftype *data_destroy;
     int is_mi_like_p;
   };
 
@@ -236,6 +238,10 @@ extern struct ui_out *ui_out_new (struct ui_out_impl *impl,
                                  void *data,
                                  int flags);
 
+/* Destroy a ui_out object.  */
+
+extern void ui_out_destroy (struct ui_out *uiout);
+
 /* Redirect the ouptut of a ui_out object temporarily.  */
 
 extern int ui_out_redirect (struct ui_out *uiout, struct ui_file *outstream);
This page took 0.028355 seconds and 4 git commands to generate.