From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from outbound-ss-820.bluehost.com (outbound-ss-820.bluehost.com [69.89.24.241]) by sourceware.org (Postfix) with ESMTPS id 5796B3858C74 for ; Fri, 10 Feb 2023 00:42:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5796B3858C74 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com Received: from cmgw11.mail.unifiedlayer.com (unknown [10.0.90.126]) by progateway2.mail.pro1.eigbox.com (Postfix) with ESMTP id BAC94100478A9 for ; Fri, 10 Feb 2023 00:42:26 +0000 (UTC) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTP id QHUgpjzqQ2s14QHUgpjiJt; Fri, 10 Feb 2023 00:42:26 +0000 X-Authority-Reason: nr=8 X-Authority-Analysis: v=2.4 cv=R7DGpfdX c=1 sm=1 tr=0 ts=63e592f2 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=dLZJa+xiwSxG16/P+YVxDGlgEgI=:19 a=m04uMKEZRckA:10:nop_rcvd_month_year a=Qbun_eYptAEA:10:endurance_base64_authed_username_1 a=WMbTGg78J-GDjbxqnkEA:9 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Transfer-Encoding:MIME-Version:Message-Id:Date:Subject: Cc:To:From:Sender:Reply-To:Content-Type:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=mGMmJjbCPi0IPQkYM/FuuBMaZpycf/QiNqY0CIH/Q/k=; b=Oj/MBtneUWYH8N6SN/71Dmxic3 CE2EEpev/u8uquWaYUWQ/HGIZ+r6EtC5zqD0qrdP4AZ1uq+d/89AiwnFyHffOFjr7FKM/lObeHe1X g/RHCfaQ9IfDxT59SDQQFT0Zg; Received: from 75-166-130-93.hlrn.qwest.net ([75.166.130.93]:43628 helo=localhost.localdomain) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1pQHUg-004M1b-Ih; Thu, 09 Feb 2023 17:42:26 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Use std::string in main_info Date: Thu, 9 Feb 2023 17:42:12 -0700 Message-Id: <20230210004212.1114508-1-tom@tromey.com> X-Mailer: git-send-email 2.39.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 75.166.130.93 X-Source-L: No X-Exim-ID: 1pQHUg-004M1b-Ih X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 75-166-130-93.hlrn.qwest.net (localhost.localdomain) [75.166.130.93]:43628 X-Source-Auth: tom+tromey.com X-Email-Count: 1 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3027.7 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,GIT_PATCH_0,JMQ_SPF_NEUTRAL,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: This changes main_info to use std::string. It removes some manual memory management. --- gdb/symtab.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/gdb/symtab.c b/gdb/symtab.c index 9d6ee388ca2..bd73c521b1a 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -104,16 +104,9 @@ static struct block_symbol struct main_info { - main_info () = default; - - ~main_info () - { - xfree (name_of_main); - } - /* Name of "main". */ - char *name_of_main = nullptr; + std::string name_of_main; /* Language of "main". */ @@ -6172,15 +6165,14 @@ set_main_name (const char *name, enum language lang) { struct main_info *info = get_main_info (); - if (info->name_of_main != NULL) + if (!info->name_of_main.empty ()) { - xfree (info->name_of_main); - info->name_of_main = NULL; + info->name_of_main.clear (); info->language_of_main = language_unknown; } if (name != NULL) { - info->name_of_main = xstrdup (name); + info->name_of_main = name; info->language_of_main = lang; } } @@ -6287,10 +6279,10 @@ main_name () { struct main_info *info = get_main_info (); - if (info->name_of_main == NULL) + if (info->name_of_main.empty ()) find_main_name (); - return info->name_of_main; + return info->name_of_main.c_str (); } /* Return the language of the main function. If it is not known, @@ -6301,7 +6293,7 @@ main_language (void) { struct main_info *info = get_main_info (); - if (info->name_of_main == NULL) + if (info->name_of_main.empty ()) find_main_name (); return info->language_of_main; -- 2.39.1