From patchwork Sun Dec 3 01:24:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Marchi X-Patchwork-Id: 24694 Received: (qmail 93988 invoked by alias); 3 Dec 2017 01:24:58 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 93916 invoked by uid 89); 3 Dec 2017 01:24:49 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_SOFTFAIL autolearn=ham version=3.3.2 spammy=SINGLE 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; Sun, 03 Dec 2017 01:24:47 +0000 X-ASG-Debug-ID: 1512264269-0c856e65d43e328e0001-fS2M51 Received: from smtp.ebox.ca (smtp.electronicbox.net [96.127.255.82]) by barracuda.ebox.ca with ESMTP id kt3yzDFfCNwDEZV1 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sat, 02 Dec 2017 20:24:29 -0500 (EST) X-Barracuda-Envelope-From: simon.marchi@polymtl.ca X-Barracuda-RBL-Trusted-Forwarder: 96.127.255.82 Received: from simark.lan (192-222-251-162.qc.cable.ebox.net [192.222.251.162]) by smtp.ebox.ca (Postfix) with ESMTP id B684D441D64; Sat, 2 Dec 2017 20:24:29 -0500 (EST) From: Simon Marchi X-Barracuda-Effective-Source-IP: 192-222-251-162.qc.cable.ebox.net[192.222.251.162] X-Barracuda-Apparent-Source-IP: 192.222.251.162 X-Barracuda-RBL-IP: 192.222.251.162 To: gdb-patches@sourceware.org Cc: Your Name Subject: [PATCH] Replace VEC(converted_character_d) with std::vector Date: Sat, 2 Dec 2017 20:24:29 -0500 X-ASG-Orig-Subj: [PATCH] Replace VEC(converted_character_d) with std::vector Message-Id: <20171203012429.28536-1-simon.marchi@polymtl.ca> X-Barracuda-Connect: smtp.electronicbox.net[96.127.255.82] X-Barracuda-Start-Time: 1512264269 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: 4694 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= X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.45460 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- X-IsSubscribed: yes From: Your Name This patch changes the usage of VEC(converted_character_d) to use an std::vector instead. This allows getting rid of a cleanup. gdb/ChangeLog: * valprint.c (converted_character_d): Remove typedef. (DEF_VEC_O (converted_character_d)): Remove. (count_next_character): Use std::vector. (print_converted_chars_to_obstack): Likewise. (generic_printstr): Likewise. --- gdb/valprint.c | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/gdb/valprint.c b/gdb/valprint.c index 9b07221f1f..8123c87fa4 100644 --- a/gdb/valprint.c +++ b/gdb/valprint.c @@ -70,9 +70,6 @@ struct converted_character int repeat_count; }; -typedef struct converted_character converted_character_d; -DEF_VEC_O (converted_character_d); - /* Command lists for set/show print raw. */ struct cmd_list_element *setprintrawlist; struct cmd_list_element *showprintrawlist; @@ -2438,11 +2435,11 @@ generic_emit_char (int c, struct type *type, struct ui_file *stream, static int count_next_character (wchar_iterator *iter, - VEC (converted_character_d) **vec) + std::vector *vec) { struct converted_character *current; - if (VEC_empty (converted_character_d, *vec)) + if (vec->empty ()) { struct converted_character tmp; gdb_wchar_t *chars; @@ -2454,10 +2451,10 @@ count_next_character (wchar_iterator *iter, gdb_assert (tmp.num_chars < MAX_WCHARS); memcpy (tmp.chars, chars, tmp.num_chars * sizeof (gdb_wchar_t)); } - VEC_safe_push (converted_character_d, *vec, &tmp); + vec->push_back (tmp); } - current = VEC_last (converted_character_d, *vec); + current = &vec->back (); /* Count repeated characters or bytes. */ current->repeat_count = 1; @@ -2511,7 +2508,7 @@ count_next_character (wchar_iterator *iter, /* Push this next converted character onto the result vector. */ repeat = current->repeat_count; - VEC_safe_push (converted_character_d, *vec, &d); + vec->push_back (d); return repeat; } } @@ -2523,13 +2520,13 @@ count_next_character (wchar_iterator *iter, static void print_converted_chars_to_obstack (struct obstack *obstack, - VEC (converted_character_d) *chars, + const std::vector &chars, int quote_char, int width, enum bfd_endian byte_order, const struct value_print_options *options) { unsigned int idx; - struct converted_character *elem; + const converted_character *elem; enum {START, SINGLE, REPEAT, INCOMPLETE, FINISH} state, last; gdb_wchar_t wide_quote_char = gdb_btowc (quote_char); int need_escape = 0; @@ -2646,7 +2643,7 @@ print_converted_chars_to_obstack (struct obstack *obstack, last = state; if (state != FINISH) { - elem = VEC_index (converted_character_d, chars, idx++); + elem = &chars[idx++]; switch (elem->result) { case wchar_iterate_ok: @@ -2689,10 +2686,8 @@ generic_printstr (struct ui_file *stream, struct type *type, enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (type)); unsigned int i; int width = TYPE_LENGTH (type); - struct cleanup *cleanup; int finished = 0; struct converted_character *last; - VEC (converted_character_d) *converted_chars; if (length == -1) { @@ -2725,9 +2720,7 @@ generic_printstr (struct ui_file *stream, struct type *type, /* Arrange to iterate over the characters, in wchar_t form. */ wchar_iterator iter (string, length * width, encoding, width); - converted_chars = NULL; - cleanup = make_cleanup (VEC_cleanup (converted_character_d), - &converted_chars); + std::vector converted_chars; /* Convert characters until the string is over or the maximum number of printed characters has been reached. */ @@ -2752,7 +2745,7 @@ generic_printstr (struct ui_file *stream, struct type *type, /* Get the last element and determine if the entire string was processed. */ - last = VEC_last (converted_character_d, converted_chars); + last = &converted_chars.back (); finished = (last->result == wchar_iterate_eof); /* Ensure that CONVERTED_CHARS is terminated. */ @@ -2779,8 +2772,6 @@ generic_printstr (struct ui_file *stream, struct type *type, obstack_1grow (&output, '\0'); fputs_filtered ((const char *) obstack_base (&output), stream); - - do_cleanups (cleanup); } /* Print a string from the inferior, starting at ADDR and printing up to LEN