From patchwork Wed Oct 9 03:44:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 98575 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 325BB384DED0 for ; Wed, 9 Oct 2024 03:45:28 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from omta38.uswest2.a.cloudfilter.net (omta38.uswest2.a.cloudfilter.net [35.89.44.37]) by sourceware.org (Postfix) with ESMTPS id 7811B3858D37 for ; Wed, 9 Oct 2024 03:44:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7811B3858D37 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 7811B3858D37 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=35.89.44.37 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1728445501; cv=none; b=eeihmFc+wlxnjxvwFybOvTvlNLw3+2lfMd/mj4K/1ANdC8g8zYSf4wFy+mf3Aw91zKewV7lKzRPlBiwGaNI4xRU3ZfM12I6my5GgJjJ+yI7orkeZVIDMcG3jg+r+chVomzhUahwIUmav2CTap1wjQVZK+2R9IoHYBP27qLV7MkA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1728445501; c=relaxed/simple; bh=8YmQxUebJzY5KGwjo4vNsKY6rN/bJOEw1LqI/yr4d2E=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=xkrD/CxcU7fCpEc1G53V0tttE9brf79lh/Tiu1JDzb0/CwS2LASxmCGjmu+Rbq1a3wWmlYA0EUdK9oXjB2oorVbV/PMklSxAp6c+bX45fpGSvA19jHB7TQXQO9b59IO5TB1hwnDAgG+Euq/6/esmitO1nl2rZoVMdVNPMqjBMeU= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from eig-obgw-5009a.ext.cloudfilter.net ([10.0.29.176]) by cmsmtp with ESMTPS id yAREs5er8umtXyNdBsgZGy; Wed, 09 Oct 2024 03:44:57 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id yNdAsbXAGGNqByNdAs3PP5; Wed, 09 Oct 2024 03:44:56 +0000 X-Authority-Analysis: v=2.4 cv=cqidkU4i c=1 sm=1 tr=0 ts=6705fc38 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=DAUX931o1VcA:10 a=ItBw4LHWJt0A:10 a=KZaEbWcjo41YybhmSzkA:9 a=6Ogn3jAGHLSNbaov7Orx:22 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Transfer-Encoding:MIME-Version:Message-ID:Date:Subject: Cc:To:From:Sender:Reply-To:Content-Type:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=KdAyc8rUKx3eet4z+1KGdDrazdxmuKiDKnpPq39mdSw=; b=Em1mnbl+KKKp/J0ciObneHz+Vs RLB6XUXC6fnIKyN6tzREXR7KOttQw0ODltFRcrqZpKDNm560N7QKHaBqs4655tTGgx0fUjhTM8wlu A61kGAn5qAROe71NSK11/YPhU; Received: from 97-122-122-36.hlrn.qwest.net ([97.122.122.36]:41932 helo=localhost.localdomain) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96.2) (envelope-from ) id 1syNd9-002DQ9-2i; Tue, 08 Oct 2024 21:44:55 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Use std::make_unique in more places Date: Tue, 8 Oct 2024 21:44:46 -0600 Message-ID: <20241009034446.795298-1-tom@tromey.com> X-Mailer: git-send-email 2.46.1 MIME-Version: 1.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 97.122.122.36 X-Source-L: No X-Exim-ID: 1syNd9-002DQ9-2i X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-122-36.hlrn.qwest.net (localhost.localdomain) [97.122.122.36]:41932 X-Source-Auth: tom+tromey.com X-Email-Count: 1 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfO3GVZ/bp+Nw4Cfbq/yKF9k9QgzC0bWqxpukVGOvEXTdrBba+zeEXzUY6INhgSKPrxzpfJdeC00FRdL9j8TsASACf+1J7BVRI61wlOhHPqb0Pto4Bhlq QnQ4ES3G1+q5rvq95mp4KqkWkHnX1/CX2tLuOXnZIJ/mcsXJiy0XHTRfnVHav3Qz7lzySvpmO1aorGzU4vM1x75VhJ6no+QUpfU= X-Spam-Status: No, score=-3019.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, 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.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~patchwork=sourceware.org@sourceware.org I searched for spots using ".reset (new ...)" and replaced most of these with std::make_unique. I think this is a bit cleaner and more idiomatic. Regression tested on x86-64 Fedora 40. Reviewed-By: Klaus Gerlicher --- gdb/breakpoint.c | 4 ++-- gdb/cli/cli-interp.c | 2 +- gdb/dwarf2/cu.c | 4 ++-- gdb/dwarf2/read.c | 16 ++++++++-------- gdb/jit.c | 7 ++++--- gdb/osdata.c | 2 +- gdb/parse.c | 2 +- gdb/regcache-dump.c | 15 ++++++++------- gdb/remote.c | 4 ++-- gdb/typeprint.c | 4 ++-- gdb/ui-out.c | 2 +- 11 files changed, 32 insertions(+), 30 deletions(-) diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index 10e2ef38523..3614e4df106 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -10533,9 +10533,9 @@ watch_command_1 (const char *arg, int accessflag, int from_tty, std::unique_ptr w; if (use_mask) - w.reset (new masked_watchpoint (nullptr, bp_type)); + w = std::make_unique (nullptr, bp_type); else - w.reset (new watchpoint (nullptr, bp_type)); + w = std::make_unique (nullptr, bp_type); /* At most one of thread or task can be set on a watchpoint. */ gdb_assert (thread == -1 || task == -1); diff --git a/gdb/cli/cli-interp.c b/gdb/cli/cli-interp.c index 18175735c4f..dbe2ed1b687 100644 --- a/gdb/cli/cli-interp.c +++ b/gdb/cli/cli-interp.c @@ -269,7 +269,7 @@ cli_interp_base::set_logging (ui_file_up logfile, bool logging_redirect, if (logfile != nullptr) { gdb_assert (m_saved_output == nullptr); - m_saved_output.reset (new saved_output_files); + m_saved_output = std::make_unique (); m_saved_output->out = gdb_stdout; m_saved_output->err = gdb_stderr; m_saved_output->log = gdb_stdlog; diff --git a/gdb/dwarf2/cu.c b/gdb/dwarf2/cu.c index 5cb22919c32..4cfef79b61f 100644 --- a/gdb/dwarf2/cu.c +++ b/gdb/dwarf2/cu.c @@ -77,9 +77,9 @@ dwarf2_cu::start_compunit_symtab (const char *name, const char *comp_dir, name_for_id = name_for_id_holder.c_str (); } - m_builder.reset (new struct buildsym_compunit + m_builder = std::make_unique (this->per_objfile->objfile, - name, comp_dir, name_for_id, lang (), low_pc)); + name, comp_dir, name_for_id, lang (), low_pc); list_in_scope = get_builder ()->get_file_symbols (); diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index ea31d8dd851..5f554f94b12 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -3968,7 +3968,7 @@ cutu_reader::init_tu_and_read_dwo_dies (dwarf2_per_cu_data *this_cu, /* If an existing_cu is provided, a dwarf2_cu must not exist for this_cu in per_objfile yet. */ gdb_assert (per_objfile->get_cu (this_cu) == nullptr); - m_new_cu.reset (new dwarf2_cu (this_cu, per_objfile)); + m_new_cu = std::make_unique (this_cu, per_objfile); cu = m_new_cu.get (); } @@ -4065,7 +4065,7 @@ cutu_reader::cutu_reader (dwarf2_per_cu_data *this_cu, thread-safe. */ gdb_assert (cache != nullptr || per_objfile->get_cu (this_cu) == nullptr); - m_new_cu.reset (new dwarf2_cu (this_cu, per_objfile)); + m_new_cu = std::make_unique (this_cu, per_objfile); cu = m_new_cu.get (); } @@ -4255,7 +4255,7 @@ cutu_reader::cutu_reader (dwarf2_per_cu_data *this_cu, /* This is cheap if the section is already read in. */ section->read (objfile); - m_new_cu.reset (new dwarf2_cu (this_cu, per_objfile)); + m_new_cu = std::make_unique (this_cu, per_objfile); begin_info_ptr = info_ptr = section->buffer + to_underlying (this_cu->sect_off); info_ptr = read_and_check_comp_unit_head (per_objfile, &m_new_cu->header, @@ -7364,7 +7364,7 @@ find_file_and_directory (struct die_info *die, struct dwarf2_cu *cu) res.set_name (make_unique_xstrdup (lbasename (res.get_name ()))); } - cu->per_cu->fnd.reset (new file_and_directory (std::move (res))); + cu->per_cu->fnd = std::make_unique (std::move (res)); return *cu->per_cu->fnd; } @@ -7610,11 +7610,11 @@ dwarf2_cu::setup_type_unit_groups (struct die_info *die) gdb_assert (tug_unshare->symtabs == NULL); gdb_assert (m_builder == nullptr); struct compunit_symtab *cust = tug_unshare->compunit_symtab; - m_builder.reset (new struct buildsym_compunit + m_builder = std::make_unique (cust->objfile (), "", cust->dirname (), cust->language (), - 0, cust)); + 0, cust); list_in_scope = get_builder ()->get_file_symbols (); } return; @@ -7664,11 +7664,11 @@ dwarf2_cu::setup_type_unit_groups (struct die_info *die) { gdb_assert (m_builder == nullptr); struct compunit_symtab *cust = tug_unshare->compunit_symtab; - m_builder.reset (new struct buildsym_compunit + m_builder = std::make_unique (cust->objfile (), "", cust->dirname (), cust->language (), - 0, cust)); + 0, cust); list_in_scope = get_builder ()->get_file_symbols (); auto &file_names = line_header->file_names (); diff --git a/gdb/jit.c b/gdb/jit.c index 78b3d984041..ed3b26cd4bd 100644 --- a/gdb/jit.c +++ b/gdb/jit.c @@ -222,7 +222,7 @@ static jiter_objfile_data * get_jiter_objfile_data (objfile *objf) { if (objf->jiter_data == nullptr) - objf->jiter_data.reset (new jiter_objfile_data ()); + objf->jiter_data = std::make_unique (); return objf->jiter_data.get (); } @@ -236,8 +236,9 @@ add_objfile_entry (struct objfile *objfile, CORE_ADDR entry, { gdb_assert (objfile->jited_data == nullptr); - objfile->jited_data.reset (new jited_objfile_data (entry, symfile_addr, - symfile_size)); + objfile->jited_data = std::make_unique (entry, + symfile_addr, + symfile_size); } /* Helper function for reading the global JIT descriptor from remote diff --git a/gdb/osdata.c b/gdb/osdata.c index e4d9b0bef97..e22c249c493 100644 --- a/gdb/osdata.c +++ b/gdb/osdata.c @@ -63,7 +63,7 @@ osdata_start_osdata (struct gdb_xml_parser *parser, gdb_xml_error (parser, _("Seen more than on osdata element")); char *type = (char *) xml_find_attribute (attributes, "type")->value.get (); - data->osdata.reset (new struct osdata (std::string (type))); + data->osdata = std::make_unique (std::string (type)); } /* Handle the start of a element. */ diff --git a/gdb/parse.c b/gdb/parse.c index e0837de7b01..ffefe6fee5f 100644 --- a/gdb/parse.c +++ b/gdb/parse.c @@ -100,7 +100,7 @@ void parser_state::mark_struct_expression (expr::structop_base_operation *op) { gdb_assert (parse_completion && m_completion_state == nullptr); - m_completion_state.reset (new expr_complete_structop (op)); + m_completion_state = std::make_unique (op); } /* Indicate that the current parser invocation is completing a tag. diff --git a/gdb/regcache-dump.c b/gdb/regcache-dump.c index 6b711bf6c2a..78924afb103 100644 --- a/gdb/regcache-dump.c +++ b/gdb/regcache-dump.c @@ -244,13 +244,13 @@ regcache_print (const char *args, enum regcache_dump_what what_to_dump) switch (what_to_dump) { case regcache_dump_none: - dump.reset (new register_dump_none (gdbarch)); + dump = std::make_unique (gdbarch); break; case regcache_dump_remote: - dump.reset (new register_dump_remote (gdbarch)); + dump = std::make_unique (gdbarch); break; case regcache_dump_groups: - dump.reset (new register_dump_groups (gdbarch)); + dump = std::make_unique (gdbarch); break; case regcache_dump_raw: case regcache_dump_cooked: @@ -258,15 +258,16 @@ regcache_print (const char *args, enum regcache_dump_what what_to_dump) auto dump_pseudo = (what_to_dump == regcache_dump_cooked); if (target_has_registers ()) - dump.reset (new register_dump_regcache (get_thread_regcache - (inferior_thread ()), - dump_pseudo)); + dump = (std::make_unique + (get_thread_regcache (inferior_thread ()), + dump_pseudo)); else { /* For the benefit of "maint print registers" & co when debugging an executable, allow dumping a regcache even when there is no thread selected / no registers. */ - dump.reset (new register_dump_reg_buffer (gdbarch, dump_pseudo)); + dump = std::make_unique (gdbarch, + dump_pseudo); } } break; diff --git a/gdb/remote.c b/gdb/remote.c index 53234915dea..fdd83ecbacc 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -3049,7 +3049,7 @@ get_remote_thread_info (thread_info *thread) gdb_assert (thread != NULL); if (thread->priv == NULL) - thread->priv.reset (new remote_thread_info); + thread->priv = std::make_unique (); return gdb::checked_static_cast (thread->priv.get ()); } @@ -7099,7 +7099,7 @@ static remote_inferior * get_remote_inferior (inferior *inf) { if (inf->priv == NULL) - inf->priv.reset (new remote_inferior); + inf->priv = std::make_unique (); return gdb::checked_static_cast (inf->priv.get ()); } diff --git a/gdb/typeprint.c b/gdb/typeprint.c index 274f6029a7e..456d8dcb00b 100644 --- a/gdb/typeprint.c +++ b/gdb/typeprint.c @@ -562,10 +562,10 @@ whatis_exp (const char *exp, int show) std::unique_ptr printer_holder; if (!flags.raw) { - table_holder.reset (new typedef_hash_table); + table_holder = std::make_unique (); flags.global_typedefs = table_holder.get (); - printer_holder.reset (new ext_lang_type_printers); + printer_holder = std::make_unique (); flags.global_printers = printer_holder.get (); } diff --git a/gdb/ui-out.c b/gdb/ui-out.c index 3330cc87ebb..41ce6efd14f 100644 --- a/gdb/ui-out.c +++ b/gdb/ui-out.c @@ -353,7 +353,7 @@ ui_out::table_begin (int nr_cols, int nr_rows, const std::string &tblid) internal_error (_("tables cannot be nested; table_begin found before \ previous table_end.")); - m_table_up.reset (new ui_out_table (level () + 1, nr_cols, tblid)); + m_table_up = std::make_unique (level () + 1, nr_cols, tblid); do_table_begin (nr_cols, nr_rows, tblid.c_str ()); }