From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 109828 invoked by alias); 24 Nov 2016 15:28:16 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 109745 invoked by uid 89); 24 Nov 2016 15:28:16 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=1.4 required=5.0 tests=AWL,BAYES_50,SPF_SOFTFAIL autolearn=no version=3.3.2 spammy=Hx-spam-relays-external:sk:cable-1, H*RU:sk:cable-1, H*r:sk:cable-1, uiout X-HELO: barracuda.ebox.ca Received: from barracuda.ebox.ca (HELO barracuda.ebox.ca) (96.127.255.19) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 24 Nov 2016 15:28:12 +0000 X-ASG-Debug-ID: 1480001290-0c856e65d5b89e80001-fS2M51 Received: from smtp.electronicbox.net (smtp.electronicbox.net [96.127.255.82]) by barracuda.ebox.ca with ESMTP id IZXFfRzlDsNEfuif (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 24 Nov 2016 10:28:10 -0500 (EST) X-Barracuda-Envelope-From: simon.marchi@polymtl.ca X-Barracuda-RBL-Trusted-Forwarder: 96.127.255.82 Received: from simark.lan (cable-11.246.173-162.electronicbox.net [173.246.11.162]) by smtp.electronicbox.net (Postfix) with ESMTP id 89DBF440E7C; Thu, 24 Nov 2016 10:28:10 -0500 (EST) From: Simon Marchi X-Barracuda-Effective-Source-IP: cable-11.246.173-162.electronicbox.net[173.246.11.162] X-Barracuda-Apparent-Source-IP: 173.246.11.162 X-Barracuda-RBL-IP: 173.246.11.162 To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH 14/22] Use std::string for ui_out_hdr's text fields Date: Thu, 24 Nov 2016 15:28:00 -0000 X-ASG-Orig-Subj: [PATCH 14/22] Use std::string for ui_out_hdr's text fields Message-Id: <20161124152710.25007-14-simon.marchi@polymtl.ca> In-Reply-To: <20161124152428.24725-1-simon.marchi@polymtl.ca> References: <20161124152428.24725-1-simon.marchi@polymtl.ca> X-Barracuda-Connect: smtp.electronicbox.net[96.127.255.82] X-Barracuda-Start-Time: 1480001290 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://96.127.255.19:443/cgi-mod/mark.cgi X-Barracuda-Scan-Msg-Size: 11652 X-Barracuda-BRTS-Status: 1 X-Barracuda-Spam-Score: 0.00 X-Barracuda-Spam-Status: No, SCORE=0.00 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=8.0 tests=BSF_SC0_MISMATCH_TO X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.34709 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- 0.00 BSF_SC0_MISMATCH_TO Envelope rcpt doesn't match header X-IsSubscribed: yes X-SW-Source: 2016-11/txt/msg00755.txt.bz2 This patch makes ui_out_hdr use std::string for its text fields. It makes freeing automatic when the object is deleted. gdb/ChangeLog: * 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) : 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. --- gdb/breakpoint.c | 2 +- gdb/cli-out.c | 5 ++--- gdb/mi/mi-out.c | 11 +++++----- gdb/ui-out.c | 64 ++++++++++++++++++++++---------------------------------- gdb/ui-out.h | 13 +++++++----- 5 files changed, 42 insertions(+), 53 deletions(-) diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index 89ae6c5..4535d59 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -6062,7 +6062,7 @@ wrap_indent_at_field (struct ui_out *uiout, const char *col_name) { 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++) diff --git a/gdb/cli-out.c b/gdb/cli-out.c index 83da5ac..9ba1d17 100644 --- a/gdb/cli-out.c +++ b/gdb/cli-out.c @@ -95,8 +95,7 @@ cli_table_end (struct ui_out *uiout) 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); @@ -105,7 +104,7 @@ cli_table_header (struct ui_out *uiout, int width, enum ui_align alignment, /* 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 */ diff --git a/gdb/mi/mi-out.c b/gdb/mi/mi-out.c index c89076a..72e84b2 100644 --- a/gdb/mi/mi-out.c +++ b/gdb/mi/mi-out.c @@ -42,8 +42,9 @@ static void mi_table_begin (struct ui_out *uiout, int nbrofcols, 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); @@ -141,7 +142,7 @@ mi_table_end (struct ui_out *uiout) 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); @@ -151,8 +152,8 @@ mi_table_header (struct ui_out *uiout, int width, enum ui_align alignment, 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); } diff --git a/gdb/ui-out.c b/gdb/ui-out.c index 8e44698..3cd5695 100644 --- a/gdb/ui-out.c +++ b/gdb/ui-out.c @@ -36,8 +36,8 @@ struct ui_out_hdr 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 @@ -148,8 +148,9 @@ static void uo_table_begin (struct ui_out *uiout, int nbrofcols, 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); @@ -176,10 +177,11 @@ static int uo_redirect (struct ui_out *uiout, struct ui_file *outstream); /* 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, @@ -247,17 +249,16 @@ ui_out_table_end (struct ui_out *uiout) 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 @@ -557,12 +558,11 @@ uo_table_end (struct ui_out *uiout) 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. */ @@ -694,12 +694,6 @@ uo_redirect (struct ui_out *uiout, struct ui_file *outstream) 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 (); } @@ -708,26 +702,18 @@ static void 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 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; @@ -742,7 +728,7 @@ get_next_header (struct ui_out *uiout, 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 ()) @@ -753,7 +739,7 @@ get_next_header (struct ui_out *uiout, *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++; @@ -771,7 +757,7 @@ verify_field (struct ui_out *uiout, int *fldno, int *width, enum ui_align *align) { struct ui_out_level *current = current_level (uiout); - char *text; + const char *text; if (uiout->table.flag) { @@ -816,7 +802,7 @@ ui_out_data (struct ui_out *uiout) /* 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; @@ -832,7 +818,7 @@ ui_out_query_field (struct ui_out *uiout, int colno, *width = hdr->width; *alignment = hdr->alignment; - *col_name = hdr->col_name; + *col_name = hdr->col_name.c_str (); return 1; } diff --git a/gdb/ui-out.h b/gdb/ui-out.h index e251d77..ed2911d 100644 --- a/gdb/ui-out.h +++ b/gdb/ui-out.h @@ -74,8 +74,9 @@ extern void ui_out_end (struct ui_out *uiout, enum ui_out_type type); 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); @@ -129,7 +130,8 @@ extern void ui_out_flush (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 @@ -152,8 +154,9 @@ typedef void (table_begin_ftype) (struct ui_out * uiout, 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, -- 2.10.0