From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gateway31.websitewelcome.com (gateway31.websitewelcome.com [192.185.144.28]) by sourceware.org (Postfix) with ESMTPS id EE1DC3857C5A for ; Sun, 9 Aug 2020 13:53:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org EE1DC3857C5A 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 gateway31.websitewelcome.com (Postfix) with ESMTP id 2CA6D13A02 for ; Sun, 9 Aug 2020 08:53:03 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id 4lkzkymPYBD8b4lkzkYqZz; Sun, 09 Aug 2020 08:53:03 -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=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: 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=W8bNLbiwxIHJuwIcMgdtT6bTD73vd1qTSDnuLp34NzY=; b=G1ZMP9H3x0vcIm5uFn8LZUa3wy 39sV159NyM/2+lcXgfprUHaus+9S61T5EhucSp70VKX7PEKA6gYhRs4QdAbRdldrryuV56oTo/D5A jELJ44qQySbS6wmfU14ThX/eU; Received: from 75-166-101-103.hlrn.qwest.net ([75.166.101.103]:56058 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1k4lkz-0022sH-2W; Sun, 09 Aug 2020 07:53:01 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 1/6] Remove some manual memory management from compile interface Date: Sun, 9 Aug 2020 07:52:53 -0600 Message-Id: <20200809135258.8207-2-tom@tromey.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20200809135258.8207-1-tom@tromey.com> References: <20200809135258.8207-1-tom@tromey.com> X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 75.166.101.103 X-Source-L: No X-Exim-ID: 1k4lkz-0022sH-2W X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 75-166-101-103.hlrn.qwest.net (bapiya.Home) [75.166.101.103]:56058 X-Source-Auth: tom+tromey.com X-Email-Count: 2 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3035.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_STOCKGEN, RCVD_IN_ABUSEAT, 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: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 09 Aug 2020 13:53:06 -0000 This changes gdb's compile code to use std::vector in a couple of places, rather than manual memory management. gdb/ChangeLog 2020-08-08 Tom Tromey * compile/compile-cplus-types.c (compile_cplus_convert_struct_or_union): Use std::vector. (compile_cplus_convert_func): Likewise. * compile/compile-c-types.c (convert_func): Use std::vector. --- gdb/ChangeLog | 7 ++++++ gdb/compile/compile-c-types.c | 4 ++-- gdb/compile/compile-cplus-types.c | 39 +++++++++++++++---------------- 3 files changed, 28 insertions(+), 22 deletions(-) diff --git a/gdb/compile/compile-c-types.c b/gdb/compile/compile-c-types.c index 2b25783bb00..7816ececb25 100644 --- a/gdb/compile/compile-c-types.c +++ b/gdb/compile/compile-c-types.c @@ -176,13 +176,13 @@ convert_func (compile_c_instance *context, struct type *type) return_type = context->convert_type (target_type); array.n_elements = type->num_fields (); - array.elements = XNEWVEC (gcc_type, type->num_fields ()); + std::vector elements (array.n_elements); + array.elements = elements.data (); for (i = 0; i < type->num_fields (); ++i) array.elements[i] = context->convert_type (type->field (i).type ()); result = context->plugin ().build_function_type (return_type, &array, is_varargs); - xfree (array.elements); return result; } diff --git a/gdb/compile/compile-cplus-types.c b/gdb/compile/compile-cplus-types.c index 02df7ab90e6..00eaaf3fa68 100644 --- a/gdb/compile/compile-cplus-types.c +++ b/gdb/compile/compile-cplus-types.c @@ -848,33 +848,33 @@ compile_cplus_convert_struct_or_union (compile_cplus_instance *instance, gcc_type result; if (type->code () == TYPE_CODE_STRUCT) { - struct gcc_vbase_array bases; int num_baseclasses = TYPE_N_BASECLASSES (type); + std::vector elements (num_baseclasses); + std::vector flags (num_baseclasses); - memset (&bases, 0, sizeof (bases)); + struct gcc_vbase_array bases {}; + bases.elements = elements.data (); if (num_baseclasses > 0) { - bases.elements = XNEWVEC (gcc_type, num_baseclasses); - bases.flags = XNEWVEC (enum gcc_cp_symbol_kind, num_baseclasses); + bases.flags = flags.data (); bases.n_elements = num_baseclasses; - for (int i = 0; i < num_baseclasses; ++i) - { - struct type *base_type = TYPE_BASECLASS (type, i); - - bases.flags[i] = GCC_CP_SYMBOL_BASECLASS - | get_field_access_flag (type, i) - | (BASETYPE_VIA_VIRTUAL (type, i) - ? GCC_CP_FLAG_BASECLASS_VIRTUAL - : GCC_CP_FLAG_BASECLASS_NOFLAG); - bases.elements[i] = instance->convert_type (base_type); - } + } + + for (int i = 0; i < num_baseclasses; ++i) + { + struct type *base_type = TYPE_BASECLASS (type, i); + + bases.flags[i] = (GCC_CP_SYMBOL_BASECLASS + | get_field_access_flag (type, i) + | (BASETYPE_VIA_VIRTUAL (type, i) + ? GCC_CP_FLAG_BASECLASS_VIRTUAL + : GCC_CP_FLAG_BASECLASS_NOFLAG)); + bases.elements[i] = instance->convert_type (base_type); } result = instance->plugin ().start_class_type (name.get (), resuld, &bases, filename, line); - xfree (bases.flags); - xfree (bases.elements); } else { @@ -985,8 +985,8 @@ compile_cplus_convert_func (compile_cplus_instance *instance, types. Those are impossible in C, though. */ gcc_type return_type = instance->convert_type (target_type); - struct gcc_type_array array = - { type->num_fields (), XNEWVEC (gcc_type, type->num_fields ()) }; + std::vector elements (type->num_fields ()); + struct gcc_type_array array = { type->num_fields (), elements.data () }; int artificials = 0; for (int i = 0; i < type->num_fields (); ++i) { @@ -1006,7 +1006,6 @@ compile_cplus_convert_func (compile_cplus_instance *instance, with some minsyms like printf (compile-cplus.exp has examples). */ gcc_type result = instance->plugin ().build_function_type (return_type, &array, is_varargs); - xfree (array.elements); return result; } -- 2.17.2