From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 41055 invoked by alias); 25 Feb 2018 16:32:56 -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 41034 invoked by uid 89); 25 Feb 2018 16:32:55 -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= 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, 25 Feb 2018 16:32:54 +0000 X-ASG-Debug-ID: 1519576370-0c856e618ae39d0001-fS2M51 Received: from smtp.ebox.ca (smtp.electronicbox.net [96.127.255.82]) by barracuda.ebox.ca with ESMTP id 46hoZ3n9KId4DPPm (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sun, 25 Feb 2018 11:32:51 -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 D68DF441D70; Sun, 25 Feb 2018 11:32:50 -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: Simon Marchi Subject: [PATCH 4/5] C++ify charsets Date: Sun, 25 Feb 2018 16:32:00 -0000 X-ASG-Orig-Subj: [PATCH 4/5] C++ify charsets Message-Id: <20180225163247.20157-4-simon.marchi@polymtl.ca> In-Reply-To: <20180225163247.20157-1-simon.marchi@polymtl.ca> References: <20180225163247.20157-1-simon.marchi@polymtl.ca> X-Barracuda-Connect: smtp.electronicbox.net[96.127.255.82] X-Barracuda-Start-Time: 1519576371 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: 3504 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.48309 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- X-IsSubscribed: yes X-SW-Source: 2018-02/txt/msg00354.txt.bz2 This patch makes the charset list an std::vector instead of a VEC. Because we must have access to the raw pointers as a simple array, we can't use a vector of unique_ptr/unique_xmalloc_ptr. Therefore, wrap the vector in a simple class to facilitate the cleanup. This allows removing one usage of free_char_ptr_vec. gdb/ChangeLog: * charset.c (struct charset_vector): New. (charsets): Change type to charset_vector. (find_charset_names): Adjust. (add_one): Adjust. (_initialize_charset): Adjust. --- gdb/charset.c | 46 +++++++++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/gdb/charset.c b/gdb/charset.c index 98a51794fb..fcb24a4882 100644 --- a/gdb/charset.c +++ b/gdb/charset.c @@ -705,21 +705,33 @@ wchar_iterator::iterate (enum wchar_iterate_result *out_result, return -1; } -/* The charset.c module initialization function. */ +struct charset_vector +{ + ~charset_vector () + { + clear (); + } + + void clear () + { + for (char *c : charsets) + xfree (c); -static VEC (char_ptr) *charsets; + charsets.clear (); + } + + std::vector charsets; +}; + +static charset_vector charsets; #ifdef PHONY_ICONV static void find_charset_names (void) { - /* Cast is fine here, because CHARSETS is never released. Note that - the vec does not hold "const char *" pointers instead of "char *" - because the non-phony version stores heap-allocated strings in - it. */ - VEC_safe_push (char_ptr, charsets, (char *) GDB_DEFAULT_HOST_CHARSET); - VEC_safe_push (char_ptr, charsets, NULL); + charsets.charsets.push_back (xstrdup (GDB_DEFAULT_HOST_CHARSET)); + charsets.charsets.push_back (NULL); } #else /* PHONY_ICONV */ @@ -740,7 +752,7 @@ add_one (unsigned int count, const char *const *names, void *data) unsigned int i; for (i = 0; i < count; ++i) - VEC_safe_push (char_ptr, charsets, xstrdup (names[i])); + charsets.charsets.push_back (xstrdup (names[i])); return 0; } @@ -749,7 +761,8 @@ static void find_charset_names (void) { iconvlist (add_one, NULL); - VEC_safe_push (char_ptr, charsets, NULL); + + charsets.charsets.push_back (NULL); } #else @@ -879,7 +892,7 @@ find_charset_names (void) break; keep_going = *p; *p = '\0'; - VEC_safe_push (char_ptr, charsets, xstrdup (start)); + charsets.charsets.push_back (xstrdup (start)); if (!keep_going) break; /* Skip any extra spaces. */ @@ -900,11 +913,10 @@ find_charset_names (void) if (fail) { /* Some error occurred, so drop the vector. */ - free_char_ptr_vec (charsets); - charsets = NULL; + charsets.clear (); } else - VEC_safe_push (char_ptr, charsets, NULL); + charsets.charsets.push_back (NULL); } #endif /* HAVE_ICONVLIST || HAVE_LIBICONVLIST */ @@ -994,11 +1006,11 @@ void _initialize_charset (void) { /* The first element is always "auto". */ - VEC_safe_push (char_ptr, charsets, xstrdup ("auto")); + charsets.charsets.push_back (xstrdup ("auto")); find_charset_names (); - if (VEC_length (char_ptr, charsets) > 1) - charset_enum = (const char **) VEC_address (char_ptr, charsets); + if (charsets.charsets.size () > 1) + charset_enum = (const char **) charsets.charsets.data (); else charset_enum = default_charset_names; -- 2.16.1