+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.
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. */
default_wrap_hint,
default_flush,
NULL,
+ default_data_destroy,
0, /* Does not need MI hacks. */
};
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 */
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);
uiout->table.flag = 0;
uo_table_end (uiout);
-
- if (uiout->table.id)
- xfree (uiout->table.id);
- clear_header_list (uiout);
+ clear_table (uiout);
}
void
{
}
+static void
+default_data_destroy (struct ui_out *uiout)
+{
+}
+
/* Interface to the implementation functions. */
void
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,
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. */
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
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 */
wrap_hint_ftype *wrap_hint;
flush_ftype *flush;
redirect_ftype *redirect;
+ data_destroy_ftype *data_destroy;
int is_mi_like_p;
};
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);