+2016-12-01 Simon Marchi <simon.marchi@polymtl.ca>
+
+ * mi/mi-out.c (mi_table_header): Change char * args to
+ std::string.
+ * cli-out.c (cli_table_header): Likewise.
+ * ui-out.h (table_header_ftype): Likewise.
+ (ui_out_table_header): Constify colhdr argument.
+ (ui_out_query_field): Constify col_name argument.
+ * ui-out.c (ui_out_hdr) <col_name, colhdr>: Change type to
+ std::string.
+ (uo_table_header): Change char * args to std::string.
+ (ui_out_table_header): Likewise.
+ (get_next_header): Constify colhdr argument and adapt.
+ (clear_header_list): Don't free col_name/colhdr fields.
+ (append_header_to_list): Change char * args to std::string and
+ adapt.
+ (verify_field): Constify variable.
+ (ui_out_query_field): Constify col_name argument and adapt.
+ * breakpoint.c (wrap_indent_at_field): Constify variable.
+
2016-12-01 Simon Marchi <simon.marchi@polymtl.ca>
* ui-out.c (struct ui_out_hdr) <next>: Remove.
{
static char wrap_indent[80];
int i, total_width, width, align;
- char *text;
+ const char *text;
total_width = 0;
for (i = 1; ui_out_query_field (uiout, i, &width, &align, &text); i++)
static void
cli_table_header (struct ui_out *uiout, int width, enum ui_align alignment,
- const char *col_name,
- const char *colhdr)
+ const std::string &col_name, const std::string &col_hdr)
{
cli_out_data *data = (cli_out_data *) ui_out_data (uiout);
/* Always go through the function pointer (virtual function call).
We may have been extended. */
- uo_field_string (uiout, 0, width, alignment, 0, colhdr);
+ uo_field_string (uiout, 0, width, alignment, 0, col_hdr.c_str ());
}
/* Mark beginning of a list */
static void mi_table_body (struct ui_out *uiout);
static void mi_table_end (struct ui_out *uiout);
static void mi_table_header (struct ui_out *uiout, int width,
- enum ui_align alig, const char *col_name,
- const char *colhdr);
+ enum ui_align alignment,
+ const std::string &col_name,
+ const std::string &col_hdr);
static void mi_begin (struct ui_out *uiout, enum ui_out_type type,
int level, const char *id);
static void mi_end (struct ui_out *uiout, enum ui_out_type type, int level);
void
mi_table_header (struct ui_out *uiout, int width, enum ui_align alignment,
- const char *col_name, const char *colhdr)
+ const std::string &col_name, const std::string &col_hdr)
{
mi_out_data *data = (mi_out_data *) ui_out_data (uiout);
mi_open (uiout, NULL, ui_out_type_tuple);
mi_field_int (uiout, 0, 0, ui_center, "width", width);
mi_field_int (uiout, 0, 0, ui_center, "alignment", alignment);
- mi_field_string (uiout, 0, 0, ui_center, "col_name", col_name);
- mi_field_string (uiout, 0, width, alignment, "colhdr", colhdr);
+ mi_field_string (uiout, 0, 0, ui_center, "col_name", col_name.c_str ());
+ mi_field_string (uiout, 0, width, alignment, "colhdr", col_hdr.c_str ());
mi_close (uiout, ui_out_type_tuple);
}
int colno;
int width;
enum ui_align alignment;
- char *col_name;
- char *colhdr;
+ std::string col_name;
+ std::string col_hdr;
};
struct ui_out_level
static void uo_table_body (struct ui_out *uiout);
static void uo_table_end (struct ui_out *uiout);
static void uo_table_header (struct ui_out *uiout, int width,
- enum ui_align align, const char *col_name,
- const char *colhdr);
+ enum ui_align align,
+ const std::string &col_name,
+ const std::string &col_hdr);
static void uo_begin (struct ui_out *uiout,
enum ui_out_type type,
int level, const char *id);
/* Prototypes for local functions */
static void append_header_to_list (struct ui_out *uiout, int width,
- enum ui_align alignment, const char *col_name,
- const char *colhdr);
+ enum ui_align alignment,
+ const std::string &col_name,
+ const std::string &col_hdr);
static int get_next_header (struct ui_out *uiout, int *colno, int *width,
- enum ui_align *alignment, char **colhdr);
+ enum ui_align *alignment, const char **col_hdr);
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,
void
ui_out_table_header (struct ui_out *uiout, int width, enum ui_align alignment,
- const char *col_name,
- const char *colhdr)
+ const std::string &col_name, const std::string &col_hdr)
{
if (!uiout->table.flag || uiout->table.body_flag)
internal_error (__FILE__, __LINE__,
_("table header must be specified after table_begin \
and before table_body."));
- append_header_to_list (uiout, width, alignment, col_name, colhdr);
+ append_header_to_list (uiout, width, alignment, col_name, col_hdr);
- uo_table_header (uiout, width, alignment, col_name, colhdr);
+ uo_table_header (uiout, width, alignment, col_name, col_hdr);
}
static void
void
uo_table_header (struct ui_out *uiout, int width, enum ui_align align,
- const char *col_name,
- const char *colhdr)
+ const std::string &col_name, const std::string &col_hdr)
{
if (!uiout->impl->table_header)
return;
- uiout->impl->table_header (uiout, width, align, col_name, colhdr);
+ uiout->impl->table_header (uiout, width, align, col_name, col_hdr);
}
/* Clear the table associated with UIOUT. */
static void
clear_header_list (struct ui_out *uiout)
{
- for (auto &it : uiout->table.headers)
- {
- xfree (it->colhdr);
- xfree (it->col_name);
- }
-
uiout->table.headers.clear ();
uiout->table.headers_iterator = uiout->table.headers.end ();
}
append_header_to_list (struct ui_out *uiout,
int width,
enum ui_align alignment,
- const char *col_name,
- const char *colhdr)
+ const std::string &col_name,
+ const std::string &col_hdr)
{
std::unique_ptr<ui_out_hdr> temphdr (new ui_out_hdr ());
temphdr->width = width;
temphdr->alignment = alignment;
- /* We have to copy the column title as the original may be an
- automatic. */
- if (colhdr != NULL)
- temphdr->colhdr = xstrdup (colhdr);
- else
- temphdr->colhdr = NULL;
- if (col_name != NULL)
- temphdr->col_name = xstrdup (col_name);
- else if (colhdr != NULL)
- temphdr->col_name = xstrdup (colhdr);
- else
- temphdr->col_name = NULL;
+ /* Make our own copy of the strings, since the lifetime of the original
+ versions may be too short. */
+ temphdr->col_hdr = col_hdr;
+ temphdr->col_name = col_name;
temphdr->colno = uiout->table.headers.size () + 1;
int *colno,
int *width,
enum ui_align *alignment,
- char **colhdr)
+ const char **col_hdr)
{
/* There may be no headers at all or we may have used all columns. */
if (uiout->table.headers_iterator == uiout->table.headers.end ())
*colno = hdr->colno;
*width = hdr->width;
*alignment = hdr->alignment;
- *colhdr = hdr->colhdr;
+ *col_hdr = hdr->col_hdr.c_str ();
/* Advance the header pointer to the next entry. */
uiout->table.headers_iterator++;
enum ui_align *align)
{
struct ui_out_level *current = current_level (uiout);
- char *text;
+ const char *text;
if (uiout->table.flag)
{
/* Access table field parameters. */
int
ui_out_query_field (struct ui_out *uiout, int colno,
- int *width, int *alignment, char **col_name)
+ int *width, int *alignment, const char **col_name)
{
if (!uiout->table.flag)
return 0;
*width = hdr->width;
*alignment = hdr->alignment;
- *col_name = hdr->col_name;
+ *col_name = hdr->col_name.c_str ();
return 1;
}
field, ... }, ... ] }''. If NR_ROWS is negative then there is at
least one row. */
extern void ui_out_table_header (struct ui_out *uiout, int width,
- enum ui_align align, const char *col_name,
- const char *colhdr);
+ enum ui_align align,
+ const std::string &col_name,
+ const std::string &col_hdr);
extern void ui_out_table_body (struct ui_out *uiout);
extern int ui_out_test_flags (struct ui_out *uiout, int mask);
extern int ui_out_query_field (struct ui_out *uiout, int colno,
- int *width, int *alignment, char **col_name);
+ int *width, int *alignment,
+ const char **col_name);
/* HACK: Code in GDB is currently checking to see the type of ui_out
builder when determining which output to produce. This function is
typedef void (table_body_ftype) (struct ui_out * uiout);
typedef void (table_end_ftype) (struct ui_out * uiout);
typedef void (table_header_ftype) (struct ui_out * uiout, int width,
- enum ui_align align, const char *col_name,
- const char *colhdr);
+ enum ui_align align,
+ const std::string &col_name,
+ const std::string &col_hdr);
/* Note: level 0 is the top-level so LEVEL is always greater than
zero. */
typedef void (ui_out_begin_ftype) (struct ui_out *uiout,