From patchwork Thu Apr 5 21:15:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 26617 Received: (qmail 40442 invoked by alias); 5 Apr 2018 21:16:01 -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 40235 invoked by uid 89); 5 Apr 2018 21:15:30 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.4 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=our, management X-HELO: gateway24.websitewelcome.com Received: from gateway24.websitewelcome.com (HELO gateway24.websitewelcome.com) (192.185.51.228) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 05 Apr 2018 21:15:28 +0000 Received: from cm17.websitewelcome.com (cm17.websitewelcome.com [100.42.49.20]) by gateway24.websitewelcome.com (Postfix) with ESMTP id 9748E2E90 for ; Thu, 5 Apr 2018 16:15:19 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id 4CE3fBmWqy2aL4CE3fb5O7; Thu, 05 Apr 2018 16:15:19 -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 1f4CE3-003niR-DS; Thu, 05 Apr 2018 16:15:19 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 10/12] Change value::parent to a value_ref_ptr Date: Thu, 5 Apr 2018 15:15:05 -0600 Message-Id: <20180405211507.6103-11-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: 1f4CE3-003niR-DS 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: 11 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes This changes value::parent to a value_ref_ptr. This removes a bit of manual reference count management. ChangeLog 2018-04-05 Tom Tromey * value.c (~value): Update. (struct value) : Now a value_ref_ptr. (value_parent, set_value_parent, value_address, value_copy): Update. --- gdb/ChangeLog | 7 +++++++ gdb/value.c | 20 +++++--------------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/gdb/value.c b/gdb/value.c index 30af33c4d2..e25934b9e3 100644 --- a/gdb/value.c +++ b/gdb/value.c @@ -181,11 +181,6 @@ struct value ~value () { - /* If there's an associated parent value, drop our reference to - it. */ - if (parent != NULL) - value_decref (parent); - if (VALUE_LVAL (this) == lval_computed) { const struct lval_funcs *funcs = location.computed.funcs; @@ -292,7 +287,7 @@ struct value /* Only used for bitfields; the containing value. This allows a single read from the target when displaying multiple bitfields. */ - struct value *parent = nullptr; + value_ref_ptr parent; /* Type of the value. */ struct type *type; @@ -1128,7 +1123,7 @@ set_value_bitsize (struct value *value, LONGEST bit) struct value * value_parent (const struct value *value) { - return value->parent; + return value->parent.get (); } /* See value.h. */ @@ -1136,12 +1131,7 @@ value_parent (const struct value *value) void set_value_parent (struct value *value, struct value *parent) { - struct value *old = value->parent; - - value->parent = parent; - if (parent != NULL) - value_incref (parent); - value_decref (old); + value->parent = value_ref_ptr (value_incref (parent)); } gdb_byte * @@ -1521,7 +1511,7 @@ value_address (const struct value *value) if (value->lval != lval_memory) return 0; if (value->parent != NULL) - return value_address (value->parent) + value->offset; + return value_address (value->parent.get ()) + value->offset; if (NULL != TYPE_DATA_LOCATION (value_type (value))) { gdb_assert (PROP_CONST == TYPE_DATA_LOCATION_KIND (value_type (value))); @@ -1699,7 +1689,7 @@ value_copy (struct value *arg) } val->unavailable = VEC_copy (range_s, arg->unavailable); val->optimized_out = VEC_copy (range_s, arg->optimized_out); - set_value_parent (val, arg->parent); + val->parent = arg->parent; if (VALUE_LVAL (val) == lval_computed) { const struct lval_funcs *funcs = val->location.computed.funcs;