From 4d0fdd9b357aff1fea3ef3def55d12464a41bf5b Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Sun, 7 Jan 2018 09:29:52 -0500 Subject: Replace VEC(gdb_xml_value_s) with std::vector This patch replaces VEC(gdb_xml_value_s), which is passed to XML visitors, with an std::vector. In order to be able to remove the cleanup in gdb_xml_parser::start_element, the gdb_xml_parser structure is made to own the value with a gdb::unique_xmalloc_ptr. This patch has been tested on the buildbot. gdb/ChangeLog: * xml-support.h (struct gdb_xml_value): Add constructor. : Change type to unique_xmalloc_ptr. (gdb_xml_value_s): Remove typedef. (DEF_VEC_O (gdb_xml_value_s)): Remove. (gdb_xml_element_start_handler): Change parameter type to std::vector. (xml_find_attribute): Likewise. * xml-support.c (xml_find_attribute): Change parameter type to std::vector and adjust. (gdb_xml_values_cleanup): Remove. (gdb_xml_parser::start_element): Adjust to std::vector. (xinclude_start_include): Change paraeter type to std::vector and adjust. * btrace.c (check_xml_btrace_version): Likewise. (parse_xml_btrace_block): Likewise. (parse_xml_btrace_pt_config_cpu): Likewise. (parse_xml_btrace_pt): Likewise. (parse_xml_btrace_conf_bts): Likewise. (parse_xml_btrace_conf_pt): Likewise. * memory-map.c (memory_map_start_memory): Likewise. (memory_map_start_property): Likewise. * osdata.c (osdata_start_osdata): Likewise. (osdata_start_item): Likewise. (osdata_start_column): Likewise. * remote.c (start_thread): Likewise. * solib-aix.c (library_list_start_library): Likewise. (library_list_start_list): Likewise. * solib-svr4.c (library_list_start_library): Likewise. (svr4_library_list_start_list): Likewise. * solib-target.c (library_list_start_segment): Likewise. (library_list_start_section): Likewise. (library_list_start_library): Likewise. (library_list_start_list): Likewise. * tracepoint.c (traceframe_info_start_memory): Likewise. (traceframe_info_start_tvar): Likewise. * xml-syscall.c (syscall_start_syscall): Likewise. * xml-tdesc.c (tdesc_start_target): Likewise. (tdesc_start_feature): Likewise. (tdesc_start_reg): Likewise. (tdesc_start_union): Likewise. (tdesc_start_struct): Likewise. (tdesc_start_flags): Likewise. (tdesc_start_enum): Likewise. (tdesc_start_field): Likewise. (tdesc_start_enum_value): Likewise. (tdesc_start_vector): Likewise. --- gdb/xml-support.c | 42 ++++++++++-------------------------------- 1 file changed, 10 insertions(+), 32 deletions(-) (limited to 'gdb/xml-support.c') diff --git a/gdb/xml-support.c b/gdb/xml-support.c index dacc5c4..2547882 100644 --- a/gdb/xml-support.c +++ b/gdb/xml-support.c @@ -228,32 +228,16 @@ gdb_xml_error (struct gdb_xml_parser *parser, const char *format, ...) ATTRIBUTES. Returns NULL if not found. */ struct gdb_xml_value * -xml_find_attribute (VEC(gdb_xml_value_s) *attributes, const char *name) +xml_find_attribute (std::vector &attributes, + const char *name) { - struct gdb_xml_value *value; - int ix; - - for (ix = 0; VEC_iterate (gdb_xml_value_s, attributes, ix, value); ix++) - if (strcmp (value->name, name) == 0) - return value; + for (gdb_xml_value &value : attributes) + if (strcmp (value.name, name) == 0) + return &value; return NULL; } -/* Clean up a vector of parsed attribute values. */ - -static void -gdb_xml_values_cleanup (void *data) -{ - VEC(gdb_xml_value_s) **values = (VEC(gdb_xml_value_s) **) data; - struct gdb_xml_value *value; - int ix; - - for (ix = 0; VEC_iterate (gdb_xml_value_s, *values, ix, value); ix++) - xfree (value->value); - VEC_free (gdb_xml_value_s, *values); -} - /* Handle the start of an element. NAME is the element, and ATTRS are the names and values of this element's attributes. */ @@ -266,9 +250,7 @@ gdb_xml_parser::start_element (const XML_Char *name, const struct gdb_xml_element *element; const struct gdb_xml_attribute *attribute; - VEC(gdb_xml_value_s) *attributes = NULL; unsigned int seen; - struct cleanup *back_to; /* Push an error scope. If we return or throw an exception before filling this in, it will tell us to ignore children of this @@ -317,7 +299,7 @@ gdb_xml_parser::start_element (const XML_Char *name, scope.seen |= seen; - back_to = make_cleanup (gdb_xml_values_cleanup, &attributes); + std::vector attributes; for (attribute = element->attributes; attribute != NULL && attribute->name != NULL; @@ -326,7 +308,6 @@ gdb_xml_parser::start_element (const XML_Char *name, const char *val = NULL; const XML_Char **p; void *parsed_value; - struct gdb_xml_value new_value; for (p = attrs; *p != NULL; p += 2) if (!strcmp (attribute->name, p[0])) @@ -361,9 +342,7 @@ gdb_xml_parser::start_element (const XML_Char *name, else parsed_value = xstrdup (val); - new_value.name = attribute->name; - new_value.value = parsed_value; - VEC_safe_push (gdb_xml_value_s, attributes, &new_value); + attributes.emplace_back (attribute->name, parsed_value); } /* Check for unrecognized attributes. */ @@ -395,8 +374,6 @@ gdb_xml_parser::start_element (const XML_Char *name, scope_level &new_scope = m_scopes.back (); new_scope.element = element; new_scope.elements = element->children; - - do_cleanups (back_to); } /* Wrapper for gdb_xml_start_element, to prevent throwing exceptions @@ -803,11 +780,12 @@ struct xinclude_parsing_data static void xinclude_start_include (struct gdb_xml_parser *parser, const struct gdb_xml_element *element, - void *user_data, VEC(gdb_xml_value_s) *attributes) + void *user_data, + std::vector &attributes) { struct xinclude_parsing_data *data = (struct xinclude_parsing_data *) user_data; - char *href = (char *) xml_find_attribute (attributes, "href")->value; + char *href = (char *) xml_find_attribute (attributes, "href")->value.get (); gdb_xml_debug (parser, _("Processing XInclude of \"%s\""), href); -- cgit v1.1