From patchwork Fri Jan 27 16:34:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 63800 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 991193857B98 for ; Fri, 27 Jan 2023 16:35:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 991193857B98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1674837311; bh=tw0xzkhaRlnTYrlN44thru6LpnSRhdlTRwON8IxO9yo=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=TF2/HR+ErG5FhXWbdHEI4Jw0inS5aoi7zxpS/BFpXovNzGvAGO0K+6yWRnXayqoq4 WiMT1ee/8Eri5vmCAk/Z6kxE34tvpyYQM9igM1VmKp3S+GVl7eef1YJXjDo+iA+m2Z aljF+nIHXYloM+XnBkmfn3DMF2JM3pORv7KV7uM8= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id A21B63857835 for ; Fri, 27 Jan 2023 16:34:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A21B63857835 Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-205-YnTiArsLOqW2Zx79IXbXPg-1; Fri, 27 Jan 2023 11:34:14 -0500 X-MC-Unique: YnTiArsLOqW2Zx79IXbXPg-1 Received: by mail-qk1-f200.google.com with SMTP id q21-20020a05620a0d9500b0070572ccdbf9so3299113qkl.10 for ; Fri, 27 Jan 2023 08:34:14 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tw0xzkhaRlnTYrlN44thru6LpnSRhdlTRwON8IxO9yo=; b=j79c7ypt3WzUGp4s7q9alrGs8zx1U6Hggt/GaARV9lNyQN9qpbxXD2TTpSApHB8LfR z+bV1BZnHxVkX5LreOWJV4rRe/sqatltZP3FYnk5aNrfmWsYvdBpIFKeff89iSE5I7yI jaRvcPteuKCjhSPBH+O6i9908EXD8hIRc34vvuBK9kmEbEsTdwrWZJglxRKHMdgVKwLW Ob6IJ94oNdoyev4LrfbFfvu74YescJ0SGA33qeOOuLatNPjOZ8eMojs83JBhybH0snUF oO7tHob4FC3A92qkMYxcBPgjbGMwfqakSEEnd5FZjcS7H6dj5hagtbtcmAMU6zkm8H6n 6IYw== X-Gm-Message-State: AFqh2kppajvsyqi1b/Rvyi3wEEgH3otDi0RZ8T+2Egi0mRTj1AC/KFZu fEodP6YEjenNOp8CzPTwYpm6+t0QQuzAyD/2EKE+c2vNMt7gDdxMBw0JW1khxGDCMLKRgwBeiQ1 jr7eJBl1mKG+BgVQUBrSpk856C5NZ7D+CQ7IM3fWDTH1ZuA/QzM4unDCYIrMk6Psi0ST0ssSAZA == X-Received: by 2002:ac8:5c86:0:b0:3a7:e9a2:4f4a with SMTP id r6-20020ac85c86000000b003a7e9a24f4amr38286989qta.8.1674837254233; Fri, 27 Jan 2023 08:34:14 -0800 (PST) X-Google-Smtp-Source: AMrXdXsU5Y1yakhj7t+TIzCjXJJbIpMmrMjoMjyRSePkS9191BQqjkQoasx3DmJKtQQrTvVhhO++2A== X-Received: by 2002:ac8:5c86:0:b0:3a7:e9a2:4f4a with SMTP id r6-20020ac85c86000000b003a7e9a24f4amr38286949qta.8.1674837253822; Fri, 27 Jan 2023 08:34:13 -0800 (PST) Received: from localhost (95.72.115.87.dyn.plus.net. [87.115.72.95]) by smtp.gmail.com with ESMTPSA id s15-20020ac85ccf000000b003b691385327sm1483514qta.6.2023.01.27.08.34.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Jan 2023 08:34:13 -0800 (PST) To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv3 3/3] gdb/tui: don't leak the known_window_types map Date: Fri, 27 Jan 2023 16:34:05 +0000 Message-Id: X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, 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 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Andrew Burgess via Gdb-patches From: Andrew Burgess Reply-To: Andrew Burgess Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" 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); - known_window_types->emplace (CMD_NAME, + known_window_types.emplace (CMD_NAME, make_standard_window); - known_window_types->emplace (DATA_NAME, + known_window_types.emplace (DATA_NAME, make_standard_window); - known_window_types->emplace (DISASSEM_NAME, + known_window_types.emplace (DISASSEM_NAME, make_standard_window); - known_window_types->emplace (STATUS_NAME, + known_window_types.emplace (STATUS_NAME, make_standard_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. */