From bd8a901f9e34191e0645a5527556d124ba5c345a Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Tue, 18 Apr 2017 21:39:25 +0100 Subject: xml-support.c: Use std::string for growing string buffer This main idea behind this patch is this change to xml-support.c:scope_level - /* Body text accumulation. This is an owning pointer. */ - struct obstack *body; + /* Body text accumulation. */ + std::string body; ... which allows simplifying other parts of the code. In target_fetch_description_xml, we want to distinguish between returning "success + empty std::string" and "no success", and gdb::optional is a natural fit for that. gdb/ChangeLog: 2017-04-18 Pedro Alves * tracefile-tfile.c (tfile_write_tdesc): Adjust to use gdb::optional. * xml-support.c: Include . (scope_level::scope_level(scope_level &&)) (scope_level::~scope_level): Delete. (scope_level::body): Now a std::string. (gdb_xml_body_text, gdb_xml_end_element): Adjust. (xinclude_parsing_data::xinclude_parsing_data): Add 'output' parameter. (xinclude_parsing_data::~xinclude_parsing_data): Delete. (xinclude_parsing_data::output): Now a std::string reference. (xinclude_start_include): Adjust. (xml_xinclude_default): Adjust. (xml_process_xincludes): Add 'output' parameter, and return bool. * xml-support.h (xml_process_xincludes): Add 'output' parameter, and return bool. * xml-tdesc.c: Include and . (tdesc_xml_cache): Delete. (tdesc_xml_cache_s): Delete. (xml_cache): Now an std::unordered_map. (tdesc_parse_xml): Adjust to use std::string and unordered_map. (target_fetch_description_xml): Change return type to gdb::optional, and adjust. * xml-tdesc.h: Include "common/gdb_optional.h" and . (target_fetch_description_xml): Change return type to gdb::optional. --- gdb/xml-support.h | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'gdb/xml-support.h') diff --git a/gdb/xml-support.h b/gdb/xml-support.h index de685e2..8248a32 100644 --- a/gdb/xml-support.h +++ b/gdb/xml-support.h @@ -54,17 +54,18 @@ extern const char *xml_builtin[][2]; typedef char *(*xml_fetch_another) (const char *href, void *baton); -/* Return a new string which is the expansion of TEXT after processing - tags. FETCHER will be called (with FETCHER_BATON) to - retrieve any new files. DEPTH should be zero on the initial call. +/* Append the expansion of TEXT after processing tags in + RESULT. FETCHER will be called (with FETCHER_BATON) to retrieve + any new files. DEPTH should be zero on the initial call. - On failure, this function uses NAME in a warning and returns NULL. + On failure, this function uses NAME in a warning and returns false. It may throw an exception, but does not for XML parsing problems. */ -char *xml_process_xincludes (const char *name, const char *text, - xml_fetch_another fetcher, void *fetcher_baton, - int depth); +bool xml_process_xincludes (std::string &result, + const char *name, const char *text, + xml_fetch_another fetcher, void *fetcher_baton, + int depth); /* Simplified XML parser infrastructure. */ -- cgit v1.1