From patchwork Thu Apr 5 21:15:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 26624 Received: (qmail 40889 invoked by alias); 5 Apr 2018 21:16:07 -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 40287 invoked by uid 89); 5 Apr 2018 21:15:34 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.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_HELO_PASS autolearn=ham version=3.3.2 spammy= X-HELO: gateway31.websitewelcome.com Received: from gateway31.websitewelcome.com (HELO gateway31.websitewelcome.com) (192.185.144.96) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 05 Apr 2018 21:15:28 +0000 Received: from cm15.websitewelcome.com (cm15.websitewelcome.com [100.42.49.9]) by gateway31.websitewelcome.com (Postfix) with ESMTP id 414C65515 for ; Thu, 5 Apr 2018 16:15:20 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id 4CE4fVM0sntAo4CE4f7DLJ; Thu, 05 Apr 2018 16:15:20 -0500 Received: from 75-166-37-45.hlrn.qwest.net ([75.166.37.45]:47524 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89_1) (envelope-from ) id 1f4CE4-003niR-1T; Thu, 05 Apr 2018 16:15:20 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 12/12] Change value::contents to be a unique_xmalloc_ptr Date: Thu, 5 Apr 2018 15:15:07 -0600 Message-Id: <20180405211507.6103-13-tom@tromey.com> In-Reply-To: <20180405211507.6103-1-tom@tromey.com> References: <20180405211507.6103-1-tom@tromey.com> X-BWhitelist: no X-Source-L: No X-Exim-ID: 1f4CE4-003niR-1T X-Source-Sender: 75-166-37-45.hlrn.qwest.net (bapiya.Home) [75.166.37.45]:47524 X-Source-Auth: tom+tromey.com X-Email-Count: 13 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes This changes value::contents to be a unique_xmalloc_ptr, removing a small bit of manual memory management. ChangeLog 2018-04-05 Tom Tromey * value.c (~value): Update. (struct value) : Now unique_xmalloc_ptr. (value_contents_bits_eq, allocate_value_contents) (value_contents_raw, value_contents_all_raw) (value_contents_for_printing, value_contents_for_printing_const) (set_value_enclosing_type): Update. --- gdb/ChangeLog | 9 +++++++++ gdb/value.c | 23 +++++++++++------------ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/gdb/value.c b/gdb/value.c index e39a3f0aac..acef33ccd9 100644 --- a/gdb/value.c +++ b/gdb/value.c @@ -186,8 +186,6 @@ struct value } else if (VALUE_LVAL (this) == lval_xcallable) delete location.xm_worker; - - xfree (contents); } DISABLE_COPY_AND_ASSIGN (value); @@ -332,7 +330,7 @@ struct value /* Actual contents of the value. Target byte-order. NULL or not valid if lazy is nonzero. */ - gdb_byte *contents = nullptr; + gdb::unique_xmalloc_ptr contents; /* Unavailable ranges in CONTENTS. We mark unavailable ranges, rather than available, since the common and default case is for a @@ -875,8 +873,8 @@ value_contents_bits_eq (const struct value *val1, int offset1, } /* Compare the available/valid contents. */ - if (memcmp_with_bit_offsets (val1->contents, offset1, - val2->contents, offset2, l) != 0) + if (memcmp_with_bit_offsets (val1->contents.get (), offset1, + val2->contents.get (), offset2, l) != 0) return false; length -= h; @@ -1012,8 +1010,8 @@ allocate_value_contents (struct value *val) if (!val->contents) { check_type_length_before_alloc (val->enclosing_type); - val->contents - = (gdb_byte *) xzalloc (TYPE_LENGTH (val->enclosing_type)); + val->contents.reset + ((gdb_byte *) xzalloc (TYPE_LENGTH (val->enclosing_type))); } } @@ -1137,14 +1135,14 @@ value_contents_raw (struct value *value) int unit_size = gdbarch_addressable_memory_unit_size (arch); allocate_value_contents (value); - return value->contents + value->embedded_offset * unit_size; + return value->contents.get () + value->embedded_offset * unit_size; } gdb_byte * value_contents_all_raw (struct value *value) { allocate_value_contents (value); - return value->contents; + return value->contents.get (); } struct type * @@ -1227,14 +1225,14 @@ value_contents_for_printing (struct value *value) { if (value->lazy) value_fetch_lazy (value); - return value->contents; + return value->contents.get (); } const gdb_byte * value_contents_for_printing_const (const struct value *value) { gdb_assert (!value->lazy); - return value->contents; + return value->contents.get (); } const gdb_byte * @@ -2876,7 +2874,8 @@ set_value_enclosing_type (struct value *val, struct type *new_encl_type) { check_type_length_before_alloc (new_encl_type); val->contents - = (gdb_byte *) xrealloc (val->contents, TYPE_LENGTH (new_encl_type)); + .reset ((gdb_byte *) xrealloc (val->contents.release (), + TYPE_LENGTH (new_encl_type))); } val->enclosing_type = new_encl_type;