Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@ericsson.com>
To: <gdb-patches@sourceware.org>
Cc: Simon Marchi <simon.marchi@polymtl.ca>
Subject: [PATCH 01/10] Make target_desc::properties an std::vector
Date: Tue, 31 Oct 2017 01:42:00 -0000	[thread overview]
Message-ID: <1509414120-14659-2-git-send-email-simon.marchi@ericsson.com> (raw)
In-Reply-To: <1509414120-14659-1-git-send-email-simon.marchi@ericsson.com>

From: Simon Marchi <simon.marchi@polymtl.ca>

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) <properties>: Make an std::vector.
	<~target_desc>: Don't manually free properties.
	(tdesc_property): Adjust.
	(set_tdesc_property): Adjust.
	(class print_c_tdesc) <visit_pre>: 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<property> 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");
   }
 
-- 
2.7.4


  parent reply	other threads:[~2017-10-31  1:42 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-31  1:42 [PATCH 00/10] Use std::vector and std::string throughout target-descriptions.c Simon Marchi
2017-10-31  1:42 ` [PATCH 09/10] Make tdesc_type::u::u::fields an std::vector Simon Marchi
2017-11-02 10:02   ` Yao Qi
2017-11-02 13:27     ` Simon Marchi
2017-12-03 16:04       ` [PATCH 11/10] Split tdesc_type into multiple classes Simon Marchi
2017-12-05 16:46         ` Yao Qi
2017-12-05 21:42           ` Simon Marchi
2017-10-31  1:42 ` [PATCH 10/10] Make tdesc_arch_data::arch_regs an std::vector Simon Marchi
2017-10-31  1:42 ` [PATCH 06/10] Make tdesc_reg string fields std::string Simon Marchi
2017-11-02  9:43   ` Yao Qi
2017-11-02 13:24     ` Simon Marchi
2017-10-31  1:42 ` [PATCH 03/10] Make target_desc::features an std::vector Simon Marchi
2017-11-02  9:29   ` Yao Qi
2017-11-02 13:20     ` Simon Marchi
2017-10-31  1:42 ` Simon Marchi [this message]
2017-10-31  1:42 ` [PATCH 08/10] Make tdesc_type::name an std::string Simon Marchi
2017-10-31  1:42 ` [PATCH 04/10] Make tdesc_feature::name " Simon Marchi
2017-10-31  1:42 ` [PATCH 05/10] Make tdesc_feature::registers an std::vector Simon Marchi
2017-11-02  9:32   ` Yao Qi
2017-11-02 13:22     ` Simon Marchi
2017-10-31  1:42 ` [PATCH 07/10] Make tdesc_feature::types " Simon Marchi
2017-10-31  1:43 ` [PATCH 02/10] Make target_desc::compatible " Simon Marchi
2017-11-02 10:16 ` [PATCH 00/10] Use std::vector and std::string throughout target-descriptions.c Yao Qi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1509414120-14659-2-git-send-email-simon.marchi@ericsson.com \
    --to=simon.marchi@ericsson.com \
    --cc=gdb-patches@sourceware.org \
    --cc=simon.marchi@polymtl.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox