From patchwork Wed Apr 28 01:01:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 1470936 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (768-bit key; unprotected) header.d=tromey.com header.i=@tromey.com header.a=rsa-sha256 header.s=default header.b=DGSwUITl; dkim-atps=neutral Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FVL2Z3q58z9sWc for ; Wed, 28 Apr 2021 11:02:30 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AD10F39C0014; Wed, 28 Apr 2021 01:01:49 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from gateway20.websitewelcome.com (gateway20.websitewelcome.com [192.185.65.13]) by sourceware.org (Postfix) with ESMTPS id 96D4A39B8C18 for ; Wed, 28 Apr 2021 01:01:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 96D4A39B8C18 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=tom@tromey.com Received: from cm10.websitewelcome.com (cm10.websitewelcome.com [100.42.49.4]) by gateway20.websitewelcome.com (Postfix) with ESMTP id 98E79400D613A for ; Tue, 27 Apr 2021 19:50:19 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id bYaElqSzHL7DmbYaElsbBX; Tue, 27 Apr 2021 20:01:42 -0500 X-Authority-Reason: nr=8 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: 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:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=PPJo6w6GsW85V2YM9xSvtRMy/TwZ5t5gHqdtqwIRfVM=; b=DGSwUITlAc3vmEX7ECVOcoCNDx ug5AcS4JMaDBAr+WEK38Pdm35mcA79/NjWsY1xeY4xDEMgcBW2OHwxwSGuW6JvBqaFiAzozL8IWOS L+7Vvps4+yue/lEiJ3YT7x93G; Received: from 97-122-70-176.hlrn.qwest.net ([97.122.70.176]:32966 helo=localhost.localdomain) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94) (envelope-from ) id 1lbYaD-003tiR-WD; Tue, 27 Apr 2021 19:01:42 -0600 From: Tom Tromey To: gcc-patches@gcc.gnu.org Subject: [PATCH v2 10/21] libcc1: use unique_ptr more Date: Tue, 27 Apr 2021 19:01:08 -0600 Message-Id: <20210428010119.806184-11-tom@tromey.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210428010119.806184-1-tom@tromey.com> References: <20210428010119.806184-1-tom@tromey.com> 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 - gcc.gnu.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.70.176 X-Source-L: No X-Exim-ID: 1lbYaD-003tiR-WD X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-70-176.hlrn.qwest.net (localhost.localdomain) [97.122.70.176]:32966 X-Source-Auth: tom+tromey.com X-Email-Count: 11 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3032.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_SBL_CSS, SPF_HELO_PASS, SPF_NEUTRAL, TXREP, URIBL_CSS, URIBL_CSS_A autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tom Tromey Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" This changes libcc1 to use unique_ptr in a few more places, removing some manual memory management. libcc1/ChangeLog 2021-04-27 Tom Tromey * libcp1.cc (struct libcp1) : Use unique_ptr. (~libcp1): Remove. (libcp1_compile, libcp1_set_triplet_regexp) (libcp1_set_driver_filename): Update. * libcc1.cc (struct libcc1) : Use unique_ptr. (~libcc1): Remove. (libcc1_set_triplet_regexp, libcc1_set_driver_filename) (libcc1_compile): Update. --- libcc1/ChangeLog | 13 +++++++++++++ libcc1/libcc1.cc | 32 +++++++++++++------------------- libcc1/libcp1.cc | 32 +++++++++++++------------------- 3 files changed, 39 insertions(+), 38 deletions(-) diff --git a/libcc1/libcc1.cc b/libcc1/libcc1.cc index 3432f4e8b212..e00355955b6e 100644 --- a/libcc1/libcc1.cc +++ b/libcc1/libcc1.cc @@ -49,7 +49,6 @@ class libcc1_connection; struct libcc1 : public gcc_c_context { libcc1 (const gcc_base_vtable *, const gcc_c_fe_vtable *); - ~libcc1 (); // A convenience function to print something. void print (const char *str) @@ -57,7 +56,7 @@ struct libcc1 : public gcc_c_context this->print_function (this->print_datum, str); } - libcc1_connection *connection; + std::unique_ptr connection; gcc_c_oracle_function *binding_oracle; gcc_c_symbol_address_function *address_oracle; @@ -85,7 +84,9 @@ struct libcc1 : public gcc_c_context virtual ~compiler () { } - } *compilerp; + }; + + std::unique_ptr compilerp; /* Compiler to set by set_triplet_regexp. */ class compiler_triplet_regexp : public compiler @@ -142,8 +143,7 @@ public: libcc1::libcc1 (const gcc_base_vtable *v, const gcc_c_fe_vtable *cv) - : connection (NULL), - binding_oracle (NULL), + : binding_oracle (NULL), address_oracle (NULL), oracle_datum (NULL), print_function (NULL), @@ -157,12 +157,6 @@ libcc1::libcc1 (const gcc_base_vtable *v, c_ops = cv; } -libcc1::~libcc1 () -{ - delete connection; - delete compilerp; -} - // Enclose these functions in an anonymous namespace because they @@ -220,7 +214,7 @@ R rpc (struct gcc_c_context *s, Arg... rest) libcc1 *self = (libcc1 *) s; R result; - if (!cc1_plugin::call (self->connection, NAME, &result, rest...)) + if (!cc1_plugin::call (self->connection.get (), NAME, &result, rest...)) return 0; return result; } @@ -380,8 +374,8 @@ libcc1_set_triplet_regexp (struct gcc_base_context *s, { libcc1 *self = (libcc1 *) s; - delete self->compilerp; - self->compilerp = new libcc1::compiler_triplet_regexp (self, triplet_regexp); + self->compilerp.reset (new libcc1::compiler_triplet_regexp (self, + triplet_regexp)); return NULL; } @@ -391,9 +385,8 @@ libcc1_set_driver_filename (struct gcc_base_context *s, { libcc1 *self = (libcc1 *) s; - delete self->compilerp; - self->compilerp = new libcc1::compiler_driver_filename (self, - driver_filename); + self->compilerp.reset (new libcc1::compiler_driver_filename (self, + driver_filename)); return NULL; } @@ -464,7 +457,8 @@ fork_exec (libcc1 *self, char **argv, int spair_fds[2], int stderr_fds[2]) cc1_plugin::status result = cc1_plugin::FAIL; if (self->connection->send ('H') - && ::cc1_plugin::marshall (self->connection, GCC_C_FE_VERSION_1)) + && ::cc1_plugin::marshall (self->connection.get (), + GCC_C_FE_VERSION_1)) result = self->connection->wait_for_query (); close (spair_fds[0]); @@ -527,7 +521,7 @@ libcc1_compile (struct gcc_base_context *s, if (self->verbose) self->args.push_back ("-v"); - self->connection = new libcc1_connection (fds[0], stderr_fds[0], self); + self->connection.reset (new libcc1_connection (fds[0], stderr_fds[0], self)); cc1_plugin::callback_ftype *fun = cc1_plugin::callbackprint_function (this->print_datum, str); } - libcp1_connection *connection; + std::unique_ptr connection; gcc_cp_oracle_function *binding_oracle; gcc_cp_symbol_address_function *address_oracle; @@ -86,7 +85,9 @@ struct libcp1 : public gcc_cp_context virtual ~compiler () { } - } *compilerp; + }; + + std::unique_ptr compilerp; /* Compiler to set by set_triplet_regexp. */ class compiler_triplet_regexp : public compiler @@ -143,8 +144,7 @@ public: libcp1::libcp1 (const gcc_base_vtable *v, const gcc_cp_fe_vtable *cv) - : connection (NULL), - binding_oracle (NULL), + : binding_oracle (NULL), address_oracle (NULL), oracle_datum (NULL), print_function (NULL), @@ -158,12 +158,6 @@ libcp1::libcp1 (const gcc_base_vtable *v, cp_ops = cv; } -libcp1::~libcp1 () -{ - delete connection; - delete compilerp; -} - // Enclose these functions in an anonymous namespace because they @@ -243,7 +237,7 @@ R rpc (struct gcc_cp_context *s, Arg... rest) libcp1 *self = (libcp1 *) s; R result; - if (!cc1_plugin::call (self->connection, NAME, &result, rest...)) + if (!cc1_plugin::call (self->connection.get (), NAME, &result, rest...)) return 0; return result; } @@ -403,8 +397,8 @@ libcp1_set_triplet_regexp (struct gcc_base_context *s, { libcp1 *self = (libcp1 *) s; - delete self->compilerp; - self->compilerp = new libcp1::compiler_triplet_regexp (self, triplet_regexp); + self->compilerp.reset (new libcp1::compiler_triplet_regexp (self, + triplet_regexp)); return NULL; } @@ -414,9 +408,8 @@ libcp1_set_driver_filename (struct gcc_base_context *s, { libcp1 *self = (libcp1 *) s; - delete self->compilerp; - self->compilerp = new libcp1::compiler_driver_filename (self, - driver_filename); + self->compilerp.reset (new libcp1::compiler_driver_filename (self, + driver_filename)); return NULL; } @@ -487,7 +480,8 @@ fork_exec (libcp1 *self, char **argv, int spair_fds[2], int stderr_fds[2]) cc1_plugin::status result = cc1_plugin::FAIL; if (self->connection->send ('H') - && ::cc1_plugin::marshall (self->connection, GCC_CP_FE_VERSION_0)) + && ::cc1_plugin::marshall (self->connection.get (), + GCC_CP_FE_VERSION_0)) result = self->connection->wait_for_query (); close (spair_fds[0]); @@ -550,7 +544,7 @@ libcp1_compile (struct gcc_base_context *s, if (self->verbose) self->args.push_back ("-v"); - self->connection = new libcp1_connection (fds[0], stderr_fds[0], self); + self->connection.reset (new libcp1_connection (fds[0], stderr_fds[0], self)); cc1_plugin::callback_ftype *fun = cc1_plugin::callback