public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Andrew Burgess <aburgess@redhat.com>
To: gdb-patches@sourceware.org
Cc: Andrew Burgess <aburgess@redhat.com>
Subject: [PATCHv3 3/3] gdb/tui: don't leak the known_window_types map
Date: Fri, 27 Jan 2023 16:34:05 +0000	[thread overview]
Message-ID: <e5d6b00090e51bf8aa0559319bf1d87ed7067c3e.1674837139.git.aburgess@redhat.com> (raw)
In-Reply-To: <cover.1674837139.git.aburgess@redhat.com>

This commit finishes the task that was started in the previous
commit.

Now that all Python TUI window factories are correctly deleted when
the Python interpreter is shut down, we no longer need to dynamically
allocate the known_window_types map in tui-layout.c

This commit changes known_window_types to a statically allocated data
structure, removes the dynamic allocation from
initialize_known_windows, and then replaces lots of '->' with '.'
throughout this file.

There should be no user visible changes after this commit.
---
 gdb/tui/tui-layout.c | 41 +++++++++++++++++------------------------
 1 file changed, 17 insertions(+), 24 deletions(-)

diff --git a/gdb/tui/tui-layout.c b/gdb/tui/tui-layout.c
index ba7ec89973e..bb8356c5544 100644
--- a/gdb/tui/tui-layout.c
+++ b/gdb/tui/tui-layout.c
@@ -343,22 +343,17 @@ make_standard_window (const char *)
   return tui_win_list[V];
 }
 
-/* A map holding all the known window types, keyed by name.  Note that
-   this is heap-allocated and "leaked" at gdb exit.  This avoids
-   ordering issues with destroying elements in the map at shutdown.
-   In particular, destroying this map can occur after Python has been
-   shut down, causing crashes if any window destruction requires
-   running Python code.  */
+/* A map holding all the known window types, keyed by name.  */
 
-static window_types_map *known_window_types;
+static window_types_map known_window_types;
 
 /* See tui-layout.h.  */
 
 known_window_names_range
 all_known_window_names ()
 {
-  auto begin = known_window_names_iterator (known_window_types->begin ());
-  auto end = known_window_names_iterator (known_window_types->end ());
+  auto begin = known_window_names_iterator (known_window_types.begin ());
+  auto end = known_window_names_iterator (known_window_types.end ());
   return known_window_names_range (begin, end);
 }
 
@@ -371,8 +366,8 @@ tui_get_window_by_name (const std::string &name)
     if (name == window->name ())
       return window;
 
-  auto iter = known_window_types->find (name);
-  if (iter == known_window_types->end ())
+  auto iter = known_window_types.find (name);
+  if (iter == known_window_types.end ())
     error (_("Unknown window type \"%s\""), name.c_str ());
 
   tui_win_info *result = iter->second (name.c_str ());
@@ -386,20 +381,18 @@ tui_get_window_by_name (const std::string &name)
 static void
 initialize_known_windows ()
 {
-  known_window_types = new window_types_map;
-
-  known_window_types->emplace (SRC_NAME,
+  known_window_types.emplace (SRC_NAME,
 			       make_standard_window<SRC_WIN,
 						    tui_source_window>);
-  known_window_types->emplace (CMD_NAME,
+  known_window_types.emplace (CMD_NAME,
 			       make_standard_window<CMD_WIN, tui_cmd_window>);
-  known_window_types->emplace (DATA_NAME,
+  known_window_types.emplace (DATA_NAME,
 			       make_standard_window<DATA_WIN,
 						    tui_data_window>);
-  known_window_types->emplace (DISASSEM_NAME,
+  known_window_types.emplace (DISASSEM_NAME,
 			       make_standard_window<DISASSEM_WIN,
 						    tui_disasm_window>);
-  known_window_types->emplace (STATUS_NAME,
+  known_window_types.emplace (STATUS_NAME,
 			       make_standard_window<STATUS_WIN,
 						    tui_locator_window>);
 }
@@ -431,11 +424,11 @@ tui_register_window (const char *name, window_factory &&factory)
      this far then NAME must be a user defined window.  Remove any existing
      factory and replace it with this new version.  */
 
-  auto iter = known_window_types->find (name);
-  if (iter != known_window_types->end ())
-    known_window_types->erase (iter);
+  auto iter = known_window_types.find (name);
+  if (iter != known_window_types.end ())
+    known_window_types.erase (iter);
 
-  known_window_types->emplace (std::move (name_copy),
+  known_window_types.emplace (std::move (name_copy),
 			       std::move (factory));
 }
 
@@ -1216,8 +1209,8 @@ initialize_layouts ()
 static bool
 validate_window_name (const std::string &name)
 {
-  auto iter = known_window_types->find (name);
-  return iter != known_window_types->end ();
+  auto iter = known_window_types.find (name);
+  return iter != known_window_types.end ();
 }
 
 /* Implementation of the "tui new-layout" command.  */
-- 
2.25.4


  parent reply	other threads:[~2023-01-27 16:34 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-12 19:19 [PATCH 0/3] Python/TUI Window Creation / Destruction Fixes Andrew Burgess
2023-01-12 19:19 ` [PATCH 1/3] gdb/python: allow Python TUI windows to be replaced Andrew Burgess
2023-01-12 19:19 ` [PATCH 2/3] gdb/python: deallocate tui window factories at Python shut down Andrew Burgess
2023-01-12 19:19 ` [PATCH 3/3] gdb/tui: don't leak the known_window_types map Andrew Burgess
2023-01-25 13:56 ` [PATCHv2 0/3] Python/TUI Window Creation / Destruction Fixes Andrew Burgess
2023-01-25 13:56   ` [PATCHv2 1/3] gdb/python: allow Python TUI windows to be replaced Andrew Burgess
2023-01-25 13:56   ` [PATCHv2 2/3] gdb/python: deallocate tui window factories at Python shut down Andrew Burgess
2023-01-25 13:56   ` [PATCHv2 3/3] gdb/tui: don't leak the known_window_types map Andrew Burgess
2023-01-27 16:34   ` [PATCHv3 0/3] Python/TUI Window Creation / Destruction Fixes Andrew Burgess
2023-01-27 16:34     ` [PATCHv3 1/3] gdb/python: allow Python TUI windows to be replaced Andrew Burgess
2023-01-27 16:34     ` [PATCHv3 2/3] gdb/python: deallocate tui window factories at Python shut down Andrew Burgess
2023-01-27 16:34     ` Andrew Burgess [this message]
2023-02-13 12:32     ` [PATCHv3 0/3] Python/TUI Window Creation / Destruction Fixes Andrew Burgess
2023-02-13 14:11       ` Tom Tromey
2023-02-13 14:52         ` Andrew Burgess

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e5d6b00090e51bf8aa0559319bf1d87ed7067c3e.1674837139.git.aburgess@redhat.com \
    --to=aburgess@redhat.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).