From 4a91f820ef4d1301ea1a85c8de313a39457b266e Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Fri, 28 Apr 2023 14:27:12 -0400 Subject: [PATCH] gdb: store interps in an intrusive_list Use intrusive_list, instead of hand-made linked list. Change-Id: Idc857b40dfa3e3c35671045898331cca2c928097 --- gdb/interps.c | 18 ++++++------------ gdb/interps.h | 8 +++----- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/gdb/interps.c b/gdb/interps.c index a066c4acfed..54e1cb45db6 100644 --- a/gdb/interps.c +++ b/gdb/interps.c @@ -49,7 +49,7 @@ struct ui_interp_info DISABLE_COPY_AND_ASSIGN (ui_interp_info); /* Each top level has its own independent set of interpreters. */ - interp *interp_list = nullptr; + intrusive_list interp_list; interp *current_interpreter = nullptr; interp *top_level_interpreter = nullptr; @@ -132,8 +132,7 @@ interp_add (struct ui *ui, struct interp *interp) gdb_assert (interp_lookup_existing (ui, interp->name ()) == NULL); - interp->next = ui_interp.interp_list; - ui_interp.interp_list = interp; + ui_interp.interp_list.push_back (*interp); } /* This sets the current interpreter to be INTERP. If INTERP has not @@ -204,17 +203,12 @@ static struct interp * interp_lookup_existing (struct ui *ui, const char *name) { ui_interp_info &ui_interp = get_interp_info (ui); - struct interp *interp; - for (interp = ui_interp.interp_list; - interp != NULL; - interp = interp->next) - { - if (strcmp (interp->name (), name) == 0) - return interp; - } + for (interp &interp : ui_interp.interp_list) + if (strcmp (interp.name (), name) == 0) + return &interp; - return NULL; + return nullptr; } /* See interps.h. */ diff --git a/gdb/interps.h b/gdb/interps.h index 29248093c67..da78a5d89fa 100644 --- a/gdb/interps.h +++ b/gdb/interps.h @@ -22,6 +22,8 @@ #ifndef INTERPS_H #define INTERPS_H +#include "gdbsupport/intrusive_list.h" + struct ui_out; struct interp; struct ui; @@ -40,7 +42,7 @@ extern void interp_factory_register (const char *name, extern void interp_exec (struct interp *interp, const char *command); -class interp +class interp : public intrusive_list_node { public: explicit interp (const char *name); @@ -85,10 +87,6 @@ private: const char *m_name; public: - /* Interpreters are stored in a linked list, this is the next - one... */ - interp *next = nullptr; - /* Has the init method been run? */ bool inited = false; }; -- 2.30.2