From patchwork Tue Oct 31 01:41:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Marchi X-Patchwork-Id: 23981 Received: (qmail 18154 invoked by alias); 31 Oct 2017 01:42:27 -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 17928 invoked by uid 89); 31 Oct 2017 01:42:25 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.8 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.2 spammy=sk:propert, 4257, xfree X-HELO: sessmg23.ericsson.net Received: from sessmg23.ericsson.net (HELO sessmg23.ericsson.net) (193.180.251.45) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 31 Oct 2017 01:42:23 +0000 Received: from ESESSHC013.ericsson.se (Unknown_Domain [153.88.183.57]) by sessmg23.ericsson.net (Symantec Mail Security) with SMTP id DB.83.09869.BF4D7F95; Tue, 31 Oct 2017 02:42:19 +0100 (CET) Received: from EUR01-VE1-obe.outbound.protection.outlook.com (153.88.183.145) by oa.msg.ericsson.com (153.88.183.57) with Microsoft SMTP Server (TLS) id 14.3.352.0; Tue, 31 Oct 2017 02:42:18 +0100 Received: from elxacz23q12.localdomain (70.81.137.44) by DBXPR07MB319.eurprd07.prod.outlook.com (2a01:111:e400:941d::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.197.4; Tue, 31 Oct 2017 01:42:16 +0000 From: Simon Marchi To: CC: Simon Marchi Subject: [PATCH 01/10] Make target_desc::properties an std::vector Date: Mon, 30 Oct 2017 21:41:51 -0400 Message-ID: <1509414120-14659-2-git-send-email-simon.marchi@ericsson.com> In-Reply-To: <1509414120-14659-1-git-send-email-simon.marchi@ericsson.com> References: <1509414120-14659-1-git-send-email-simon.marchi@ericsson.com> MIME-Version: 1.0 X-ClientProxiedBy: BN6PR1101CA0023.namprd11.prod.outlook.com (2603:10b6:405:4a::33) To DBXPR07MB319.eurprd07.prod.outlook.com (2a01:111:e400:941d::13) X-MS-Office365-Filtering-Correlation-Id: b4263b08-c211-40df-57fb-08d520009e7e X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(4534020)(4602075)(2017052603238); SRVR:DBXPR07MB319; X-Microsoft-Exchange-Diagnostics: 1; DBXPR07MB319; 3:PDfrqNr/0hphWakvk+VjYmPQk4ZLIEPp/NtJoZvJ9ea/34/AhSByaKroq4hAqpskthnuIUmuGc1RFhbjj7I/Bx3C0UaEuhpEY3Yv/MpGb4wHaLS0L2nc2mg1oPxcsAIHUN5+2G/CPMua+lG9UIWf1Mms7qwnb1TBN2EUp8tEJ11VI79UiB3NsdGeLwqwJrQu6An+VPivzLMChvNpYBnew8L2ue1agYrIEwRJrMCElCxYRk7l1We/kIJPjPK2DiGh; 25:Uz5/lGs63a7MMf4m1+yK3dFPxUgYZJSMvisvpcNZy6jA7lPqK3cjyCsKp4U1cwel8qqtiGMA/9GNZarEVc8v+VRgDrYjtiajIz9CpXqucxtfEd5WlrLmf3JQ6p44fqUczEx0QidTMyDI+3Ggv8oR6Jboi3JeaDd0dHUBjAJErHB2E9Uc4GXbIInxTNR4ZKN8E4Q9rFMesXsXWQ4UyiGl3M8ZP3+nB9aPt8nhKaAYz+S7eVdWY1ogznhcUKwcblligdy/YNMaRqG1Iz4ZSGXLp+dhO4OQPal2YKeys9gmM3el55RwR86wwnbkVsrqWE2WlPPTHiU/cFN09pS+vgWZnZDNI3PiWLqRG+Z1zzW8jQk=; 31:/TpTXjOYR/0Ng3J7osfGD85sUCxbTI5Pv8h1NxUNFgERbiORsG1eYvgOWEh7bYsB9rI+v4QIibLvEXV1RW2k3Wlr+BnmptptL7UEMICdQ8khN351x3LdpVlcovq8OvQf0CwizPftl5yVbR1qjvWd+//VNykMQhhW+RGExETmeP7E/TFmg/xH6aUf4XKgPX9ykz0laCR08cCOC1GKkQ3I1WPMcJ6tdm4rHufUJ256RU8= X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DBXPR07MB319: Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=simon.marchi@ericsson.com; X-Microsoft-Exchange-Diagnostics: 1; DBXPR07MB319; 20:K23VhYmTUvXY02C7waDXjCkFGB229QIpdE2aQGBXqe7UJyRj0yk6n2M0WBLl4XJ9otxDkzING1AUwvtRshwKG/i7xpBcwWT+qC6dGI2IEaMniIlbxsuV3DY+Su2D+GMYPBcx2c7vomr16dUPY5SAhWaScGe749Sg/1v6/rS0fvx8zYPi4REbDgppNc5xHh61Rm27JkbLzvbaj08Q/xJ49DnevGKl7qu/rKiuG5PaT6u9v9dlMr2PYGtIIDslunjVXBHnu7hdNg1GJNNOCbGONQqmaqWsTEvLODdjL8TCRdiWXgRPFo/3K0VDLEXOk5ExqHfQwPuA9c2pPUy65TaIVHeLNsDz3h9WxpBHD7Xc823iBvM2ULyeMtfMPwTr+Pokr6DbbMxYlQHmvcmcF9u0eWzOtdl1kSKqIOd8xgHIkt24FFhuMMssD5AcS0yf29SmEonUqYw1dEUdo9wgwCwmLDg02eRudURvuoTKInTow4SWyWK77yfhowJOpTg6jfg7; 4:m8+RN8oQe11HKpAOnt30UGx+3JDjJ6Q0WMz79ALy5XOaIC84aVo28aIDFSEuh2lkn/mFaze06Lnu9IMx3SQdKqHWI2ldXxdnbZLozN6H3A8JLwuE2xS/RokBYcp0KSLS6tO1pZsH6dCSWwGEJUEvFa+1hcMbpQFQXqIM4FnUDdGRhPPq/4oOl+w/UekGUmnt3JRvdp1Gw3/VaD2P8P8GxDrByY43nqNUli4hrBGDClYy3B+8JXDN2dtCWFJYkWFRPu+BeAN0f6hHk3yl4FxGkg== X-Exchange-Antispam-Report-Test: UriScan:; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(2401047)(8121501046)(5005006)(100000703101)(100105400095)(3231020)(93006095)(93001095)(3002001)(10201501046)(6041248)(20161123558100)(20161123564025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123562025)(20161123555025)(20161123560025)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:DBXPR07MB319; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:DBXPR07MB319; X-Forefront-PRVS: 04772EA191 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6009001)(376002)(39860400002)(346002)(189002)(199003)(54534003)(6916009)(16526018)(7736002)(2906002)(6666003)(47776003)(68736007)(4326008)(3846002)(478600001)(305945005)(66066001)(106356001)(36756003)(105586002)(53936002)(25786009)(2950100002)(6512007)(50226002)(2361001)(6116002)(2351001)(5003940100001)(16586007)(76176999)(33646002)(101416001)(5660300001)(6506006)(6486002)(316002)(50986999)(81156014)(81166006)(8936002)(8676002)(50466002)(97736004)(48376002)(86362001)(189998001); DIR:OUT; SFP:1101; SCL:1; SRVR:DBXPR07MB319; H:elxacz23q12.localdomain; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: ericsson.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DBXPR07MB319; 23:aeJIKObfBfp5srZe05ec6A0YKUIwV/w3Oec1bfuYGG?= =?us-ascii?Q?SJoRNEGnEJe5gwnUwcLTmYY2EWRkNU8XmsoD5UnwO6i0u615uKhOuwNeLCFP?= =?us-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yII/e+/4du3ifx9/SM83k+tA3H2x+JFyY/k2OjMIdUSmG2GbKngscUotsuvJjKgBV3aEH5OG1 SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 Oct 2017 01:42:16.8962 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b4263b08-c211-40df-57fb-08d520009e7e X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 92e84ceb-fbfd-47ab-be52-080c6b87953f X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBXPR07MB319 X-OriginatorOrg: ericsson.com X-IsSubscribed: yes From: Simon Marchi This patch changes target_desc::properties to be a vector of property objects. This way, we don't need to manually free the property members as well as the property objects themselves. gdb/ChangeLog: * target-descriptions.c (property_s): Remove typedef. (DEF_VEC_O (property_s)): Remove. (struct target_desc) : Make an std::vector. <~target_desc>: Don't manually free properties. (tdesc_property): Adjust. (set_tdesc_property): Adjust. (class print_c_tdesc) : Adjust. --- gdb/target-descriptions.c | 60 ++++++++++++++++------------------------------- 1 file changed, 20 insertions(+), 40 deletions(-) diff --git a/gdb/target-descriptions.c b/gdb/target-descriptions.c index 4f5e9d6..6f8a1c9 100644 --- a/gdb/target-descriptions.c +++ b/gdb/target-descriptions.c @@ -61,12 +61,15 @@ public: /* Types. */ -typedef struct property +struct property { - char *key; - char *value; -} property_s; -DEF_VEC_O(property_s); + property (const std::string &key_, const std::string &value_) + : key (key_), value (value_) + {} + + std::string key; + std::string value; +}; /* An individual register from a target description. */ @@ -397,7 +400,6 @@ struct target_desc : tdesc_element virtual ~target_desc () { struct tdesc_feature *feature; - struct property *prop; int ix; for (ix = 0; @@ -406,15 +408,6 @@ struct target_desc : tdesc_element delete feature; VEC_free (tdesc_feature_p, features); - for (ix = 0; - VEC_iterate (property_s, properties, ix, prop); - ix++) - { - xfree (prop->key); - xfree (prop->value); - } - - VEC_free (property_s, properties); VEC_free (arch_p, compatible); } @@ -432,7 +425,7 @@ struct target_desc : tdesc_element VEC(arch_p) *compatible = NULL; /* Any architecture-specific properties specified by the target. */ - VEC(property_s) *properties = NULL; + std::vector properties; /* The features associated with this target. */ VEC(tdesc_feature_p) *features = NULL; @@ -726,13 +719,9 @@ tdesc_compatible_p (const struct target_desc *target_desc, const char * tdesc_property (const struct target_desc *target_desc, const char *key) { - struct property *prop; - int ix; - - for (ix = 0; VEC_iterate (property_s, target_desc->properties, ix, prop); - ix++) - if (strcmp (prop->key, key) == 0) - return prop->value; + for (const property &prop : target_desc->properties) + if (prop.key == key) + return prop.value.c_str (); return NULL; } @@ -1803,20 +1792,13 @@ void set_tdesc_property (struct target_desc *target_desc, const char *key, const char *value) { - struct property *prop, new_prop; - int ix; - gdb_assert (key != NULL && value != NULL); - for (ix = 0; VEC_iterate (property_s, target_desc->properties, ix, prop); - ix++) - if (strcmp (prop->key, key) == 0) - internal_error (__FILE__, __LINE__, - _("Attempted to add duplicate property \"%s\""), key); + if (tdesc_property (target_desc, key) != NULL) + internal_error (__FILE__, __LINE__, + _("Attempted to add duplicate property \"%s\""), key); - new_prop.key = xstrdup (key); - new_prop.value = xstrdup (value); - VEC_safe_push (property_s, target_desc->properties, &new_prop); + target_desc->properties.emplace_back (key, value); } /* See arch/tdesc.h. */ @@ -1989,12 +1971,10 @@ public: if (ix) printf_unfiltered ("\n"); - for (ix = 0; VEC_iterate (property_s, e->properties, ix, prop); - ix++) - { - printf_unfiltered (" set_tdesc_property (result, \"%s\", \"%s\");\n", - prop->key, prop->value); - } + for (const property &prop : e->properties) + printf_unfiltered (" set_tdesc_property (result, \"%s\", \"%s\");\n", + prop.key.c_str (), prop.value.c_str ()); + printf_unfiltered (" struct tdesc_feature *feature;\n"); }