From patchwork Tue Jan 7 22:07:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 37243 Received: (qmail 108788 invoked by alias); 7 Jan 2020 22:08:00 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 108650 invoked by uid 89); 7 Jan 2020 22:07:59 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-22.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=HContent-Transfer-Encoding:8bit X-HELO: rock.gnat.com Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 07 Jan 2020 22:07:58 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 1AA51116542; Tue, 7 Jan 2020 17:07:57 -0500 (EST) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id kGy9cnRRWqD6; Tue, 7 Jan 2020 17:07:57 -0500 (EST) Received: from murgatroyd.Home (75-166-123-50.hlrn.qwest.net [75.166.123.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by rock.gnat.com (Postfix) with ESMTPSA id CCAF3116414; Tue, 7 Jan 2020 17:07:56 -0500 (EST) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 3/4] Use std::vector in abbrev_table_read_table Date: Tue, 7 Jan 2020 15:07:53 -0700 Message-Id: <20200107220754.24796-4-tromey@adacore.com> In-Reply-To: <20200107220754.24796-1-tromey@adacore.com> References: <20200107220754.24796-1-tromey@adacore.com> MIME-Version: 1.0 This removes some manual memory management from abbrev_table_read_table, replacing it with a std::vector. gdb/ChangeLog 2020-01-07 Tom Tromey * dwarf2read.c (abbrev_table_read_table): Use std::vector. Change-Id: I0b0e70ac2281d89a78f4d6a642700c9f0506871d --- gdb/ChangeLog | 4 ++++ gdb/dwarf2read.c | 27 ++++++++------------------- 2 files changed, 12 insertions(+), 19 deletions(-) diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index e6584d96537..ad361df00b9 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -18563,8 +18563,7 @@ abbrev_table_read_table (struct dwarf2_per_objfile *dwarf2_per_objfile, struct abbrev_info *cur_abbrev; unsigned int abbrev_number, bytes_read, abbrev_name; unsigned int abbrev_form; - struct attr_abbrev *cur_attrs; - unsigned int allocated_attrs; + std::vector cur_attrs; abbrev_table_up abbrev_table (new struct abbrev_table (sect_off)); @@ -18573,12 +18572,10 @@ abbrev_table_read_table (struct dwarf2_per_objfile *dwarf2_per_objfile, abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); abbrev_ptr += bytes_read; - allocated_attrs = ATTR_ALLOC_CHUNK; - cur_attrs = XNEWVEC (struct attr_abbrev, allocated_attrs); - /* Loop until we reach an abbrev number of 0. */ while (abbrev_number) { + cur_attrs.clear (); cur_abbrev = abbrev_table->alloc_abbrev (); /* read in abbrev header */ @@ -18613,25 +18610,18 @@ abbrev_table_read_table (struct dwarf2_per_objfile *dwarf2_per_objfile, if (abbrev_name == 0) break; - if (cur_abbrev->num_attrs == allocated_attrs) - { - allocated_attrs += ATTR_ALLOC_CHUNK; - cur_attrs - = XRESIZEVEC (struct attr_abbrev, cur_attrs, allocated_attrs); - } - - cur_attrs[cur_abbrev->num_attrs].name - = (enum dwarf_attribute) abbrev_name; - cur_attrs[cur_abbrev->num_attrs].form - = (enum dwarf_form) abbrev_form; - cur_attrs[cur_abbrev->num_attrs].implicit_const = implicit_const; + cur_attrs.emplace_back (); + struct attr_abbrev &cur_attr = cur_attrs.back (); + cur_attr.name = (enum dwarf_attribute) abbrev_name; + cur_attr.form = (enum dwarf_form) abbrev_form; + cur_attr.implicit_const = implicit_const; ++cur_abbrev->num_attrs; } cur_abbrev->attrs = XOBNEWVEC (&abbrev_table->abbrev_obstack, struct attr_abbrev, cur_abbrev->num_attrs); - memcpy (cur_abbrev->attrs, cur_attrs, + memcpy (cur_abbrev->attrs, cur_attrs.data (), cur_abbrev->num_attrs * sizeof (struct attr_abbrev)); abbrev_table->add_abbrev (abbrev_number, cur_abbrev); @@ -18651,7 +18641,6 @@ abbrev_table_read_table (struct dwarf2_per_objfile *dwarf2_per_objfile, break; } - xfree (cur_attrs); return abbrev_table; }