From patchwork Sun Jan 3 18:26:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 1421903 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; dmarc=none (p=none dis=none) header.from=tromey.com 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=Jxx+hHuk; dkim-atps=neutral Received: from sourceware.org (unknown [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 4D86fk6WxQz9sSs for ; Mon, 4 Jan 2021 05:26:54 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id F3936386F837; Sun, 3 Jan 2021 18:26:37 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from gateway33.websitewelcome.com (gateway33.websitewelcome.com [192.185.146.97]) by sourceware.org (Postfix) with ESMTPS id 056D2386F80F for ; Sun, 3 Jan 2021 18:26:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 056D2386F80F 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 cm17.websitewelcome.com (cm17.websitewelcome.com [100.42.49.20]) by gateway33.websitewelcome.com (Postfix) with ESMTP id 62E534EAF9 for ; Sun, 3 Jan 2021 12:26:33 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id w85JkOsqCDT64w85JkVz8P; Sun, 03 Jan 2021 12:26:33 -0600 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=avRPhIb8Kh+JKfDzxhd13KVSsSc2+NBGP5Ff8hVVk/c=; b=Jxx+hHukxeez3jpq5RHt+kSZ5x AMQwg+ds0LM06dT+wLra7W0liLJ1lDITl6JP/LXvavVIrQzogY4hYRiQ3a6YEt/y/ufCPPvOL1rXz XIbsioV6h472JTwQf2W32GoIO; Received: from 97-122-81-39.hlrn.qwest.net ([97.122.81.39]:39392 helo=localhost.localdomain) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1kw85J-00234L-5N; Sun, 03 Jan 2021 11:26:33 -0700 From: Tom Tromey To: gcc-patches@gcc.gnu.org Subject: [PATCH 01/10] libcc1: use templates to unmarshall enums Date: Sun, 3 Jan 2021 11:26:22 -0700 Message-Id: <20210103182631.2316205-2-tom@tromey.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210103182631.2316205-1-tom@tromey.com> References: <20210103182631.2316205-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.81.39 X-Source-L: No X-Exim-ID: 1kw85J-00234L-5N X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-81-39.hlrn.qwest.net (localhost.localdomain) [97.122.81.39]:39392 X-Source-Auth: tom+tromey.com X-Email-Count: 2 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3032.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_SHORT, RCVD_IN_ABUSEAT, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_NEUTRAL, TXREP 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" Now that C++11 can be used in GCC, libcc1 can be changed to use templates and type traits to handle unmarshalling all kinds of enums. libcc1/ChangeLog 2021-01-03 Tom Tromey * marshall.hh (cc1_plugin::unmarshall): Use type traits. * marshall-cp.hh (cc1_plugin::unmarshall): Remove overloads. * marshall-c.hh: Remove. * libcc1plugin.cc: Update includes. * libcc1.cc: Update includes. --- libcc1/ChangeLog | 8 ++++++ libcc1/libcc1.cc | 3 ++- libcc1/libcc1plugin.cc | 3 ++- libcc1/marshall-c.hh | 59 ------------------------------------------ libcc1/marshall-cp.hh | 40 ---------------------------- libcc1/marshall.hh | 26 +++++++++++++++---- 6 files changed, 33 insertions(+), 106 deletions(-) delete mode 100644 libcc1/marshall-c.hh diff --git a/libcc1/libcc1.cc b/libcc1/libcc1.cc index c675624ee1c..1838f2e5577 100644 --- a/libcc1/libcc1.cc +++ b/libcc1/libcc1.cc @@ -29,7 +29,7 @@ along with GCC; see the file COPYING3. If not see #include #include #include -#include "marshall-c.hh" +#include "marshall.hh" #include "rpc.hh" #include "connection.hh" #include "names.hh" @@ -39,6 +39,7 @@ along with GCC; see the file COPYING3. If not see #include "findcomp.hh" #include "compiler-name.hh" #include "intl.h" +#include "gcc-c-interface.h" struct libcc1; diff --git a/libcc1/libcc1plugin.cc b/libcc1/libcc1plugin.cc index 241a8158b98..a0fb61f2e46 100644 --- a/libcc1/libcc1plugin.cc +++ b/libcc1/libcc1plugin.cc @@ -63,8 +63,9 @@ #include "callbacks.hh" #include "connection.hh" -#include "marshall-c.hh" +#include "marshall.hh" #include "rpc.hh" +#include "gcc-c-interface.h" #ifdef __GNUC__ #pragma GCC visibility push(default) diff --git a/libcc1/marshall-c.hh b/libcc1/marshall-c.hh deleted file mode 100644 index a617654bd5e..00000000000 --- a/libcc1/marshall-c.hh +++ /dev/null @@ -1,59 +0,0 @@ -/* Marshalling and unmarshalling of C-specific types. - Copyright (C) 2014-2020 Free Software Foundation, Inc. - -This file is part of GCC. - -GCC 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, or (at your option) any later -version. - -GCC 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 GCC; see the file COPYING3. If not see -. */ - -#ifndef CC1_PLUGIN_MARSHALL_C_HH -#define CC1_PLUGIN_MARSHALL_C_HH - -#include "marshall.hh" -#include "gcc-c-interface.h" - -namespace cc1_plugin -{ - status - unmarshall (connection *conn, enum gcc_c_symbol_kind *result) - { - protocol_int p; - if (!unmarshall_intlike (conn, &p)) - return FAIL; - *result = (enum gcc_c_symbol_kind) p; - return OK; - } - - status - unmarshall (connection *conn, enum gcc_c_oracle_request *result) - { - protocol_int p; - if (!unmarshall_intlike (conn, &p)) - return FAIL; - *result = (enum gcc_c_oracle_request) p; - return OK; - } - - status - unmarshall (connection *conn, enum gcc_qualifiers *result) - { - protocol_int p; - if (!unmarshall_intlike (conn, &p)) - return FAIL; - *result = (enum gcc_qualifiers) p; - return OK; - } -} - -#endif // CC1_PLUGIN_MARSHALL_C_HH diff --git a/libcc1/marshall-cp.hh b/libcc1/marshall-cp.hh index 23756c44b5f..e921ab0d3a9 100644 --- a/libcc1/marshall-cp.hh +++ b/libcc1/marshall-cp.hh @@ -25,46 +25,6 @@ along with GCC; see the file COPYING3. If not see namespace cc1_plugin { - status - unmarshall (connection *conn, enum gcc_cp_symbol_kind *result) - { - protocol_int p; - if (!unmarshall_intlike (conn, &p)) - return FAIL; - *result = (enum gcc_cp_symbol_kind) p; - return OK; - } - - status - unmarshall (connection *conn, enum gcc_cp_oracle_request *result) - { - protocol_int p; - if (!unmarshall_intlike (conn, &p)) - return FAIL; - *result = (enum gcc_cp_oracle_request) p; - return OK; - } - - status - unmarshall (connection *conn, enum gcc_cp_qualifiers *result) - { - protocol_int p; - if (!unmarshall_intlike (conn, &p)) - return FAIL; - *result = (enum gcc_cp_qualifiers) p; - return OK; - } - - status - unmarshall (connection *conn, enum gcc_cp_ref_qualifiers *result) - { - protocol_int p; - if (!unmarshall_intlike (conn, &p)) - return FAIL; - *result = (enum gcc_cp_ref_qualifiers) p; - return OK; - } - // Send a gcc_vbase_array marker followed by the array. status marshall (connection *conn, const gcc_vbase_array *a) diff --git a/libcc1/marshall.hh b/libcc1/marshall.hh index fb4e9a484d7..7fadbeaa5ac 100644 --- a/libcc1/marshall.hh +++ b/libcc1/marshall.hh @@ -20,6 +20,8 @@ along with GCC; see the file COPYING3. If not see #ifndef CC1_PLUGIN_MARSHALL_HH #define CC1_PLUGIN_MARSHALL_HH +#include + #include "status.hh" #include "gcc-interface.h" @@ -59,17 +61,31 @@ namespace cc1_plugin } // A template function that can handle unmarshalling various integer - // objects from the connection. Note that this can't be - // instantiated for enum types. Note also that there's no way at - // the protocol level to distinguish different int types. + // objects from the connection. Note that there's no way at the + // protocol level to distinguish different int types. + template + status unmarshall (connection *conn, T *scalar, + typename std::enable_if::value, T>::type * = 0) + { + protocol_int result; + + if (!unmarshall_intlike (conn, &result)) + return FAIL; + *scalar = (T) result; + return OK; + } + + // A template function that can handle unmarshalling various enum + // objects from the connection. template - status unmarshall (connection *conn, T *scalar) + status unmarshall (connection *conn, T *e_val, + typename std::enable_if::value, T>::type * = 0) { protocol_int result; if (!unmarshall_intlike (conn, &result)) return FAIL; - *scalar = result; + *e_val = (T) result; return OK; } From patchwork Sun Jan 3 18:26:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 1421901 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; dmarc=none (p=none dis=none) header.from=tromey.com 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=g4kpgmLf; dkim-atps=neutral Received: from sourceware.org (server2.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 4D86fY4jmvz9sSs for ; Mon, 4 Jan 2021 05:26:45 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 14F64386F824; Sun, 3 Jan 2021 18:26:37 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from gateway24.websitewelcome.com (gateway24.websitewelcome.com [192.185.51.253]) by sourceware.org (Postfix) with ESMTPS id F1089386F804 for ; Sun, 3 Jan 2021 18:26:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org F1089386F804 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 cm11.websitewelcome.com (cm11.websitewelcome.com [100.42.49.5]) by gateway24.websitewelcome.com (Postfix) with ESMTP id 8F99D18DC for ; Sun, 3 Jan 2021 12:26:33 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id w85JkzdsOnPrxw85JkApAS; Sun, 03 Jan 2021 12:26:33 -0600 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=6F2ywLRSRB+eIbKNWwTEKqVFxmUFbjaCLyzIJOz3HxE=; b=g4kpgmLfmVqu3z6hRhE2rBUW2H av3WRc3GgxxsBRg2oH7K3m3Es7Qv2MZOxV7aNsQvinQoLpFNeH3xTIT0S92YKnTlsVizu8yZ+K/ED oPDrL/DxjoulY1ABt3+roJ+wK; Received: from 97-122-81-39.hlrn.qwest.net ([97.122.81.39]:39392 helo=localhost.localdomain) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1kw85J-00234L-CB; Sun, 03 Jan 2021 11:26:33 -0700 From: Tom Tromey To: gcc-patches@gcc.gnu.org Subject: [PATCH 02/10] libcc1: use "override" Date: Sun, 3 Jan 2021 11:26:23 -0700 Message-Id: <20210103182631.2316205-3-tom@tromey.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210103182631.2316205-1-tom@tromey.com> References: <20210103182631.2316205-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.81.39 X-Source-L: No X-Exim-ID: 1kw85J-00234L-CB X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-81-39.hlrn.qwest.net (localhost.localdomain) [97.122.81.39]:39392 X-Source-Auth: tom+tromey.com X-Email-Count: 3 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3030.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_ABUSEAT, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_BL_SPAMCOP_NET, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_NEUTRAL, TXREP, T_FILL_THIS_FORM_SHORT 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 "override" where appropriate. libcc1/ChangeLog 2021-01-03 Tom Tromey * libcp1.cc (class compiler_triplet_regexp) (class compiler_driver_filename, class libcp1_connection): Use "override". * libcc1.cc (class compiler_triplet_regexp) (class compiler_driver_filename, class libcc1_connection): Use "override". --- libcc1/ChangeLog | 9 +++++++++ libcc1/libcc1.cc | 6 +++--- libcc1/libcp1.cc | 6 +++--- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/libcc1/libcc1.cc b/libcc1/libcc1.cc index 1838f2e5577..4fb3084c24c 100644 --- a/libcc1/libcc1.cc +++ b/libcc1/libcc1.cc @@ -93,7 +93,7 @@ struct libcc1 : public gcc_c_context private: std::string triplet_regexp_; public: - virtual char *find (std::string &compiler) const; + char *find (std::string &compiler) const override; compiler_triplet_regexp (libcc1 *self, std::string triplet_regexp) : compiler (self), triplet_regexp_ (triplet_regexp) { @@ -109,7 +109,7 @@ struct libcc1 : public gcc_c_context private: std::string driver_filename_; public: - virtual char *find (std::string &compiler) const; + char *find (std::string &compiler) const override; compiler_driver_filename (libcc1 *self, std::string driver_filename) : compiler (self), driver_filename_ (driver_filename) { @@ -132,7 +132,7 @@ public: { } - virtual void print (const char *buf) + void print (const char *buf) override { back_ptr->print (buf); } diff --git a/libcc1/libcp1.cc b/libcc1/libcp1.cc index e8aceb14604..5fa6a6742f5 100644 --- a/libcc1/libcp1.cc +++ b/libcc1/libcp1.cc @@ -94,7 +94,7 @@ struct libcp1 : public gcc_cp_context private: std::string triplet_regexp_; public: - virtual char *find (std::string &compiler) const; + char *find (std::string &compiler) const override; compiler_triplet_regexp (libcp1 *self, std::string triplet_regexp) : compiler (self), triplet_regexp_ (triplet_regexp) { @@ -110,7 +110,7 @@ struct libcp1 : public gcc_cp_context private: std::string driver_filename_; public: - virtual char *find (std::string &compiler) const; + char *find (std::string &compiler) const override; compiler_driver_filename (libcp1 *self, std::string driver_filename) : compiler (self), driver_filename_ (driver_filename) { @@ -133,7 +133,7 @@ public: { } - virtual void print (const char *buf) + void print (const char *buf) override { back_ptr->print (buf); } From patchwork Sun Jan 3 18:26:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 1421902 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=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=tromey.com 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=wpHmWMTh; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 4D86ff3yCmz9sSs for ; Mon, 4 Jan 2021 05:26:50 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8BE38386F822; Sun, 3 Jan 2021 18:26:37 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from gateway22.websitewelcome.com (gateway22.websitewelcome.com [192.185.47.168]) by sourceware.org (Postfix) with ESMTPS id 4F907386F81A for ; Sun, 3 Jan 2021 18:26:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 4F907386F81A 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 cm12.websitewelcome.com (cm12.websitewelcome.com [100.42.49.8]) by gateway22.websitewelcome.com (Postfix) with ESMTP id C265D9C71 for ; Sun, 3 Jan 2021 12:26:33 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id w85JkQduZiQiZw85Jk7J5L; Sun, 03 Jan 2021 12:26:33 -0600 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=zafFIAhrJAqUrKfc39GCWljv3+1EuvEzltUQo1rkFww=; b=wpHmWMTh/PPQk2P/0YifgKR3wS yiPOwBNse1ZlHXPzXWW2HPDmHy0stOa9oLYmRyBx1n395UClT10+jxXhTUCehPOLqOhrZUuSwAQxO v6BM0I3uPG+CNApVIVCxRXUtf; Received: from 97-122-81-39.hlrn.qwest.net ([97.122.81.39]:39392 helo=localhost.localdomain) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1kw85J-00234L-J3; Sun, 03 Jan 2021 11:26:33 -0700 From: Tom Tromey To: gcc-patches@gcc.gnu.org Subject: [PATCH 03/10] libcc1: inline some simple methods Date: Sun, 3 Jan 2021 11:26:24 -0700 Message-Id: <20210103182631.2316205-4-tom@tromey.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210103182631.2316205-1-tom@tromey.com> References: <20210103182631.2316205-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.81.39 X-Source-L: No X-Exim-ID: 1kw85J-00234L-J3 X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-81-39.hlrn.qwest.net (localhost.localdomain) [97.122.81.39]:39392 X-Source-Auth: tom+tromey.com X-Email-Count: 4 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3030.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_ABUSEAT, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_BL_SPAMCOP_NET, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_NEUTRAL, TXREP 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 inline a trivial method and to use the default constructor. libcc1/ChangeLog 2021-01-03 Tom Tromey * connection.hh (~connection): Use default. (print): Inline. * connection.cc (cc1_plugin::connection::~connection) (cc1_plugin::connection::print): Remove definitions. --- libcc1/ChangeLog | 7 +++++++ libcc1/connection.cc | 9 --------- libcc1/connection.hh | 6 ++++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/libcc1/connection.cc b/libcc1/connection.cc index a91dfc8c5e2..01cda378613 100644 --- a/libcc1/connection.cc +++ b/libcc1/connection.cc @@ -27,15 +27,6 @@ along with GCC; see the file COPYING3. If not see #include "connection.hh" #include "rpc.hh" -cc1_plugin::connection::~connection () -{ -} - -void -cc1_plugin::connection::print (const char *) -{ -} - cc1_plugin::status cc1_plugin::connection::send (char c) { diff --git a/libcc1/connection.hh b/libcc1/connection.hh index f7cc5319a24..d8562a26154 100644 --- a/libcc1/connection.hh +++ b/libcc1/connection.hh @@ -46,7 +46,7 @@ namespace cc1_plugin { } - virtual ~connection (); + virtual ~connection () = default; // Send a single character. This is used to introduce various // higher-level protocol elements. @@ -89,7 +89,9 @@ namespace cc1_plugin m_callbacks.add_callback (name, func); } - virtual void print (const char *); + virtual void print (const char *) + { + } private: From patchwork Sun Jan 3 18:26:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 1421907 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; dmarc=none (p=none dis=none) header.from=tromey.com 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=NV8IdIdC; dkim-atps=neutral Received: from sourceware.org (unknown [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 4D86g61MrQz9sSs for ; Mon, 4 Jan 2021 05:27:14 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 316C73870858; Sun, 3 Jan 2021 18:26:40 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from gateway22.websitewelcome.com (gateway22.websitewelcome.com [192.185.47.168]) by sourceware.org (Postfix) with ESMTPS id 14AAB386F822 for ; Sun, 3 Jan 2021 18:26:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 14AAB386F822 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 cm16.websitewelcome.com (cm16.websitewelcome.com [100.42.49.19]) by gateway22.websitewelcome.com (Postfix) with ESMTP id 0DFEB782 for ; Sun, 3 Jan 2021 12:26:34 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id w85KkwSq8HPnUw85Kk5pbI; Sun, 03 Jan 2021 12:26:34 -0600 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=7Q8w9YlpIsXwdzOytmIysA/lHlg7g5YYpaCAhHqnDi4=; b=NV8IdIdC3EekjZhoKNHDMwe4Px gELoI/CqTZdF3kKZsLgLeF1CgPKYeXBEuamyOxpp4wIfm3vtqZZQkfOV1RZLkV4taA+cOA8+XJWds UHzFzo17RBMScJLWzFcLe/q/J; Received: from 97-122-81-39.hlrn.qwest.net ([97.122.81.39]:39392 helo=localhost.localdomain) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1kw85J-00234L-QU; Sun, 03 Jan 2021 11:26:33 -0700 From: Tom Tromey To: gcc-patches@gcc.gnu.org Subject: [PATCH 04/10] libcc1: delete copy constructor and assignment operators Date: Sun, 3 Jan 2021 11:26:25 -0700 Message-Id: <20210103182631.2316205-5-tom@tromey.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210103182631.2316205-1-tom@tromey.com> References: <20210103182631.2316205-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.81.39 X-Source-L: No X-Exim-ID: 1kw85J-00234L-QU X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-81-39.hlrn.qwest.net (localhost.localdomain) [97.122.81.39]:39392 X-Source-Auth: tom+tromey.com X-Email-Count: 5 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3032.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_ABUSEAT, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_NEUTRAL, TXREP 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" Change libcc1 to use "= delete" for the copy constructor and assignment operator, rather than the old approach of private methods that are nowhere defined. libcc1/ChangeLog 2021-01-03 Tom Tromey * rpc.hh (argument_wrapper): Use delete for copy constructor. * connection.hh (class connection): Use delete for copy constructor. * callbacks.hh (class callbacks): Use delete for copy constructor. --- libcc1/ChangeLog | 7 +++++++ libcc1/callbacks.hh | 7 +++---- libcc1/connection.hh | 7 +++---- libcc1/rpc.hh | 42 ++++++++++++++++++------------------------ 4 files changed, 31 insertions(+), 32 deletions(-) diff --git a/libcc1/callbacks.hh b/libcc1/callbacks.hh index e2d19b888b3..d3b06d9cf25 100644 --- a/libcc1/callbacks.hh +++ b/libcc1/callbacks.hh @@ -42,6 +42,9 @@ namespace cc1_plugin callbacks (); ~callbacks (); + callbacks (const callbacks &) = delete; + callbacks &operator= (const callbacks &) = delete; + // Add a callback named NAME. FUNC is the function to call when // this method is invoked. void add_callback (const char *name, callback_ftype *func); @@ -52,10 +55,6 @@ namespace cc1_plugin private: - // Declared but not defined to avoid use. - callbacks (const callbacks &); - callbacks &operator= (const callbacks &); - // The mapping. htab_t m_registry; }; diff --git a/libcc1/connection.hh b/libcc1/connection.hh index d8562a26154..1dc099902c8 100644 --- a/libcc1/connection.hh +++ b/libcc1/connection.hh @@ -48,6 +48,9 @@ namespace cc1_plugin virtual ~connection () = default; + connection (const connection &) = delete; + connection &operator= (const connection &) = delete; + // Send a single character. This is used to introduce various // higher-level protocol elements. status send (char c); @@ -95,10 +98,6 @@ namespace cc1_plugin private: - // Declared but not defined, to prevent use. - connection (const connection &); - connection &operator= (const connection &); - // Helper function for the wait_* methods. status do_wait (bool); diff --git a/libcc1/rpc.hh b/libcc1/rpc.hh index f616124fabe..ef2527ae40b 100644 --- a/libcc1/rpc.hh +++ b/libcc1/rpc.hh @@ -39,6 +39,9 @@ namespace cc1_plugin argument_wrapper () { } ~argument_wrapper () { } + argument_wrapper (const argument_wrapper &) = delete; + argument_wrapper &operator= (const argument_wrapper &) = delete; + operator T () const { return m_object; } status unmarshall (connection *conn) @@ -49,10 +52,6 @@ namespace cc1_plugin private: T m_object; - - // No copying or assignment allowed. - argument_wrapper (const argument_wrapper &); - argument_wrapper &operator= (const argument_wrapper &); }; // Specialization for any kind of pointer. This is declared but not @@ -72,6 +71,9 @@ namespace cc1_plugin delete[] m_object; } + argument_wrapper (const argument_wrapper &) = delete; + argument_wrapper &operator= (const argument_wrapper &) = delete; + operator const char * () const { return m_object; @@ -85,10 +87,6 @@ namespace cc1_plugin private: char *m_object; - - // No copying or assignment allowed. - argument_wrapper (const argument_wrapper &); - argument_wrapper &operator= (const argument_wrapper &); }; // Specialization for gcc_type_array. @@ -106,6 +104,9 @@ namespace cc1_plugin delete m_object; } + argument_wrapper (const argument_wrapper &) = delete; + argument_wrapper &operator= (const argument_wrapper &) = delete; + operator const gcc_type_array * () const { return m_object; @@ -119,10 +120,6 @@ namespace cc1_plugin private: gcc_type_array *m_object; - - // No copying or assignment allowed. - argument_wrapper (const argument_wrapper &); - argument_wrapper &operator= (const argument_wrapper &); }; #ifdef GCC_CP_INTERFACE_H @@ -144,6 +141,9 @@ namespace cc1_plugin delete m_object; } + argument_wrapper (const argument_wrapper &) = delete; + argument_wrapper &operator= (const argument_wrapper &) = delete; + operator const gcc_vbase_array * () const { return m_object; @@ -157,10 +157,6 @@ namespace cc1_plugin private: gcc_vbase_array *m_object; - - // No copying or assignment allowed. - argument_wrapper (const argument_wrapper &); - argument_wrapper &operator= (const argument_wrapper &); }; // Specialization for gcc_cp_template_args. @@ -181,6 +177,9 @@ namespace cc1_plugin delete m_object; } + argument_wrapper (const argument_wrapper &) = delete; + argument_wrapper &operator= (const argument_wrapper &) = delete; + operator const gcc_cp_template_args * () const { return m_object; @@ -194,10 +193,6 @@ namespace cc1_plugin private: gcc_cp_template_args *m_object; - - // No copying or assignment allowed. - argument_wrapper (const argument_wrapper &); - argument_wrapper &operator= (const argument_wrapper &); }; // Specialization for gcc_cp_function_args. @@ -217,6 +212,9 @@ namespace cc1_plugin delete m_object; } + argument_wrapper (const argument_wrapper &) = delete; + argument_wrapper &operator= (const argument_wrapper &) = delete; + operator const gcc_cp_function_args * () const { return m_object; @@ -230,10 +228,6 @@ namespace cc1_plugin private: gcc_cp_function_args *m_object; - - // No copying or assignment allowed. - argument_wrapper (const argument_wrapper &); - argument_wrapper &operator= (const argument_wrapper &); }; #endif /* GCC_CP_INTERFACE_H */ From patchwork Sun Jan 3 18:26:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 1421904 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=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=tromey.com 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=nWSVCKq5; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 4D86fr09QVz9sSs for ; Mon, 4 Jan 2021 05:27:00 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 672583870844; Sun, 3 Jan 2021 18:26:38 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from gateway33.websitewelcome.com (gateway33.websitewelcome.com [192.185.146.97]) by sourceware.org (Postfix) with ESMTPS id AF17B386F820 for ; Sun, 3 Jan 2021 18:26:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org AF17B386F820 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 cm17.websitewelcome.com (cm17.websitewelcome.com [100.42.49.20]) by gateway33.websitewelcome.com (Postfix) with ESMTP id 49E8F4EDCC for ; Sun, 3 Jan 2021 12:26:34 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id w85KkOsqkDT64w85KkVz8y; Sun, 03 Jan 2021 12:26:34 -0600 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=nGY6w7uA5FB6tgjpm1OnQ4hXN0p5y7D0Dwr7g1SL9MQ=; b=nWSVCKq56rEhuHgH1PU4d3gJOK +z+udhHmePvm0Q1QklDgCiAVQXwbfk/fmySUCvsLC9hvB+K3q92E6C13M8T1MucCgICjlzUEytGzM fvNZZlakrFKCW1lY3VoDUTzOE; Received: from 97-122-81-39.hlrn.qwest.net ([97.122.81.39]:39392 helo=localhost.localdomain) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1kw85K-00234L-1S; Sun, 03 Jan 2021 11:26:34 -0700 From: Tom Tromey To: gcc-patches@gcc.gnu.org Subject: [PATCH 05/10] libcc1: use variadic templates for "call" Date: Sun, 3 Jan 2021 11:26:26 -0700 Message-Id: <20210103182631.2316205-6-tom@tromey.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210103182631.2316205-1-tom@tromey.com> References: <20210103182631.2316205-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.81.39 X-Source-L: No X-Exim-ID: 1kw85K-00234L-1S X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-81-39.hlrn.qwest.net (localhost.localdomain) [97.122.81.39]:39392 X-Source-Auth: tom+tromey.com X-Email-Count: 6 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3032.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_ABUSEAT, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_NEUTRAL, TXREP 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 variadic templates for the "call" functions. The primary benefit is that this simplifies the code. libcc1/ChangeLog 2021-01-03 Tom Tromey * rpc.hh (call): Use variadic template. Remove overloads. * marshall.hh (marshall): Add base overload. Use variadic template. --- libcc1/ChangeLog | 6 ++ libcc1/marshall.hh | 16 +++++ libcc1/rpc.hh | 168 +++------------------------------------------ 3 files changed, 31 insertions(+), 159 deletions(-) diff --git a/libcc1/marshall.hh b/libcc1/marshall.hh index 7fadbeaa5ac..d9d5d6cbc74 100644 --- a/libcc1/marshall.hh +++ b/libcc1/marshall.hh @@ -52,6 +52,14 @@ namespace cc1_plugin status unmarshall_array_start (connection *, char, size_t *); status unmarshall_array_elmts (connection *, size_t, void *); + // An "empty" marshall call -- used to handle the base case for some + // variadic templates. + static inline + status marshall (connection *) + { + return OK; + } + // A template function that can handle marshalling various integer // objects to the connection. template @@ -103,6 +111,14 @@ namespace cc1_plugin // resulting array must be freed by the caller, using 'delete[]' on // the elements, and 'delete' on the array object itself. status unmarshall (connection *, struct gcc_type_array **); + + template + status marshall (connection *c, T1 arg1, T2 arg2, Arg... rest) + { + if (!marshall (c, arg1)) + return FAIL; + return marshall (c, arg2, rest...); + } }; #endif // CC1_PLUGIN_MARSHALL_HH diff --git a/libcc1/rpc.hh b/libcc1/rpc.hh index ef2527ae40b..322521274e6 100644 --- a/libcc1/rpc.hh +++ b/libcc1/rpc.hh @@ -232,10 +232,10 @@ namespace cc1_plugin #endif /* GCC_CP_INTERFACE_H */ // There are two kinds of template functions here: "call" and - // "callback". They are each repeated multiple times to handle - // different numbers of arguments. (This would be improved with - // C++11, though applying a call is still tricky until C++14 can be - // used.) + // "callback". "call" is implemented with variadic templates, but + // "callback" is repeated multiple times to handle different numbers + // of arguments. (This could be improved with C++17 and + // std::apply.) // The "call" template is used for making a remote procedure call. // It starts a query ('Q') packet, marshalls its arguments, waits @@ -248,15 +248,17 @@ namespace cc1_plugin // arguments, passes them to the wrapped function, and finally // marshalls a reply packet. - template + template status - call (connection *conn, const char *method, R *result) + call (connection *conn, const char *method, R *result, Arg... args) { if (!conn->send ('Q')) return FAIL; if (!marshall (conn, method)) return FAIL; - if (!marshall (conn, 0)) + if (!marshall (conn, (int) sizeof... (Arg))) + return FAIL; + if (!marshall (conn, args...)) return FAIL; if (!conn->wait_for_result ()) return FAIL; @@ -279,25 +281,6 @@ namespace cc1_plugin return marshall (conn, result); } - template - status - call (connection *conn, const char *method, R *result, A arg) - { - if (!conn->send ('Q')) - return FAIL; - if (!marshall (conn, method)) - return FAIL; - if (!marshall (conn, 1)) - return FAIL; - if (!marshall (conn, arg)) - return FAIL; - if (!conn->wait_for_result ()) - return FAIL; - if (!unmarshall (conn, result)) - return FAIL; - return OK; - } - template status callback (connection *conn) @@ -315,27 +298,6 @@ namespace cc1_plugin return marshall (conn, result); } - template - status - call (connection *conn, const char *method, R *result, A1 arg1, A2 arg2) - { - if (!conn->send ('Q')) - return FAIL; - if (!marshall (conn, method)) - return FAIL; - if (!marshall (conn, 2)) - return FAIL; - if (!marshall (conn, arg1)) - return FAIL; - if (!marshall (conn, arg2)) - return FAIL; - if (!conn->wait_for_result ()) - return FAIL; - if (!unmarshall (conn, result)) - return FAIL; - return OK; - } - template status @@ -357,30 +319,6 @@ namespace cc1_plugin return marshall (conn, result); } - template - status - call (connection *conn, const char *method, R *result, A1 arg1, A2 arg2, - A3 arg3) - { - if (!conn->send ('Q')) - return FAIL; - if (!marshall (conn, method)) - return FAIL; - if (!marshall (conn, 3)) - return FAIL; - if (!marshall (conn, arg1)) - return FAIL; - if (!marshall (conn, arg2)) - return FAIL; - if (!marshall (conn, arg3)) - return FAIL; - if (!conn->wait_for_result ()) - return FAIL; - if (!unmarshall (conn, result)) - return FAIL; - return OK; - } - template status @@ -405,32 +343,6 @@ namespace cc1_plugin return marshall (conn, result); } - template - status - call (connection *conn, const char *method, R *result, A1 arg1, A2 arg2, - A3 arg3, A4 arg4) - { - if (!conn->send ('Q')) - return FAIL; - if (!marshall (conn, method)) - return FAIL; - if (!marshall (conn, 4)) - return FAIL; - if (!marshall (conn, arg1)) - return FAIL; - if (!marshall (conn, arg2)) - return FAIL; - if (!marshall (conn, arg3)) - return FAIL; - if (!marshall (conn, arg4)) - return FAIL; - if (!conn->wait_for_result ()) - return FAIL; - if (!unmarshall (conn, result)) - return FAIL; - return OK; - } - template status @@ -458,35 +370,6 @@ namespace cc1_plugin return marshall (conn, result); } - template - status - call (connection *conn, const char *method, R *result, A1 arg1, A2 arg2, - A3 arg3, A4 arg4, A5 arg5) - { - if (!conn->send ('Q')) - return FAIL; - if (!marshall (conn, method)) - return FAIL; - if (!marshall (conn, 5)) - return FAIL; - if (!marshall (conn, arg1)) - return FAIL; - if (!marshall (conn, arg2)) - return FAIL; - if (!marshall (conn, arg3)) - return FAIL; - if (!marshall (conn, arg4)) - return FAIL; - if (!marshall (conn, arg5)) - return FAIL; - if (!conn->wait_for_result ()) - return FAIL; - if (!unmarshall (conn, result)) - return FAIL; - return OK; - } - template status @@ -517,39 +400,6 @@ namespace cc1_plugin return marshall (conn, result); } - template - status - call (connection *conn, const char *method, R *result, A1 arg1, A2 arg2, - A3 arg3, A4 arg4, A5 arg5, A6 arg6, A7 arg7) - { - if (!conn->send ('Q')) - return FAIL; - if (!marshall (conn, method)) - return FAIL; - if (!marshall (conn, 7)) - return FAIL; - if (!marshall (conn, arg1)) - return FAIL; - if (!marshall (conn, arg2)) - return FAIL; - if (!marshall (conn, arg3)) - return FAIL; - if (!marshall (conn, arg4)) - return FAIL; - if (!marshall (conn, arg5)) - return FAIL; - if (!marshall (conn, arg6)) - return FAIL; - if (!marshall (conn, arg7)) - return FAIL; - if (!conn->wait_for_result ()) - return FAIL; - if (!unmarshall (conn, result)) - return FAIL; - return OK; - } - template From patchwork Sun Jan 3 18:26:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 1421906 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; dmarc=none (p=none dis=none) header.from=tromey.com 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=VHEiVBbY; dkim-atps=neutral Received: from sourceware.org (unknown [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 4D86g20kFjz9sVt for ; Mon, 4 Jan 2021 05:27:10 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BCC803870855; Sun, 3 Jan 2021 18:26:39 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from gateway22.websitewelcome.com (gateway22.websitewelcome.com [192.185.47.168]) by sourceware.org (Postfix) with ESMTPS id 7C52C386F826 for ; Sun, 3 Jan 2021 18:26:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 7C52C386F826 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 cm16.websitewelcome.com (cm16.websitewelcome.com [100.42.49.19]) by gateway22.websitewelcome.com (Postfix) with ESMTP id 76C81EBD for ; Sun, 3 Jan 2021 12:26:34 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id w85KkwSqPHPnUw85Kk5pbW; Sun, 03 Jan 2021 12:26:34 -0600 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=YCI72rZw8kJicRLbn2iO/QCrivJiHvT3O+yMaSA3lAQ=; b=VHEiVBbYSTaiqvjsv5tZ0YB+mz o9I+NacqivazragM22yCNorhD63AS9jS95gERKJbQYBwI2z2ofK5999URK7LmLbyx3ZZ87odbeZ2a +AL0Duso5HZRlZm/ldYYH/dQZ; Received: from 97-122-81-39.hlrn.qwest.net ([97.122.81.39]:39392 helo=localhost.localdomain) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1kw85K-00234L-8z; Sun, 03 Jan 2021 11:26:34 -0700 From: Tom Tromey To: gcc-patches@gcc.gnu.org Subject: [PATCH 06/10] libcc1: use variadic templates for "rpc" Date: Sun, 3 Jan 2021 11:26:27 -0700 Message-Id: <20210103182631.2316205-7-tom@tromey.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210103182631.2316205-1-tom@tromey.com> References: <20210103182631.2316205-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.81.39 X-Source-L: No X-Exim-ID: 1kw85K-00234L-8z X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-81-39.hlrn.qwest.net (localhost.localdomain) [97.122.81.39]:39392 X-Source-Auth: tom+tromey.com X-Email-Count: 7 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3032.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_ASCII_DIVIDERS, RCVD_IN_ABUSEAT, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_NEUTRAL, TXREP 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 variadic templates for the "rpc" functions. This simplifies the code and removes some possibility for mistakes. libcc1/ChangeLog 2021-01-03 Tom Tromey * libcp1.cc (rpc): Use variadic template. Remove overloads. * libcc1.cc (rpc): Use variadic template. Remove overloads. --- libcc1/ChangeLog | 5 +++ libcc1/libcc1.cc | 81 +++--------------------------------------------- libcc1/libcp1.cc | 81 +++--------------------------------------------- 3 files changed, 13 insertions(+), 154 deletions(-) diff --git a/libcc1/libcc1.cc b/libcc1/libcc1.cc index 4fb3084c24c..82b1a6435b4 100644 --- a/libcc1/libcc1.cc +++ b/libcc1/libcc1.cc @@ -210,90 +210,17 @@ set_callbacks (struct gcc_c_context *s, self->oracle_datum = datum; } -// Instances of these rpc<> template functions are installed into the +// Instances of this rpc<> template function are installed into the // "c_vtable". These functions are parameterized by type and method // name and forward the call via the connection. -template -R rpc (struct gcc_c_context *s) +template +R rpc (struct gcc_c_context *s, Arg... rest) { libcc1 *self = (libcc1 *) s; R result; - if (!cc1_plugin::call (self->connection, NAME, &result)) - return 0; - return result; -} - -template -R rpc (struct gcc_c_context *s, A arg) -{ - libcc1 *self = (libcc1 *) s; - R result; - - if (!cc1_plugin::call (self->connection, NAME, &result, arg)) - return 0; - return result; -} - -template -R rpc (struct gcc_c_context *s, A1 arg1, A2 arg2) -{ - libcc1 *self = (libcc1 *) s; - R result; - - if (!cc1_plugin::call (self->connection, NAME, &result, arg1, arg2)) - return 0; - return result; -} - -template -R rpc (struct gcc_c_context *s, A1 arg1, A2 arg2, A3 arg3) -{ - libcc1 *self = (libcc1 *) s; - R result; - - if (!cc1_plugin::call (self->connection, NAME, &result, arg1, arg2, arg3)) - return 0; - return result; -} - -template -R rpc (struct gcc_c_context *s, A1 arg1, A2 arg2, A3 arg3, A4 arg4) -{ - libcc1 *self = (libcc1 *) s; - R result; - - if (!cc1_plugin::call (self->connection, NAME, &result, arg1, arg2, arg3, - arg4)) - return 0; - return result; -} - -template -R rpc (struct gcc_c_context *s, A1 arg1, A2 arg2, A3 arg3, A4 arg4, A5 arg5) -{ - libcc1 *self = (libcc1 *) s; - R result; - - if (!cc1_plugin::call (self->connection, NAME, &result, arg1, arg2, arg3, - arg4, arg5)) - return 0; - return result; -} - -template -R rpc (struct gcc_c_context *s, A1 arg1, A2 arg2, A3 arg3, A4 arg4, A5 arg5, - A6 arg6, A7 arg7) -{ - libcc1 *self = (libcc1 *) s; - R result; - - if (!cc1_plugin::call (self->connection, NAME, &result, arg1, arg2, arg3, - arg4, arg5, arg6, arg7)) + if (!cc1_plugin::call (self->connection, NAME, &result, rest...)) return 0; return result; } diff --git a/libcc1/libcp1.cc b/libcc1/libcp1.cc index 5fa6a6742f5..4fced736204 100644 --- a/libcc1/libcp1.cc +++ b/libcc1/libcp1.cc @@ -233,90 +233,17 @@ set_callbacks (struct gcc_cp_context *s, self->oracle_datum = datum; } -// Instances of these rpc<> template functions are installed into the +// Instances of this rpc<> template function are installed into the // "cp_vtable". These functions are parameterized by type and method // name and forward the call via the connection. -template -R rpc (struct gcc_cp_context *s) +template +R rpc (struct gcc_cp_context *s, Arg... rest) { libcp1 *self = (libcp1 *) s; R result; - if (!cc1_plugin::call (self->connection, NAME, &result)) - return 0; - return result; -} - -template -R rpc (struct gcc_cp_context *s, A arg) -{ - libcp1 *self = (libcp1 *) s; - R result; - - if (!cc1_plugin::call (self->connection, NAME, &result, arg)) - return 0; - return result; -} - -template -R rpc (struct gcc_cp_context *s, A1 arg1, A2 arg2) -{ - libcp1 *self = (libcp1 *) s; - R result; - - if (!cc1_plugin::call (self->connection, NAME, &result, arg1, arg2)) - return 0; - return result; -} - -template -R rpc (struct gcc_cp_context *s, A1 arg1, A2 arg2, A3 arg3) -{ - libcp1 *self = (libcp1 *) s; - R result; - - if (!cc1_plugin::call (self->connection, NAME, &result, arg1, arg2, arg3)) - return 0; - return result; -} - -template -R rpc (struct gcc_cp_context *s, A1 arg1, A2 arg2, A3 arg3, A4 arg4) -{ - libcp1 *self = (libcp1 *) s; - R result; - - if (!cc1_plugin::call (self->connection, NAME, &result, arg1, arg2, arg3, - arg4)) - return 0; - return result; -} - -template -R rpc (struct gcc_cp_context *s, A1 arg1, A2 arg2, A3 arg3, A4 arg4, A5 arg5) -{ - libcp1 *self = (libcp1 *) s; - R result; - - if (!cc1_plugin::call (self->connection, NAME, &result, arg1, arg2, arg3, - arg4, arg5)) - return 0; - return result; -} - -template -R rpc (struct gcc_cp_context *s, A1 arg1, A2 arg2, A3 arg3, A4 arg4, A5 arg5, - A6 arg6, A7 arg7) -{ - libcp1 *self = (libcp1 *) s; - R result; - - if (!cc1_plugin::call (self->connection, NAME, &result, arg1, arg2, arg3, - arg4, arg5, arg6, arg7)) + if (!cc1_plugin::call (self->connection, NAME, &result, rest...)) return 0; return result; } From patchwork Sun Jan 3 18:26:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 1421905 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; dmarc=none (p=none dis=none) header.from=tromey.com 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=vNqrgJnS; dkim-atps=neutral Received: from sourceware.org (unknown [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 4D86fx5WjTz9sSs for ; Mon, 4 Jan 2021 05:27:05 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5127B3870849; Sun, 3 Jan 2021 18:26:39 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from gateway33.websitewelcome.com (gateway33.websitewelcome.com [192.185.146.97]) by sourceware.org (Postfix) with ESMTPS id 1D702386F824 for ; Sun, 3 Jan 2021 18:26:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 1D702386F824 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 cm17.websitewelcome.com (cm17.websitewelcome.com [100.42.49.20]) by gateway33.websitewelcome.com (Postfix) with ESMTP id AD8F14EDD1 for ; Sun, 3 Jan 2021 12:26:34 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id w85KkOsqyDT64w85KkVz9D; Sun, 03 Jan 2021 12:26:34 -0600 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=oL2tdLAC2jPaNgvkF6H7qd+6yLKeV1gfRg/DwgmGkeE=; b=vNqrgJnSIoB3U+CQmgJxaU7usg L6EIAh97yCT+juZO4eipscg6qBWfWSZdYbsT+iErZyKGAPASW5QpShaBtOxBArEXsYtC/qlNkSStv x8ZikvuC0rc50sVGjHEja2wwr; Received: from 97-122-81-39.hlrn.qwest.net ([97.122.81.39]:39392 helo=localhost.localdomain) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1kw85K-00234L-Fy; Sun, 03 Jan 2021 11:26:34 -0700 From: Tom Tromey To: gcc-patches@gcc.gnu.org Subject: [PATCH 07/10] libcc1: use std::vector when building function types Date: Sun, 3 Jan 2021 11:26:28 -0700 Message-Id: <20210103182631.2316205-8-tom@tromey.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210103182631.2316205-1-tom@tromey.com> References: <20210103182631.2316205-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.81.39 X-Source-L: No X-Exim-ID: 1kw85K-00234L-Fy X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-81-39.hlrn.qwest.net (localhost.localdomain) [97.122.81.39]:39392 X-Source-Auth: tom+tromey.com X-Email-Count: 8 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3032.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_ABUSEAT, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_NEUTRAL, TXREP 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 std::vector in the code that builds function types. This avoids some explicit memory management. libcc1/ChangeLog 2021-01-03 Tom Tromey * libcp1plugin.cc (plugin_build_function_type): Use std::vector. * libcc1plugin.cc (plugin_build_function_type): Use std::vector. --- libcc1/ChangeLog | 5 +++++ libcc1/libcc1plugin.cc | 11 +++++------ libcc1/libcp1plugin.cc | 11 +++++------ 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/libcc1/libcc1plugin.cc b/libcc1/libcc1plugin.cc index a0fb61f2e46..aa07e6dbaef 100644 --- a/libcc1/libcc1plugin.cc +++ b/libcc1/libcc1plugin.cc @@ -67,6 +67,8 @@ #include "rpc.hh" #include "gcc-c-interface.h" +#include + #ifdef __GNUC__ #pragma GCC visibility push(default) #endif @@ -672,24 +674,21 @@ plugin_build_function_type (cc1_plugin::connection *self, const struct gcc_type_array *argument_types_in, int is_varargs) { - tree *argument_types; tree return_type = convert_in (return_type_in); tree result; - argument_types = new tree[argument_types_in->n_elements]; + std::vector argument_types (argument_types_in->n_elements); for (int i = 0; i < argument_types_in->n_elements; ++i) argument_types[i] = convert_in (argument_types_in->elements[i]); if (is_varargs) result = build_varargs_function_type_array (return_type, argument_types_in->n_elements, - argument_types); + argument_types.data ()); else result = build_function_type_array (return_type, argument_types_in->n_elements, - argument_types); - - delete[] argument_types; + argument_types.data ()); plugin_context *ctx = static_cast (self); return convert_out (ctx->preserve (result)); diff --git a/libcc1/libcp1plugin.cc b/libcc1/libcp1plugin.cc index 648368353cb..d2700e24152 100644 --- a/libcc1/libcp1plugin.cc +++ b/libcc1/libcp1plugin.cc @@ -70,6 +70,8 @@ #include "marshall-cp.hh" #include "rpc.hh" +#include + #ifdef __GNUC__ #pragma GCC visibility push(default) #endif @@ -1980,24 +1982,21 @@ plugin_build_function_type (cc1_plugin::connection *self, const struct gcc_type_array *argument_types_in, int is_varargs) { - tree *argument_types; tree return_type = convert_in (return_type_in); tree result; - argument_types = new tree[argument_types_in->n_elements]; + std::vector argument_types (argument_types_in->n_elements); for (int i = 0; i < argument_types_in->n_elements; ++i) argument_types[i] = convert_in (argument_types_in->elements[i]); if (is_varargs) result = build_varargs_function_type_array (return_type, argument_types_in->n_elements, - argument_types); + argument_types.data ()); else result = build_function_type_array (return_type, argument_types_in->n_elements, - argument_types); - - delete[] argument_types; + argument_types.data ()); plugin_context *ctx = static_cast (self); return convert_out (ctx->preserve (result)); From patchwork Sun Jan 3 18:26:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 1421908 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; dmarc=none (p=none dis=none) header.from=tromey.com 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=VlhUDPRu; dkim-atps=neutral Received: from sourceware.org (server2.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 4D86gB6BN8z9sSs for ; Mon, 4 Jan 2021 05:27:18 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 994CA387085C; Sun, 3 Jan 2021 18:26:40 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from gateway22.websitewelcome.com (gateway22.websitewelcome.com [192.185.47.168]) by sourceware.org (Postfix) with ESMTPS id 9E88D386F82D for ; Sun, 3 Jan 2021 18:26:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 9E88D386F82D 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 cm16.websitewelcome.com (cm16.websitewelcome.com [100.42.49.19]) by gateway22.websitewelcome.com (Postfix) with ESMTP id E71CD952 for ; Sun, 3 Jan 2021 12:26:34 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id w85KkwSqgHPnUw85Kk5pbo; Sun, 03 Jan 2021 12:26:34 -0600 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=c5QazCRpDirzKwSpba0HoNaig9WzEn4Vi15xYqlGEKo=; b=VlhUDPRuHD1JipsMT0MdXqeoMK bxw+34WNFv00H3l2m4Hpo7QxlMhvM1oUUs8FvO8Uq7L6oLBHNJ0GRQ4gyqimM6C6UvCRw+nVcGsfI zZIrZfcutDuONNHfB38hSJsJr; Received: from 97-122-81-39.hlrn.qwest.net ([97.122.81.39]:39392 helo=localhost.localdomain) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1kw85K-00234L-N5; Sun, 03 Jan 2021 11:26:34 -0700 From: Tom Tromey To: gcc-patches@gcc.gnu.org Subject: [PATCH 08/10] libcc1: add deleter objects Date: Sun, 3 Jan 2021 11:26:29 -0700 Message-Id: <20210103182631.2316205-9-tom@tromey.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210103182631.2316205-1-tom@tromey.com> References: <20210103182631.2316205-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.81.39 X-Source-L: No X-Exim-ID: 1kw85K-00234L-N5 X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-81-39.hlrn.qwest.net (localhost.localdomain) [97.122.81.39]:39392 X-Source-Auth: tom+tromey.com X-Email-Count: 9 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3032.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_ABUSEAT, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_NEUTRAL, TXREP 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 adds deleter objects for various kinds of protocol pointers to libcc1. Existing specializations of argument_wrapper are then replaced with a single specialization that handles all pointer types via the appropriate deleter. The result here is a bit nicer because the argument_wrapper boilerplate code is completely shared, leaving just the memory-management detail to the particular specializations. libcc1/ChangeLog 2021-01-03 Tom Tromey * rpc.hh (struct deleter): New template class and specializations. (argument_wrapper): Remove specializations. Add specialization for any pointer type. --- libcc1/ChangeLog | 7 ++ libcc1/rpc.hh | 176 ++++++++++++----------------------------------- 2 files changed, 52 insertions(+), 131 deletions(-) diff --git a/libcc1/rpc.hh b/libcc1/rpc.hh index 322521274e6..00f108d6dc9 100644 --- a/libcc1/rpc.hh +++ b/libcc1/rpc.hh @@ -22,6 +22,7 @@ along with GCC; see the file COPYING3. If not see #include "status.hh" #include "connection.hh" +#include namespace cc1_plugin { @@ -54,182 +55,95 @@ namespace cc1_plugin T m_object; }; - // Specialization for any kind of pointer. This is declared but not - // defined to avoid bugs if a new pointer type is introduced into - // the API. Instead you will just get a compilation error. - template - class argument_wrapper; + // Any pointer type requires a deleter object that knows how to + // clean up. These are used in multiple places. + template struct deleter; - // Specialization for string types. template<> - class argument_wrapper + struct deleter { - public: - argument_wrapper () : m_object (NULL) { } - ~argument_wrapper () + void operator() (char *s) { - delete[] m_object; + delete[] s; } - - argument_wrapper (const argument_wrapper &) = delete; - argument_wrapper &operator= (const argument_wrapper &) = delete; - - operator const char * () const - { - return m_object; - } - - status unmarshall (connection *conn) - { - return ::cc1_plugin::unmarshall (conn, &m_object); - } - - private: - - char *m_object; }; - // Specialization for gcc_type_array. template<> - class argument_wrapper + struct deleter { - public: - argument_wrapper () : m_object (NULL) { } - ~argument_wrapper () + void operator() (gcc_type_array *p) { - // It would be nicer if gcc_type_array could have a destructor. - // But, it is in code shared with gdb and cannot. - if (m_object != NULL) - delete[] m_object->elements; - delete m_object; + delete[] p->elements; + delete p; } - - argument_wrapper (const argument_wrapper &) = delete; - argument_wrapper &operator= (const argument_wrapper &) = delete; - - operator const gcc_type_array * () const - { - return m_object; - } - - status unmarshall (connection *conn) - { - return ::cc1_plugin::unmarshall (conn, &m_object); - } - - private: - - gcc_type_array *m_object; }; #ifdef GCC_CP_INTERFACE_H - // Specialization for gcc_vbase_array. template<> - class argument_wrapper + struct deleter { - public: - argument_wrapper () : m_object (NULL) { } - ~argument_wrapper () - { - // It would be nicer if gcc_type_array could have a destructor. - // But, it is in code shared with gdb and cannot. - if (m_object != NULL) - { - delete[] m_object->flags; - delete[] m_object->elements; - } - delete m_object; - } - - argument_wrapper (const argument_wrapper &) = delete; - argument_wrapper &operator= (const argument_wrapper &) = delete; - - operator const gcc_vbase_array * () const + void operator() (gcc_vbase_array *p) { - return m_object; - } - - status unmarshall (connection *conn) - { - return ::cc1_plugin::unmarshall (conn, &m_object); + delete[] p->flags; + delete[] p->elements; + delete p; } - - private: - - gcc_vbase_array *m_object; }; - // Specialization for gcc_cp_template_args. template<> - class argument_wrapper + struct deleter { - public: - argument_wrapper () : m_object (NULL) { } - ~argument_wrapper () - { - // It would be nicer if gcc_type_array could have a destructor. - // But, it is in code shared with gdb and cannot. - if (m_object != NULL) - { - delete[] m_object->elements; - delete[] m_object->kinds; - } - delete m_object; - } - - argument_wrapper (const argument_wrapper &) = delete; - argument_wrapper &operator= (const argument_wrapper &) = delete; - - operator const gcc_cp_template_args * () const + void operator() (gcc_cp_template_args *p) { - return m_object; + delete[] p->elements; + delete[] p->kinds; + delete p; } + }; - status unmarshall (connection *conn) + template<> + struct deleter + { + void operator() (gcc_cp_function_args *p) { - return ::cc1_plugin::unmarshall (conn, &m_object); + delete[] p->elements; + delete p; } - - private: - - gcc_cp_template_args *m_object; }; - // Specialization for gcc_cp_function_args. - template<> - class argument_wrapper +#endif // GCC_CP_INTERFACE_H + + // Specialization for any kind of pointer. + template + class argument_wrapper { public: - argument_wrapper () : m_object (NULL) { } - ~argument_wrapper () - { - // It would be nicer if gcc_type_array could have a destructor. - // But, it is in code shared with gdb and cannot. - if (m_object != NULL) - { - delete[] m_object->elements; - } - delete m_object; - } + argument_wrapper () = default; + ~argument_wrapper () = default; argument_wrapper (const argument_wrapper &) = delete; argument_wrapper &operator= (const argument_wrapper &) = delete; - operator const gcc_cp_function_args * () const + typedef typename std::remove_const::type type; + + operator const type * () const { - return m_object; + return m_object.get (); } status unmarshall (connection *conn) { - return ::cc1_plugin::unmarshall (conn, &m_object); + type *ptr; + if (!::cc1_plugin::unmarshall (conn, &ptr)) + return FAIL; + m_object.reset (ptr); + return OK; } private: - gcc_cp_function_args *m_object; + std::unique_ptr> m_object; }; -#endif /* GCC_CP_INTERFACE_H */ // There are two kinds of template functions here: "call" and // "callback". "call" is implemented with variadic templates, but From patchwork Sun Jan 3 18:26:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 1421909 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; dmarc=none (p=none dis=none) header.from=tromey.com 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=MdDe+710; dkim-atps=neutral Received: from sourceware.org (unknown [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 4D86gH12HPz9sSs for ; Mon, 4 Jan 2021 05:27:22 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 131A83870864; Sun, 3 Jan 2021 18:26:41 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from gateway22.websitewelcome.com (gateway22.websitewelcome.com [192.185.47.168]) by sourceware.org (Postfix) with ESMTPS id ACD9F386F82E for ; Sun, 3 Jan 2021 18:26:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org ACD9F386F82E 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 cm12.websitewelcome.com (cm12.websitewelcome.com [100.42.49.8]) by gateway22.websitewelcome.com (Postfix) with ESMTP id 45395170F for ; Sun, 3 Jan 2021 12:26:35 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id w85LkQdvTiQiZw85Lk7J6F; Sun, 03 Jan 2021 12:26:35 -0600 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=KP7c1PZKuzxlpx/qq4119YbKQcceqWnpxrWogPUyx8g=; b=MdDe+710RVsKz6NNv6iBxzP6cv kX3kyxbTr/Bw6/JRcZ7R08ZoHE/I5vPSyVk18K94MNH1ycfUn/rFfnxLc2BrPUF30s36fQTjrWkuC f5iSZiBV1tZr0uZli4NXuNu6C; Received: from 97-122-81-39.hlrn.qwest.net ([97.122.81.39]:39392 helo=localhost.localdomain) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1kw85K-00234L-WB; Sun, 03 Jan 2021 11:26:35 -0700 From: Tom Tromey To: gcc-patches@gcc.gnu.org Subject: [PATCH 09/10] libcc1: add more uses of 'deleter' Date: Sun, 3 Jan 2021 11:26:30 -0700 Message-Id: <20210103182631.2316205-10-tom@tromey.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210103182631.2316205-1-tom@tromey.com> References: <20210103182631.2316205-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.81.39 X-Source-L: No X-Exim-ID: 1kw85K-00234L-WB X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-81-39.hlrn.qwest.net (localhost.localdomain) [97.122.81.39]:39392 X-Source-Auth: tom+tromey.com X-Email-Count: 10 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3030.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_SHORT, RCVD_IN_ABUSEAT, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_BL_SPAMCOP_NET, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_NEUTRAL, TXREP 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 the 'deleter' template in a few more places. The template and basic specializations are moved to a new header, then some unmarshall functions are changed to use this code. This change avoids the need to repeat cleanup code in the unmarshallers. libcc1/ChangeLog 2021-01-03 Tom Tromey * rpc.hh (deleter): Move template and some specializations to deleter.hh. (argument_wrapper): Use cc1_plugin::unique_ptr. * marshall.cc (cc1_plugin::unmarshall): Use cc1_plugin::unique_ptr. * marshall-cp.hh (deleter): New specializations. (unmarshall): Use cc1_plugin::unique_ptr. * deleter.hh: New file. --- libcc1/ChangeLog | 11 ++++++ libcc1/deleter.hh | 53 +++++++++++++++++++++++++++++ libcc1/marshall-cp.hh | 79 +++++++++++++++++++++++++------------------ libcc1/marshall.cc | 11 +++--- libcc1/rpc.hh | 62 ++------------------------------- 5 files changed, 116 insertions(+), 100 deletions(-) create mode 100644 libcc1/deleter.hh diff --git a/libcc1/deleter.hh b/libcc1/deleter.hh new file mode 100644 index 00000000000..70553eef8f8 --- /dev/null +++ b/libcc1/deleter.hh @@ -0,0 +1,53 @@ +/* Deleter objects + Copyright (C) 2020 Free Software Foundation, Inc. + +This file is part of GCC. + +GCC 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, or (at your option) any later +version. + +GCC 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 GCC; see the file COPYING3. If not see +. */ + +#ifndef CC1_PLUGIN_DELETER_HH +#define CC1_PLUGIN_DELETER_HH + +#include + +namespace cc1_plugin +{ + // Any pointer type requires a deleter object that knows how to + // clean up. These are used in multiple places. + template struct deleter; + + template<> + struct deleter + { + void operator() (char *s) + { + delete[] s; + } + }; + + template<> + struct deleter + { + void operator() (gcc_type_array *p) + { + delete[] p->elements; + delete p; + } + }; + + template using unique_ptr = std::unique_ptr>; +} + +#endif // CC1_PLUGIN_DELETER_HH diff --git a/libcc1/marshall-cp.hh b/libcc1/marshall-cp.hh index e921ab0d3a9..f3c1dbd43ea 100644 --- a/libcc1/marshall-cp.hh +++ b/libcc1/marshall-cp.hh @@ -22,9 +22,42 @@ along with GCC; see the file COPYING3. If not see #include "marshall.hh" #include "gcc-cp-interface.h" +#include "deleter.hh" namespace cc1_plugin { + template<> + struct deleter + { + void operator() (gcc_vbase_array *p) + { + delete[] p->flags; + delete[] p->elements; + delete p; + } + }; + + template<> + struct deleter + { + void operator() (gcc_cp_template_args *p) + { + delete[] p->elements; + delete[] p->kinds; + delete p; + } + }; + + template<> + struct deleter + { + void operator() (gcc_cp_function_args *p) + { + delete[] p->elements; + delete p; + } + }; + // Send a gcc_vbase_array marker followed by the array. status marshall (connection *conn, const gcc_vbase_array *a) @@ -67,7 +100,7 @@ namespace cc1_plugin return OK; } - struct gcc_vbase_array *gva = new gcc_vbase_array; + cc1_plugin::unique_ptr gva (new gcc_vbase_array {}); gva->n_elements = len; gva->elements = new gcc_type[len]; @@ -75,25 +108,16 @@ namespace cc1_plugin if (!unmarshall_array_elmts (conn, len * sizeof (gva->elements[0]), gva->elements)) - { - delete[] gva->elements; - delete gva; - return FAIL; - } + return FAIL; gva->flags = new enum gcc_cp_symbol_kind[len]; if (!unmarshall_array_elmts (conn, len * sizeof (gva->flags[0]), gva->flags)) - { - delete[] gva->flags; - delete[] gva->elements; - delete gva; - return FAIL; - } + return FAIL; - *result = gva; + *result = gva.release (); return OK; } @@ -139,7 +163,8 @@ namespace cc1_plugin return OK; } - struct gcc_cp_template_args *gva = new gcc_cp_template_args; + cc1_plugin::unique_ptr gva + (new gcc_cp_template_args {}); gva->n_elements = len; gva->kinds = new char[len]; @@ -147,25 +172,16 @@ namespace cc1_plugin if (!unmarshall_array_elmts (conn, len * sizeof (gva->kinds[0]), gva->kinds)) - { - delete[] gva->kinds; - delete gva; - return FAIL; - } + return FAIL; gva->elements = new gcc_cp_template_arg[len]; if (!unmarshall_array_elmts (conn, len * sizeof (gva->elements[0]), gva->elements)) - { - delete[] gva->elements; - delete[] gva->kinds; - delete gva; - return FAIL; - } + return FAIL; - *result = gva; + *result = gva.release (); return OK; } @@ -208,7 +224,8 @@ namespace cc1_plugin return OK; } - struct gcc_cp_function_args *gva = new gcc_cp_function_args; + cc1_plugin::unique_ptr gva + (new gcc_cp_function_args {}); gva->n_elements = len; gva->elements = new gcc_expr[len]; @@ -216,13 +233,9 @@ namespace cc1_plugin if (!unmarshall_array_elmts (conn, len * sizeof (gva->elements[0]), gva->elements)) - { - delete[] gva->elements; - delete gva; - return FAIL; - } + return FAIL; - *result = gva; + *result = gva.release (); return OK; } diff --git a/libcc1/marshall.cc b/libcc1/marshall.cc index 368418a8215..5d2d3428a53 100644 --- a/libcc1/marshall.cc +++ b/libcc1/marshall.cc @@ -22,6 +22,7 @@ along with GCC; see the file COPYING3. If not see #include #include "marshall.hh" #include "connection.hh" +#include "rpc.hh" cc1_plugin::status cc1_plugin::unmarshall_check (connection *conn, unsigned long long check) @@ -175,7 +176,7 @@ cc1_plugin::unmarshall (connection *conn, gcc_type_array **result) return OK; } - gcc_type_array *gta = new gcc_type_array; + cc1_plugin::unique_ptr gta (new gcc_type_array {}); gta->n_elements = len; gta->elements = new gcc_type[len]; @@ -183,13 +184,9 @@ cc1_plugin::unmarshall (connection *conn, gcc_type_array **result) if (!unmarshall_array_elmts (conn, len * sizeof (gta->elements[0]), gta->elements)) - { - delete[] gta->elements; - delete *result; - return FAIL; - } + return FAIL; - *result = gta; + *result = gta.release (); return OK; } diff --git a/libcc1/rpc.hh b/libcc1/rpc.hh index 00f108d6dc9..f829e77682d 100644 --- a/libcc1/rpc.hh +++ b/libcc1/rpc.hh @@ -22,7 +22,7 @@ along with GCC; see the file COPYING3. If not see #include "status.hh" #include "connection.hh" -#include +#include "deleter.hh" namespace cc1_plugin { @@ -55,64 +55,6 @@ namespace cc1_plugin T m_object; }; - // Any pointer type requires a deleter object that knows how to - // clean up. These are used in multiple places. - template struct deleter; - - template<> - struct deleter - { - void operator() (char *s) - { - delete[] s; - } - }; - - template<> - struct deleter - { - void operator() (gcc_type_array *p) - { - delete[] p->elements; - delete p; - } - }; - -#ifdef GCC_CP_INTERFACE_H - template<> - struct deleter - { - void operator() (gcc_vbase_array *p) - { - delete[] p->flags; - delete[] p->elements; - delete p; - } - }; - - template<> - struct deleter - { - void operator() (gcc_cp_template_args *p) - { - delete[] p->elements; - delete[] p->kinds; - delete p; - } - }; - - template<> - struct deleter - { - void operator() (gcc_cp_function_args *p) - { - delete[] p->elements; - delete p; - } - }; - -#endif // GCC_CP_INTERFACE_H - // Specialization for any kind of pointer. template class argument_wrapper @@ -142,7 +84,7 @@ namespace cc1_plugin private: - std::unique_ptr> m_object; + unique_ptr m_object; }; // There are two kinds of template functions here: "call" and From patchwork Sun Jan 3 18:26:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 1421910 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=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=tromey.com 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=KTvj3Jpt; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 4D86gM0S7vz9sSs for ; Mon, 4 Jan 2021 05:27:27 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 82FAE3870869; Sun, 3 Jan 2021 18:26:41 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from gateway21.websitewelcome.com (gateway21.websitewelcome.com [192.185.45.147]) by sourceware.org (Postfix) with ESMTPS id 0A3CA385480B for ; Sun, 3 Jan 2021 18:26:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 0A3CA385480B 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 cm14.websitewelcome.com (cm14.websitewelcome.com [100.42.49.7]) by gateway21.websitewelcome.com (Postfix) with ESMTP id 8BB07400C6887 for ; Sun, 3 Jan 2021 12:26:35 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id w85LkNfi0svw9w85LkkkM0; Sun, 03 Jan 2021 12:26:35 -0600 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=aSAJkXpWiHKMbNVLSnTKmR5oJXuo+F4TrOpXeDT8FNg=; b=KTvj3Jpt31YIKhbzdV76hyI0HC gLnXAgfPDf+fI2p/IhNoMW2EMLsgAaIVeXcjkRigZrJLgj2C7Nj3MoIlzdYnMPBV2IojtaoyIp7zd Q/YL5wTPnkzC9+YULGvuSjOie; Received: from 97-122-81-39.hlrn.qwest.net ([97.122.81.39]:39392 helo=localhost.localdomain) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1kw85L-00234L-7Q; Sun, 03 Jan 2021 11:26:35 -0700 From: Tom Tromey To: gcc-patches@gcc.gnu.org Subject: [PATCH 10/10] libcc1: use unique_ptr more Date: Sun, 3 Jan 2021 11:26:31 -0700 Message-Id: <20210103182631.2316205-11-tom@tromey.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210103182631.2316205-1-tom@tromey.com> References: <20210103182631.2316205-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.81.39 X-Source-L: No X-Exim-ID: 1kw85L-00234L-7Q X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-81-39.hlrn.qwest.net (localhost.localdomain) [97.122.81.39]:39392 X-Source-Auth: tom+tromey.com X-Email-Count: 11 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3032.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_ABUSEAT, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_NEUTRAL, TXREP 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-01-03 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 82b1a6435b4..f79dac23137 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