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.
+2018-03-02 Simon Marchi <simon.marchi@polymtl.ca>
+
+ * charset.c (struct charset_vector): New.
+ (charsets): Change type to charset_vector.
+ (find_charset_names): Adjust.
+ (add_one): Adjust.
+ (_initialize_charset): Adjust.
+
2018-03-02 Simon Marchi <simon.marchi@polymtl.ca>
* progspace.h (struct program_space) <deleted_solibs>: Change
2018-03-02 Simon Marchi <simon.marchi@polymtl.ca>
* progspace.h (struct program_space) <deleted_solibs>: Change
-/* 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<char *> charsets;
+};
+
+static charset_vector charsets;
#ifdef PHONY_ICONV
static void
find_charset_names (void)
{
#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 */
}
#else /* PHONY_ICONV */
unsigned int i;
for (i = 0; i < count; ++i)
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]));
find_charset_names (void)
{
iconvlist (add_one, NULL);
find_charset_names (void)
{
iconvlist (add_one, NULL);
- VEC_safe_push (char_ptr, charsets, NULL);
+
+ charsets.charsets.push_back (NULL);
break;
keep_going = *p;
*p = '\0';
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. */
if (!keep_going)
break;
/* Skip any extra spaces. */
if (fail)
{
/* Some error occurred, so drop the vector. */
if (fail)
{
/* Some error occurred, so drop the vector. */
- free_char_ptr_vec (charsets);
- charsets = NULL;
- VEC_safe_push (char_ptr, charsets, NULL);
+ charsets.charsets.push_back (NULL);
}
#endif /* HAVE_ICONVLIST || HAVE_LIBICONVLIST */
}
#endif /* HAVE_ICONVLIST || HAVE_LIBICONVLIST */
_initialize_charset (void)
{
/* The first element is always "auto". */
_initialize_charset (void)
{
/* The first element is always "auto". */
- VEC_safe_push (char_ptr, charsets, xstrdup ("auto"));
+ charsets.charsets.push_back (xstrdup ("auto"));
- 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;
else
charset_enum = default_charset_names;