From c55d06ec95961fadd9deeffae519ff0f20f237d3 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Wed, 2 Jan 2019 08:03:13 -0700 Subject: Remove a cleanup from target-descriptions.c This removes a cleanup from target-descriptions.c, by changing it to use a unique_ptr instead. Note that a deletion adapter is used, even though target_desc is allocated with new, to avoid moving target_desc to target-descriptions.h. gdb/ChangeLog 2019-01-02 Tom Tromey * xml-tdesc.c (xml_cache): Hold a target_desc_up. (tdesc_parse_xml): Remove cleanups. * target-descriptions.h (make_cleanup_free_target_description): Don't declare. (target_desc_deleter): New struct. (target_desc_up): New typedef. * target-descriptions.c (target_desc_deleter::operator()): Rename from free_target_description. (make_cleanup_free_target_description): Remove. --- gdb/xml-tdesc.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'gdb/xml-tdesc.c') diff --git a/gdb/xml-tdesc.c b/gdb/xml-tdesc.c index 601ffe6..7588cb0 100644 --- a/gdb/xml-tdesc.c +++ b/gdb/xml-tdesc.c @@ -66,7 +66,7 @@ tdesc_parse_xml (const char *document, xml_fetch_another fetcher, then we will create unnecessary duplicate gdbarches. See gdbarch_list_lookup_by_info. */ -static std::unordered_map xml_cache; +static std::unordered_map xml_cache; /* Callback data for target description parsing. */ @@ -637,25 +637,22 @@ tdesc_parse_xml (const char *document, xml_fetch_another fetcher, previously parsed. */ const auto it = xml_cache.find (expanded_text); if (it != xml_cache.end ()) - return it->second; + return it->second.get (); memset (&data, 0, sizeof (struct tdesc_parsing_data)); - data.tdesc = allocate_target_description (); - struct cleanup *result_cleanup - = make_cleanup_free_target_description (data.tdesc); + target_desc_up description (allocate_target_description ()); + data.tdesc = description.get (); if (gdb_xml_parse_quick (_("target description"), "gdb-target.dtd", tdesc_elements, expanded_text.c_str (), &data) == 0) { /* Parsed successfully. */ - xml_cache.emplace (std::move (expanded_text), data.tdesc); - discard_cleanups (result_cleanup); + xml_cache.emplace (std::move (expanded_text), std::move (description)); return data.tdesc; } else { warning (_("Could not load XML target description; ignoring")); - do_cleanups (result_cleanup); return NULL; } } -- cgit v1.1