From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gateway32.websitewelcome.com (gateway32.websitewelcome.com [192.185.145.184]) by sourceware.org (Postfix) with ESMTPS id C73903950809 for ; Wed, 28 Apr 2021 01:01:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org C73903950809 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 gateway32.websitewelcome.com (Postfix) with ESMTP id 67E04227DA for ; Tue, 27 Apr 2021 20:01:41 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id bYaDloC6Pw11MbYaDlBjIP; Tue, 27 Apr 2021 20:01:41 -0500 X-Authority-Reason: nr=8 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=Jg8HUZyxRALoLe9K7O6n8bEIHUAG7oaQ7crJa5hf26Y=; b=gtqQWuF4Fja7KdRbRK0Wxj/d5r 0I8hksS8uvbhzBsFUJ1eySsUcmW0BF2La7DIPKKqQsnpR5f6+bpk0HqCh0auEuGP1Nr0Ner2xtUe/ 44f7xGZI9Xkq0wS40lxgQ5oe4; Received: from 97-122-70-176.hlrn.qwest.net ([97.122.70.176]:32966 helo=localhost.localdomain) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94) (envelope-from ) id 1lbYaD-003tiR-3B; Tue, 27 Apr 2021 19:01:41 -0600 From: Tom Tromey To: gcc-patches@gcc.gnu.org Cc: Tom Tromey Subject: [PATCH v2 07/21] libcc1: use std::vector when building function types Date: Tue, 27 Apr 2021 19:01:05 -0600 Message-Id: <20210428010119.806184-8-tom@tromey.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210428010119.806184-1-tom@tromey.com> References: <20210428010119.806184-1-tom@tromey.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - gcc.gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 97.122.70.176 X-Source-L: No X-Exim-ID: 1lbYaD-003tiR-3B X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-70-176.hlrn.qwest.net (localhost.localdomain) [97.122.70.176]:32966 X-Source-Auth: tom+tromey.com X-Email-Count: 8 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3032.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, RCVD_IN_SBL_CSS, SPF_HELO_PASS, SPF_NEUTRAL, TXREP, URIBL_CSS, URIBL_CSS_A autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 28 Apr 2021 01:01:46 -0000 This changes libcc1 to use std::vector in the code that builds function types. This avoids some explicit memory management. libcc1/ChangeLog 2021-04-27 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 59e4851064a2..65e748258f40 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 27a6175e34e6..1fc8e269f075 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)); -- 2.26.2