From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id O3woKmBBh2otoDIAWB0awg (envelope-from ) for ; Thu, 20 Aug 2026 14:03:12 -0400 Received: by simark.ca (Postfix, from userid 112) id 8A5881E09E; Thu, 20 Aug 2026 14:03:12 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-5.3 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id BA3EF1E09E for ; Thu, 20 Aug 2026 14:03:10 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 414AE4BB1C2C for ; Thu, 20 Aug 2026 18:03:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 414AE4BB1C2C Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 6C1C04B9DB5C for ; Thu, 20 Aug 2026 18:02:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6C1C04B9DB5C Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=efficios.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=efficios.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 6C1C04B9DB5C Authentication-Results: sourceware.org; arc=none smtp.remote-ip=158.69.221.121 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1787248966; cv=none; b=VjP5FyJi4nM3Ncx5x9A/1AF4DYxXY0H0M238DL7rWT/kSvavAHmMDfuzKIap8uKYpKgeVyub3zESADGJoE4dWS2dNuEGdEW7uG53JiFbqDtXii7TnnaVoipegnJUWkKgbReqZMBd1tjQsGj97wd5J6vMaIodPsle5ixrejow1o4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1787248966; c=relaxed/simple; bh=Qhv+B1ar0EMJtF1Mi1yDHJ2CXSStoEA+m5+M/t2zWgk=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=FtlEenSy+3kHEpmAQ5iyK44VfC+EqypVJBZFLsLj3L2CELxElQkGBih70G78Lp8h5ojAtsFmzEqiqu1CqfxC7pj4N2gaG3uRtIE3STSC0FYeWaP1xHI/z0D/hpLieC+MxRNgq5Qzh38iepvfc35fSemasM4r9ZBCIn506qGCYO4= ARC-Authentication-Results: i=1; sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6C1C04B9DB5C Received: by simark.ca (Postfix) id CD3701E09E; Thu, 20 Aug 2026 14:02:44 -0400 (EDT) From: Simon Marchi To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH 2/2] gdb: introduce demangle_parse_info_up Date: Thu, 20 Aug 2026 14:02:34 -0400 Message-ID: <20260820180243.730651-2-simon.marchi@efficios.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260820180243.730651-1-simon.marchi@efficios.com> References: <20260820180243.730651-1-simon.marchi@efficios.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org 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 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_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 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 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 cp_canonicalize_string (const char *string) { - std::unique_ptr 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 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 +static demangle_parse_info_up mangled_name_to_comp (const char *mangled_name, int options, void **memory, gdb::unique_xmalloc_ptr *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 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 demangled_name; gdb::unique_xmalloc_ptr ret; struct demangle_component *ret_comp, *prev_comp, *cur_comp; - std::unique_ptr 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 demangled_name; gdb::unique_xmalloc_ptr ret; struct demangle_component *ret_comp; - std::unique_ptr 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 ret; struct demangle_component *ret_comp; - std::unique_ptr 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 info; gdb::unique_xmalloc_ptr 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; + /* 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> infos; + std::vector 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 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 cp_comp_to_string extern void cp_merge_demangle_parse_infos (struct demangle_parse_info *, struct demangle_component *, - std::unique_ptr); + 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 info; + demangle_parse_info_up info; std::string err; struct type *argtype; -- 2.55.0