Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Keith Seitz <keiths@redhat.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 5/9] Change decode_compound_collector to use std::vector
Date: Fri, 10 Aug 2018 23:32:00 -0000	[thread overview]
Message-ID: <20180810232534.481-6-keiths@redhat.com> (raw)
In-Reply-To: <20180810232534.481-1-keiths@redhat.com>

This patch changes decode_compound_collector to use std::vector instead of
VEC, eliminating a cleanup in the process.

gdb/ChangeLog:

	* linespec.c (decode_compound_collector::decode_compound_collector):
	Remove initialization for `m_symtabs'.
	(decode_compound_collector::release_symbols): Change return type
	to std::vector.  Update all callers.
	(class decode_compound_collector) <m_symbols>: Change type to
	std::vector.
	(lookup_prefix_sym): Change return type to std::vector.  Update all
	callers.
	(find_method): Change `sym_classes' parameter to std::vector.
	Update all callers.
	(find_linespec_symbols): Remove cleanup.
---
 gdb/ChangeLog  | 14 ++++++++++++++
 gdb/linespec.c | 47 ++++++++++++++++++-----------------------------
 2 files changed, 32 insertions(+), 29 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index f762196cbc..8e0bbd9a9f 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,19 @@
 YYYY-MM-DD  Keith Seitz  <keiths@redhat.com>
 
+	* linespec.c (decode_compound_collector::decode_compound_collector):
+	Remove initialization for `m_symtabs'.
+	(decode_compound_collector::release_symbols): Change return type
+	to std::vector.  Update all callers.
+	(class decode_compound_collector) <m_symbols>: Change type to
+	std::vector.
+	(lookup_prefix_sym): Change return type to std::vector.  Update all
+	callers.
+	(find_method): Change `sym_classes' parameter to std::vector.
+	Update all callers.
+	(find_linespec_symbols): Remove cleanup.
+
+YYYY-MM-DD  Keith Seitz  <keiths@redhat.com>
+
 	* linespec.c (struct linespec) <minimal_symbols>: Change type to
 	std::vector.  Update all users.
 	(struct collect_info) <minimal_symbols>: Likewise.
diff --git a/gdb/linespec.c b/gdb/linespec.c
index bc20001df9..c3e5f484b8 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -3494,7 +3494,6 @@ class decode_compound_collector
 {
 public:
   decode_compound_collector ()
-    : m_symbols (NULL)
   {
     m_unique_syms = htab_create_alloc (1, htab_hash_pointer,
 				       htab_eq_pointer, NULL,
@@ -3507,12 +3506,10 @@ public:
       htab_delete (m_unique_syms);
   }
 
-  /* Releases ownership of the collected symbols and returns them.  */
-  VEC (symbolp) *release_symbols ()
+  /* Return all symbols collected.  */
+  std::vector<symbol *> release_symbols ()
   {
-    VEC (symbolp) *res = m_symbols;
-    m_symbols = NULL;
-    return res;
+    return m_symbols;
   }
 
   /* Callable as a symbol_found_callback_ftype callback.  */
@@ -3524,7 +3521,7 @@ private:
   htab_t m_unique_syms;
 
   /* The result vector.  */
-  VEC (symbolp) *m_symbols;
+  std::vector<symbol *>  m_symbols;
 };
 
 bool
@@ -3547,7 +3544,7 @@ decode_compound_collector::operator () (symbol *sym)
   if (!*slot)
     {
       *slot = sym;
-      VEC_safe_push (symbolp, m_symbols, sym);
+      m_symbols.push_back (sym);
     }
 
   return true; /* Continue iterating.  */
@@ -3557,7 +3554,7 @@ decode_compound_collector::operator () (symbol *sym)
 
 /* Return any symbols corresponding to CLASS_NAME in FILE_SYMTABS.  */
 
-static VEC (symbolp) *
+static std::vector<symbol *>
 lookup_prefix_sym (struct linespec_state *state,
 		   std::vector<symtab *> *file_symtabs,
 		   const char *class_name)
@@ -3696,11 +3693,9 @@ find_superclass_methods (std::vector<struct type *> &&superclasses,
 static void
 find_method (struct linespec_state *self, std::vector<symtab *> *file_symtabs,
 	     const char *class_name, const char *method_name,
-	     VEC (symbolp) *sym_classes, std::vector<symbol *> *symbols,
+	     std::vector<symbol *> *sym_classes, std::vector<symbol *> *symbols,
 	     std::vector<bound_minimal_symbol> *minsyms)
 {
-  struct symbol *sym;
-  int ix;
   size_t last_result_len;
   std::vector<struct type *> superclass_vec;
   std::vector<const char *> result_names;
@@ -3708,10 +3703,8 @@ find_method (struct linespec_state *self, std::vector<symtab *> *file_symtabs,
 
   /* Sort symbols so that symbols with the same program space are next
      to each other.  */
-  qsort (VEC_address (symbolp, sym_classes),
-	 VEC_length (symbolp, sym_classes),
-	 sizeof (symbolp),
-	 compare_symbols);
+  qsort (sym_classes->data (), sym_classes->size (),
+	 sizeof (symbol *), compare_symbols);
 
   info.state = self;
   info.file_symtabs = file_symtabs;
@@ -3728,7 +3721,8 @@ find_method (struct linespec_state *self, std::vector<symtab *> *file_symtabs,
      because we collect data across the program space before deciding
      what to do.  */
   last_result_len = 0;
-  for (ix = 0; VEC_iterate (symbolp, sym_classes, ix, sym); ++ix)
+  unsigned int ix = 0;
+  for (const auto &sym : *sym_classes)
     {
       struct type *t;
       struct program_space *pspace;
@@ -3744,10 +3738,9 @@ find_method (struct linespec_state *self, std::vector<symtab *> *file_symtabs,
 
       /* Handle all items from a single program space at once; and be
 	 sure not to miss the last batch.  */
-      if (ix == VEC_length (symbolp, sym_classes) - 1
+      if (ix == sym_classes->size () - 1
 	  || (pspace
-	      != SYMTAB_PSPACE (symbol_symtab (VEC_index (symbolp, sym_classes,
-							  ix + 1)))))
+	      != SYMTAB_PSPACE (symbol_symtab (sym_classes->at (ix + 1)))))
 	{
 	  /* If we did not find a direct implementation anywhere in
 	     this program space, consider superclasses.  */
@@ -3763,6 +3756,7 @@ find_method (struct linespec_state *self, std::vector<symtab *> *file_symtabs,
 
 	  superclass_vec.clear ();
 	  last_result_len = result_names.size ();
+	  ++ix;
 	}
     }
 
@@ -3952,7 +3946,6 @@ find_linespec_symbols (struct linespec_state *state,
     {
       std::string klass, method;
       const char *last, *p, *scope_op;
-      VEC (symbolp) *classes;
 
       /* See if we can find a scope operator and break this symbol
 	 name into namespaces${SCOPE_OPERATOR}class_name and method_name.  */
@@ -3981,18 +3974,16 @@ find_linespec_symbols (struct linespec_state *state,
       method = last;
 
       /* Find a list of classes named KLASS.  */
-      classes = lookup_prefix_sym (state, file_symtabs, klass.c_str ());
-      struct cleanup *old_chain
-	= make_cleanup (VEC_cleanup (symbolp), &classes);
-
-      if (!VEC_empty (symbolp, classes))
+      std::vector<symbol *> classes
+	= lookup_prefix_sym (state, file_symtabs, klass.c_str ());
+      if (!classes.empty ())
 	{
 	  /* Now locate a list of suitable methods named METHOD.  */
 	  TRY
 	    {
 	      find_method (state, file_symtabs,
 			   klass.c_str (), method.c_str (),
-			   classes, symbols, minsyms);
+			   &classes, symbols, minsyms);
 	    }
 
 	  /* If successful, we're done.  If NOT_FOUND_ERROR
@@ -4004,8 +3995,6 @@ find_linespec_symbols (struct linespec_state *state,
 	    }
 	  END_CATCH
 	}
-
-      do_cleanups (old_chain);
     }
 }
 
-- 
2.13.6


  parent reply	other threads:[~2018-08-10 23:32 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-10 23:25 [PATCH 0/9] C++ Support for Compile Keith Seitz
2018-08-10 23:25 ` [PATCH 1/9] Change `file_symtabs' to std::vector Keith Seitz
2018-08-11 14:47   ` Tom Tromey
2018-08-17 17:56     ` Keith Seitz
2018-08-28 17:30       ` Tom Tromey
2018-08-10 23:25 ` [PATCH 3/9] Change `label_symbols' to std::vector in linespec.c structures Keith Seitz
2018-08-11 14:50   ` Tom Tromey
2018-08-10 23:25 ` [PATCH 2/9] Change `function_symbols' to std::vector Keith Seitz
2018-08-11 14:49   ` Tom Tromey
2018-08-17 17:59     ` Keith Seitz
2018-08-28 17:43       ` Tom Tromey
2018-08-10 23:31 ` [PATCH 7/9] Use block_symbol_d in linespec APIs Keith Seitz
2018-08-11 15:05   ` Tom Tromey
2018-08-17 18:04     ` Keith Seitz
2018-08-10 23:31 ` [PATCH 6/9] Remove VEC definitions from linespec.c Keith Seitz
2018-08-11 15:03   ` Tom Tromey
2018-08-10 23:32 ` [PATCH 4/9] Change `minimal_symbols' to std::vector in linespec.c structures Keith Seitz
2018-08-11 15:01   ` Tom Tromey
2018-08-17 18:00     ` Keith Seitz
2018-08-28 17:44       ` Tom Tromey
2018-08-10 23:32 ` Keith Seitz [this message]
2018-08-11 15:02   ` [PATCH 5/9] Change decode_compound_collector to use std::vector Tom Tromey
2018-08-17 18:04     ` Keith Seitz
2018-08-20  1:20       ` Simon Marchi
2018-08-20 13:28         ` Tom Tromey
2018-08-20 14:03           ` Simon Marchi
2018-08-28 17:46       ` Tom Tromey
2018-08-10 23:32 ` [PATCH 9/9] C++ compile support Keith Seitz
2018-08-11  7:22   ` Eli Zaretskii
2018-08-17 17:51     ` Keith Seitz
2018-08-17 18:57       ` Eli Zaretskii
2018-08-20 17:02         ` Keith Seitz
2018-08-12  0:17   ` Tom Tromey
2018-08-17 18:26     ` Keith Seitz
2018-08-28 17:52       ` Tom Tromey
2018-08-29 22:32         ` Keith Seitz
2021-03-24  1:04   ` Simon Marchi via Gdb-patches
2021-03-24 14:51     ` Keith Seitz via Gdb-patches
2021-03-24 15:06       ` Simon Marchi via Gdb-patches
2021-03-24 20:49         ` Keith Seitz via Gdb-patches
2021-04-01 18:03     ` Tom Tromey
2021-04-01 18:07       ` Luis Machado via Gdb-patches
2021-04-01 19:36       ` Keith Seitz via Gdb-patches
2018-08-10 23:34 ` [PATCH 8/9] Add new search_symbols_multiple API Keith Seitz
2018-08-11 20:49   ` Tom Tromey

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=20180810232534.481-6-keiths@redhat.com \
    --to=keiths@redhat.com \
    --cc=gdb-patches@sourceware.org \
    /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