From 25eb2931f6f19d5ef48d240774bab488f6d52bf1 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Fri, 30 Dec 2022 11:23:43 -0700 Subject: [PATCH] Use std::string in main_info 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.30.2