From patchwork Wed Jan 2 15:52:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 30934 Received: (qmail 13374 invoked by alias); 2 Jan 2019 15:52:54 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 13342 invoked by uid 89); 2 Jan 2019 15:52:52 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= X-HELO: gateway22.websitewelcome.com Received: from gateway22.websitewelcome.com (HELO gateway22.websitewelcome.com) (192.185.46.187) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 02 Jan 2019 15:52:50 +0000 Received: from cm16.websitewelcome.com (cm16.websitewelcome.com [100.42.49.19]) by gateway22.websitewelcome.com (Postfix) with ESMTP id EFAE19BE2 for ; Wed, 2 Jan 2019 09:52:48 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id eip6gduM24FKpeip6g6ba4; Wed, 02 Jan 2019 09:52:48 -0600 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version :Content-Type:Content-Transfer-Encoding:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=zaMn5/ZWCZQ7S2Zlr/hfGxccsHzT1fHwbWa3kH+UkUA=; b=L9PMBNL3WcPFvcBGgvxbcaD+x8 58VHm8WC4aOYZWDMSvGZdm2X7gXMxG8JwpZaZCnJxyw9DJ0vRlJTGMQtMdKG2Yl9dqQxZxRyBdOsM 6dY0css0W5x19keol2MRJ7mDV; Received: from [50.236.237.38] (port=44066 helo=bapiya.TCHFunNetwork.pvt) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1geip6-003fu7-QT; Wed, 02 Jan 2019 09:52:48 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Remove a cleanup from target-descriptions.c Date: Wed, 2 Jan 2019 08:52:43 -0700 Message-Id: <20190102155243.17250-1-tom@tromey.com> 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/ChangeLog | 12 ++++++++++++ gdb/target-descriptions.c | 12 ++---------- gdb/target-descriptions.h | 13 ++++++++++++- gdb/xml-tdesc.c | 13 +++++-------- 4 files changed, 31 insertions(+), 19 deletions(-) diff --git a/gdb/target-descriptions.c b/gdb/target-descriptions.c index efea97ed40..f04b8fc316 100644 --- a/gdb/target-descriptions.c +++ b/gdb/target-descriptions.c @@ -1138,20 +1138,12 @@ allocate_target_description (void) return new target_desc (); } -static void -free_target_description (void *arg) +void +target_desc_deleter::operator() (struct target_desc *target_desc) const { - struct target_desc *target_desc = (struct target_desc *) arg; - delete target_desc; } -struct cleanup * -make_cleanup_free_target_description (struct target_desc *target_desc) -{ - return make_cleanup (free_target_description, target_desc); -} - void tdesc_add_compatible (struct target_desc *target_desc, const struct bfd_arch_info *compatible) diff --git a/gdb/target-descriptions.h b/gdb/target-descriptions.h index 402bef56e0..fe07d425a5 100644 --- a/gdb/target-descriptions.h +++ b/gdb/target-descriptions.h @@ -199,9 +199,20 @@ struct type *tdesc_find_type (struct gdbarch *gdbarch, const char *id); int tdesc_register_in_reggroup_p (struct gdbarch *gdbarch, int regno, struct reggroup *reggroup); + +/* A deleter adapter for a target desc. */ + +struct target_desc_deleter +{ + void operator() (struct target_desc *desc) const; +}; + +/* A unique pointer specialization that holds a target_desc. */ + +typedef std::unique_ptr target_desc_up; + /* Methods for constructing a target description. */ -struct cleanup *make_cleanup_free_target_description (struct target_desc *); void set_tdesc_architecture (struct target_desc *, const struct bfd_arch_info *); void set_tdesc_osabi (struct target_desc *, enum gdb_osabi osabi); diff --git a/gdb/xml-tdesc.c b/gdb/xml-tdesc.c index 601ffe6086..7588cb0f99 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; } }