Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@efficios.com>
To: gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@efficios.com>
Subject: [PATCH 2/2] gdb: introduce demangle_parse_info_up
Date: Thu, 20 Aug 2026 14:02:34 -0400	[thread overview]
Message-ID: <20260820180243.730651-2-simon.marchi@efficios.com> (raw)
In-Reply-To: <20260820180243.730651-1-simon.marchi@efficios.com>

Introduce the demangle_parse_info_up type alias, as per our convention.
I find that more legible.

Change-Id: I31944c7d81c8fd7d16df4aac5691fad38ef40ac2
---
 gdb/cp-name-parser.y |  4 +--
 gdb/cp-support.c     | 59 +++++++++++++++++++-------------------------
 gdb/cp-support.h     | 10 +++++---
 gdb/python/py-type.c |  2 +-
 4 files changed, 36 insertions(+), 39 deletions(-)

diff --git a/gdb/cp-name-parser.y b/gdb/cp-name-parser.y
index aee5d8341519..1fd4a17db06a 100644
--- a/gdb/cp-name-parser.y
+++ b/gdb/cp-name-parser.y
@@ -2040,7 +2040,7 @@ cp_comp_to_string (struct demangle_component *result, int estimated_len)
 void
 cp_merge_demangle_parse_infos (struct demangle_parse_info *dest,
 			       struct demangle_component *target,
-			       std::unique_ptr<demangle_parse_info> src)
+			       demangle_parse_info_up src)
 
 {
   /* Copy the SRC's parse data into DEST.  */
@@ -2055,7 +2055,7 @@ cp_merge_demangle_parse_infos (struct demangle_parse_info *dest,
    error, NULL is returned, and an error message will be set in
    *ERRMSG.  */
 
-struct std::unique_ptr<demangle_parse_info>
+demangle_parse_info_up
 cp_demangled_name_to_comp (const char *demangled_name,
 			   std::string *errmsg)
 {
diff --git a/gdb/cp-support.c b/gdb/cp-support.c
index 36d7c8dd113e..b17f1e77d683 100644
--- a/gdb/cp-support.c
+++ b/gdb/cp-support.c
@@ -182,7 +182,6 @@ inspect_type (struct demangle_parse_info *info,
 	  long len;
 	  int is_anon;
 	  struct type *type;
-	  std::unique_ptr<demangle_parse_info> i;
 
 	  /* Get the real type of the typedef.  */
 	  type = check_typedef (otype);
@@ -253,8 +252,9 @@ inspect_type (struct demangle_parse_info *info,
 	     tree will contain pointers into NAME, so NAME cannot
 	     be free'd until all typedef conversion is done and
 	     the final result is converted into a string.  */
-	  i = cp_demangled_name_to_comp (name);
-	  if (i != NULL)
+	  if (demangle_parse_info_up i
+		= cp_demangled_name_to_comp (name);
+	      i != nullptr)
 	    {
 	      /* Merge the two trees.  */
 	      cp_merge_demangle_parse_infos (info, ret_comp, std::move (i));
@@ -596,12 +596,10 @@ cp_canonicalize_string_full (const char *string,
 			     canonicalization_ftype *finder,
 			     void *data)
 {
-  unsigned int estimated_len;
-  std::unique_ptr<demangle_parse_info> info;
+  unsigned int estimated_len = strlen (string) * 2;
+  demangle_parse_info_up info = cp_demangled_name_to_comp (string);
 
-  estimated_len = strlen (string) * 2;
-  info = cp_demangled_name_to_comp (string);
-  if (info != NULL)
+  if (info != nullptr)
     {
       /* Replace all the typedefs in the tree.  */
       replace_typedefs (info.get (), info->tree, finder, data);
@@ -641,17 +639,15 @@ cp_canonicalize_string_no_typedefs (const char *string)
 gdb::unique_xmalloc_ptr<char>
 cp_canonicalize_string (const char *string)
 {
-  std::unique_ptr<demangle_parse_info> info;
-  unsigned int estimated_len;
-
   if (cp_already_canonical (string))
     return nullptr;
 
-  info = cp_demangled_name_to_comp (string);
-  if (info == NULL)
+  demangle_parse_info_up info = cp_demangled_name_to_comp (string);
+
+  if (info == nullptr)
     return nullptr;
 
-  estimated_len = strlen (string) * 2;
+  unsigned int estimated_len = strlen (string) * 2;
   gdb::unique_xmalloc_ptr<char> us (cp_comp_to_string (info->tree,
 						       estimated_len));
 
@@ -677,7 +673,7 @@ cp_canonicalize_string (const char *string)
    freed when finished with the tree, or NULL if none was needed.
    OPTIONS will be passed to the demangler.  */
 
-static std::unique_ptr<demangle_parse_info>
+static demangle_parse_info_up
 mangled_name_to_comp (const char *mangled_name, int options,
 		      void **memory,
 		      gdb::unique_xmalloc_ptr<char> *demangled_p)
@@ -708,7 +704,7 @@ mangled_name_to_comp (const char *mangled_name, int options,
 
   /* If we could demangle the name, parse it to build the component
      tree.  */
-  std::unique_ptr<demangle_parse_info> info
+  demangle_parse_info_up info
     = cp_demangled_name_to_comp (demangled_name.get ());
 
   if (info == NULL)
@@ -727,13 +723,12 @@ cp_class_name_from_physname (const char *physname)
   gdb::unique_xmalloc_ptr<char> demangled_name;
   gdb::unique_xmalloc_ptr<char> ret;
   struct demangle_component *ret_comp, *prev_comp, *cur_comp;
-  std::unique_ptr<demangle_parse_info> info;
+  demangle_parse_info_up info
+    = mangled_name_to_comp (physname, DMGL_ANSI, &storage, &demangled_name);
   int done;
 
-  info = mangled_name_to_comp (physname, DMGL_ANSI,
-			       &storage, &demangled_name);
-  if (info == NULL)
-    return NULL;
+  if (info == nullptr)
+    return nullptr;
 
   done = 0;
   ret_comp = info->tree;
@@ -874,12 +869,11 @@ method_name_from_physname (const char *physname)
   gdb::unique_xmalloc_ptr<char> demangled_name;
   gdb::unique_xmalloc_ptr<char> ret;
   struct demangle_component *ret_comp;
-  std::unique_ptr<demangle_parse_info> info;
+  demangle_parse_info_up info
+    = mangled_name_to_comp (physname, DMGL_ANSI, &storage, &demangled_name);
 
-  info = mangled_name_to_comp (physname, DMGL_ANSI,
-			       &storage, &demangled_name);
-  if (info == NULL)
-    return NULL;
+  if (info == nullptr)
+    return nullptr;
 
   ret_comp = unqualified_name_from_comp (info->tree);
 
@@ -902,10 +896,9 @@ cp_func_name (const char *full_name)
 {
   gdb::unique_xmalloc_ptr<char> ret;
   struct demangle_component *ret_comp;
-  std::unique_ptr<demangle_parse_info> info;
+  demangle_parse_info_up info = cp_demangled_name_to_comp (full_name);
 
-  info = cp_demangled_name_to_comp (full_name);
-  if (!info)
+  if (info == nullptr)
     return nullptr;
 
   ret_comp = unqualified_name_from_comp (info->tree);
@@ -927,15 +920,15 @@ cp_remove_params_1 (const char *demangled_name, bool require_params)
 {
   bool done = false;
   struct demangle_component *ret_comp;
-  std::unique_ptr<demangle_parse_info> info;
   gdb::unique_xmalloc_ptr<char> ret;
 
   if (demangled_name == NULL)
     return NULL;
 
-  info = cp_demangled_name_to_comp (demangled_name);
-  if (info == NULL)
-    return NULL;
+  demangle_parse_info_up info = cp_demangled_name_to_comp (demangled_name);
+
+  if (info == nullptr)
+    return nullptr;
 
   /* First strip off any qualifiers, if we have a function or method.  */
   ret_comp = info->tree;
diff --git a/gdb/cp-support.h b/gdb/cp-support.h
index e495895afdbc..da8e777f516b 100644
--- a/gdb/cp-support.h
+++ b/gdb/cp-support.h
@@ -53,6 +53,10 @@ struct using_direct;
 
 #define CP_OPERATOR_LEN 8
 
+struct demangle_parse_info;
+
+using demangle_parse_info_up = std::unique_ptr<demangle_parse_info>;
+
 /* The result of parsing a name.  */
 
 struct demangle_parse_info
@@ -69,7 +73,7 @@ struct demangle_parse_info
 
   /* Any other objects referred to by this object, and whose storage
      lifetime must be linked.  */
-  std::vector<std::unique_ptr<demangle_parse_info>> infos;
+  std::vector<demangle_parse_info_up> infos;
 };
 
 
@@ -168,7 +172,7 @@ struct type *cp_find_type_baseclass_by_name (struct type *parent_type,
 
 /* Functions from cp-name-parser.y.  */
 
-extern std::unique_ptr<demangle_parse_info> cp_demangled_name_to_comp
+extern demangle_parse_info_up cp_demangled_name_to_comp
      (const char *demangled_name, std::string *errmsg = nullptr);
 
 /* Convert RESULT to a string.  ESTIMATED_LEN is used only as a guide
@@ -179,7 +183,7 @@ extern gdb::unique_xmalloc_ptr<char> cp_comp_to_string
 
 extern void cp_merge_demangle_parse_infos (struct demangle_parse_info *,
 					   struct demangle_component *,
-					   std::unique_ptr<demangle_parse_info>);
+					   demangle_parse_info_up);
 
 /* The list of "maint cplus" commands.  */
 
diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c
index 9dd0fe2ab37f..f374af23d2a2 100644
--- a/gdb/python/py-type.c
+++ b/gdb/python/py-type.c
@@ -925,7 +925,7 @@ typy_legacy_template_argument (struct type *type, const struct block *block,
 {
   int i;
   struct demangle_component *demangled;
-  std::unique_ptr<demangle_parse_info> info;
+  demangle_parse_info_up info;
   std::string err;
   struct type *argtype;
 
-- 
2.55.0


  reply	other threads:[~2026-08-20 18:03 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-20 18:02 [PATCH 1/2] gdb: add default parameter for cp_demangled_name_to_comp errmsg Simon Marchi
2026-08-20 18:02 ` Simon Marchi [this message]
2026-08-21 15:06   ` [PATCH 2/2] gdb: introduce demangle_parse_info_up Tom Tromey
2026-08-21 15:05 ` [PATCH 1/2] gdb: add default parameter for cp_demangled_name_to_comp errmsg Tom Tromey
2026-08-22  5:22   ` Simon Marchi

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=20260820180243.730651-2-simon.marchi@efficios.com \
    --to=simon.marchi@efficios.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