public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] Convert main_info to type-safe registry API
@ 2019-05-08 22:07 Tom Tromey
0 siblings, 0 replies; only message in thread
From: Tom Tromey @ 2019-05-08 22:07 UTC (permalink / raw)
To: gdb-cvs
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=a32ad8c55c5c6bcdbc6773b6b825c4505fd44c16
commit a32ad8c55c5c6bcdbc6773b6b825c4505fd44c16
Author: Tom Tromey <tom@tromey.com>
Date: Tue Apr 9 20:26:09 2019 -0600
Convert main_info to type-safe registry API
This changes main_info to use the type-safe registry API.
gdb/ChangeLog
2019-05-08 Tom Tromey <tom@tromey.com>
* symtab.c (struct main_info): Add destructor and initializers.
(main_progspace_key): Move. Change type.
(get_main_info): Update.
(main_info_cleanup): Remove.
(_initialize_symtab): Update.
Diff:
---
gdb/ChangeLog | 8 ++++++++
gdb/symtab.c | 44 +++++++++++++++-----------------------------
2 files changed, 23 insertions(+), 29 deletions(-)
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index b5e4422..2642249 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,13 @@
2019-05-08 Tom Tromey <tom@tromey.com>
+ * symtab.c (struct main_info): Add destructor and initializers.
+ (main_progspace_key): Move. Change type.
+ (get_main_info): Update.
+ (main_info_cleanup): Remove.
+ (_initialize_symtab): Update.
+
+2019-05-08 Tom Tromey <tom@tromey.com>
+
* registry.h (DECLARE_REGISTRY): Define the _key class.
2019-05-08 Andrew Burgess <andrew.burgess@embecosm.com>
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 0e1f7ea..5d1c14b 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -95,23 +95,30 @@ static struct block_symbol
lookup_symbol_in_objfile (struct objfile *objfile, int block_index,
const char *name, const domain_enum domain);
-/* Program space key for finding name and language of "main". */
-
-static const struct program_space_data *main_progspace_key;
-
/* Type of the data stored on the program space. */
struct main_info
{
+ main_info () = default;
+
+ ~main_info ()
+ {
+ xfree (name_of_main);
+ }
+
/* Name of "main". */
- char *name_of_main;
+ char *name_of_main = nullptr;
/* Language of "main". */
- enum language language_of_main;
+ enum language language_of_main = language_unknown;
};
+/* Program space key for finding name and language of "main". */
+
+static const program_space_key<main_info> main_progspace_key;
+
/* Program space key for finding its symbol cache. */
static const struct program_space_data *symbol_cache_key;
@@ -5665,9 +5672,7 @@ make_source_files_completion_list (const char *text, const char *word)
static struct main_info *
get_main_info (void)
{
- struct main_info *info
- = (struct main_info *) program_space_data (current_program_space,
- main_progspace_key);
+ struct main_info *info = main_progspace_key.get (current_program_space);
if (info == NULL)
{
@@ -5677,28 +5682,12 @@ get_main_info (void)
gdb returned "main" as the name even if no function named
"main" was defined the program; and this approach lets us
keep compatibility. */
- info = XCNEW (struct main_info);
- info->language_of_main = language_unknown;
- set_program_space_data (current_program_space, main_progspace_key,
- info);
+ info = main_progspace_key.emplace (current_program_space);
}
return info;
}
-/* A cleanup to destroy a struct main_info when a progspace is
- destroyed. */
-
-static void
-main_info_cleanup (struct program_space *pspace, void *data)
-{
- struct main_info *info = (struct main_info *) data;
-
- if (info != NULL)
- xfree (info->name_of_main);
- xfree (info);
-}
-
static void
set_main_name (const char *name, enum language lang)
{
@@ -6048,9 +6037,6 @@ _initialize_symtab (void)
{
initialize_ordinary_address_classes ();
- main_progspace_key
- = register_program_space_data_with_cleanup (NULL, main_info_cleanup);
-
symbol_cache_key
= register_program_space_data_with_cleanup (NULL, symbol_cache_cleanup);
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2019-05-08 22:07 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-08 22:07 [binutils-gdb] Convert main_info to type-safe registry API Tom Tromey
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).