From patchwork Mon Oct 9 02:43:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 23401 Received: (qmail 6852 invoked by alias); 9 Oct 2017 02:43:14 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 6800 invoked by uid 89); 9 Oct 2017 02:43:14 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: gproxy10-pub.mail.unifiedlayer.com Received: from gproxy10-pub.mail.unifiedlayer.com (HELO gproxy10-pub.mail.unifiedlayer.com) (69.89.20.226) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 09 Oct 2017 02:43:12 +0000 Received: from CMOut01 (unknown [10.0.90.82]) by gproxy10.mail.unifiedlayer.com (Postfix) with ESMTP id 059A8140522 for ; Sun, 8 Oct 2017 20:43:11 -0600 (MDT) Received: from box522.bluehost.com ([74.220.219.122]) by CMOut01 with id KEj71w00L2f2jeq01EjApW; Sun, 08 Oct 2017 20:43:10 -0600 X-Authority-Analysis: v=2.2 cv=K4VSJ2eI c=1 sm=1 tr=0 a=GsOEXm/OWkKvwdLVJsfwcA==:117 a=GsOEXm/OWkKvwdLVJsfwcA==:17 a=02M-m0pO-4AA:10 a=zstS-IiYAAAA:8 a=mDV3o1hIAAAA:8 a=teX5xLC7vk0jWGD3yCAA:9 a=4G6NA9xxw8l3yy4pmD5M:22 a=_FVE-zBwftR9WsbkzFJk:22 Received: from 75-166-4-236.hlrn.qwest.net ([75.166.4.236]:43016 helo=bapiya.localdomain) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.87) (envelope-from ) id 1e1O27-000vsd-EW; Sun, 08 Oct 2017 20:43:07 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 2/2] Remove free_splay_tree cleanup Date: Sun, 8 Oct 2017 20:43:00 -0600 Message-Id: <20171009024300.8346-3-tom@tromey.com> In-Reply-To: <20171009024300.8346-1-tom@tromey.com> References: <20171009024300.8346-1-tom@tromey.com> X-BWhitelist: no X-Exim-ID: 1e1O27-000vsd-EW X-Source-Sender: 75-166-4-236.hlrn.qwest.net (bapiya.localdomain) [75.166.4.236]:43016 X-Source-Auth: tom+tromey.com X-Email-Count: 3 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== X-Local-Domain: yes One spot in gdb uses a cleanup to free a splay tree. This patch introduces a unique_ptr specialization for this case. gdb/ChangeLog 2017-10-08 Tom Tromey * mi/mi-main.c (free_splay_tree): Remove. (list_available_thread_groups): Use splay_tree_up. * common/gdb_splay_tree.h: New file. --- gdb/ChangeLog | 6 ++++++ gdb/common/gdb_splay_tree.h | 38 ++++++++++++++++++++++++++++++++++++++ gdb/mi/mi-main.c | 24 ++++++++---------------- 3 files changed, 52 insertions(+), 16 deletions(-) create mode 100644 gdb/common/gdb_splay_tree.h diff --git a/gdb/common/gdb_splay_tree.h b/gdb/common/gdb_splay_tree.h new file mode 100644 index 0000000000..b0dca2115c --- /dev/null +++ b/gdb/common/gdb_splay_tree.h @@ -0,0 +1,38 @@ +/* GDB wrapper for splay trees. + + Copyright (C) 2017 Free Software Foundation, Inc. + + This file is part of GDB. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#ifndef GDB_SPLAY_TREE_H +#define GDB_SPLAY_TREE_H + +#include "splay-tree.h" + +struct gdb_splay_tree_deleter +{ + void operator() (splay_tree tree) const + { + splay_tree_delete (tree); + } +}; + +/* A unique pointer to a splay tree. */ + +typedef std::unique_ptr + gdb_splay_tree_up; + +#endif /* ! GDB_SPLAY_TREE_H */ diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c index 98fff4f1b5..b9d3cba931 100644 --- a/gdb/mi/mi-main.c +++ b/gdb/mi/mi-main.c @@ -46,7 +46,7 @@ #include "valprint.h" #include "inferior.h" #include "osdata.h" -#include "splay-tree.h" +#include "common/gdb_splay_tree.h" #include "tracepoint.h" #include "ctf.h" #include "ada-lang.h" @@ -720,13 +720,6 @@ splay_tree_int_comparator (splay_tree_key xa, splay_tree_key xb) } static void -free_splay_tree (void *xt) -{ - splay_tree t = (splay_tree) xt; - splay_tree_delete (t); -} - -static void list_available_thread_groups (const std::set &ids, int recurse) { struct osdata *data; @@ -739,7 +732,7 @@ list_available_thread_groups (const std::set &ids, int recurse) The vector contains information about all threads for the given pid. This is assigned an initial value to avoid "may be used uninitialized" warning from gcc. */ - splay_tree tree = NULL; + gdb_splay_tree_up tree; /* get_osdata will throw if it cannot return data. */ data = get_osdata ("processes"); @@ -750,10 +743,9 @@ list_available_thread_groups (const std::set &ids, int recurse) struct osdata *threads = get_osdata ("threads"); make_cleanup_osdata_free (threads); - tree = splay_tree_new (splay_tree_int_comparator, - NULL, - free_vector_of_osdata_items); - make_cleanup (free_splay_tree, tree); + tree.reset (splay_tree_new (splay_tree_int_comparator, + NULL, + free_vector_of_osdata_items)); for (ix_items = 0; VEC_iterate (osdata_item_s, threads->items, @@ -764,11 +756,11 @@ list_available_thread_groups (const std::set &ids, int recurse) int pid_i = strtoul (pid, NULL, 0); VEC (osdata_item_s) *vec = 0; - splay_tree_node n = splay_tree_lookup (tree, pid_i); + splay_tree_node n = splay_tree_lookup (tree.get (), pid_i); if (!n) { VEC_safe_push (osdata_item_s, vec, item); - splay_tree_insert (tree, pid_i, (splay_tree_value)vec); + splay_tree_insert (tree.get (), pid_i, (splay_tree_value)vec); } else { @@ -812,7 +804,7 @@ list_available_thread_groups (const std::set &ids, int recurse) if (recurse) { - splay_tree_node n = splay_tree_lookup (tree, pid_i); + splay_tree_node n = splay_tree_lookup (tree.get (), pid_i); if (n) { VEC (osdata_item_s) *children = (VEC (osdata_item_s) *) n->value;