From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 3AFF3385B509 for ; Thu, 12 Jan 2023 19:19:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3AFF3385B509 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1673551175; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fVn5IOLw5BZIPWuRa0Az7BeeqKdJycOl4yREX59G6Ig=; b=Yi5uVCGkhrGIikic9LHden8QVu0Zf5iMQ3GO6NczKSX/NU1aua9sSfr4K8PgK8qUtLvBmo LNySkOnndTa+nk95+yO8j0rF2awUOYm7zZ5q3pdFfkphkUojRbwR+xqMHk2ezDh5UjcaLl qwU18tD4Keth1ZObOOdPAeW22wEefPQ= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-226-b6BGAw4RO2GAcayEbw7x1Q-1; Thu, 12 Jan 2023 14:19:34 -0500 X-MC-Unique: b6BGAw4RO2GAcayEbw7x1Q-1 Received: by mail-wm1-f71.google.com with SMTP id bi11-20020a05600c3d8b00b003d9ebf905c9so7086406wmb.5 for ; Thu, 12 Jan 2023 11:19:34 -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=fVn5IOLw5BZIPWuRa0Az7BeeqKdJycOl4yREX59G6Ig=; b=XgAgNQoPG8sDv2YNJKdmvG9llTGXv4YHfalKz5yXm1cIJRTu64YEIekZX+asuRBH6G KMfA0PBCfNtjWT6TWR44JMbztCDpsITYIT0+vQwX1awbh6jg0MuoP2HWjlPC2M2Oxtdl N6O6S2u8ZUDFQU/hANmrbDXkYjJcCx0MgytumTo4jKvWuTBwWm20kq6aBzdJu2TFgVKp 5omA1e2xT6x5K9/lEZSdN0FG5/2WuF6oDsday7awT5zVUoo3Ig393j8g/mqNyd5OTC2M buWNaW7vBZq3vSg8+PyDEVNidlhhkgWvVMsU1oye173f+0pb1NYS3f8LqX/Jk28xwka/ lHqA== X-Gm-Message-State: AFqh2kpgcpp3xcooADHnnCUi0u7fci9V3mGSvJIRpLBDByViXmpnHyBg FAl0oDAQo5FIWnOuSv1CyG8wbbMapgzokApFIv5Kcj46VvKXJtoKCNtNM1WASkxLF8AqVxAsCDE PMRKmGgBebKRhtuhGZBYbHct1PimQB2MwI4EQGNZBYLmS8wFjtKP689CUzudwFE+w2StNmAXKaw == X-Received: by 2002:a1c:6a16:0:b0:3c6:f732:bf6f with SMTP id f22-20020a1c6a16000000b003c6f732bf6fmr56149416wmc.13.1673551173371; Thu, 12 Jan 2023 11:19:33 -0800 (PST) X-Google-Smtp-Source: AMrXdXtp0aqXhK0FqfLT1p4AKpI/hxIaFUhqjfm+rTOzrEjkO2mgsrF/Wly24Npjs9plqmz5bVb01g== X-Received: by 2002:a1c:6a16:0:b0:3c6:f732:bf6f with SMTP id f22-20020a1c6a16000000b003c6f732bf6fmr56149407wmc.13.1673551173153; Thu, 12 Jan 2023 11:19:33 -0800 (PST) Received: from localhost (92.40.218.34.threembb.co.uk. [92.40.218.34]) by smtp.gmail.com with ESMTPSA id p5-20020a1c5445000000b003b4fe03c881sm1778895wmi.48.2023.01.12.11.19.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Jan 2023 11:19:32 -0800 (PST) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 3/3] gdb/tui: don't leak the known_window_types map Date: Thu, 12 Jan 2023 19:19:22 +0000 Message-Id: <52467d4e99bed2dfb4ef6fff7a7168c0e6f46f33.1673550880.git.aburgess@redhat.com> 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 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-11.6 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 List-Id: 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 | 37 +++++++++++++++---------------------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/gdb/tui/tui-layout.c b/gdb/tui/tui-layout.c index b895e00a80d..b65314ec30b 100644 --- a/gdb/tui/tui-layout.c +++ b/gdb/tui/tui-layout.c @@ -344,14 +344,9 @@ 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 std::unordered_map *known_window_types; +static std::unordered_map known_window_types; /* Helper function that returns a TUI window, given its name. */ @@ -362,8 +357,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 ()); @@ -377,20 +372,18 @@ tui_get_window_by_name (const std::string &name) static void initialize_known_windows () { - known_window_types = new std::unordered_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); } @@ -422,11 +415,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)); } @@ -1207,8 +1200,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