From patchwork Fri Nov 3 17:30:39 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 24076 Received: (qmail 52257 invoked by alias); 3 Nov 2017 17:30:49 -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 52245 invoked by uid 89); 3 Nov 2017 17:30:49 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.7 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=albeit, policy X-HELO: gateway23.websitewelcome.com Received: from gateway23.websitewelcome.com (HELO gateway23.websitewelcome.com) (192.185.50.164) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 03 Nov 2017 17:30:47 +0000 Received: from cm12.websitewelcome.com (cm12.websitewelcome.com [100.42.49.8]) by gateway23.websitewelcome.com (Postfix) with ESMTP id 2F2DD159FC for ; Fri, 3 Nov 2017 12:30:46 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id AfnqeYhYeDL8rAfnqeNpyD; Fri, 03 Nov 2017 12:30:46 -0500 Received: from 71-218-90-63.hlrn.qwest.net ([71.218.90.63]:60238 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89) (envelope-from ) id 1eAfnp-000wAw-Tg; Fri, 03 Nov 2017 12:30:46 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA] Use gdb::ref_ptr for values Date: Fri, 3 Nov 2017 11:30:39 -0600 Message-Id: <20171103173039.6397-1-tom@tromey.com> X-BWhitelist: no X-Source-L: No X-Exim-ID: 1eAfnp-000wAw-Tg X-Source-Sender: 71-218-90-63.hlrn.qwest.net (bapiya.Home) [71.218.90.63]:60238 X-Source-Auth: tom+tromey.com X-Email-Count: 7 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes A while back I introduced gdb_value_up, a unique_ptr specialization for struct value. However, I think this is incorrect -- values are reference counted (albeit in a somewhat strange way), and so it's better to use a gdb::ref_ptr specialization. This patch makes this change. There was only one use of gdb_value_up. Regression tested on the buildbot. gdb/ChangeLog 2017-11-03 Tom Tromey * value.h (struct value_ref_policy): Rename from value_deleter. Change to be gdb::ref_ptr policy class. (gdb_value_ref): Rename from gdb_value_up. Use gdb::ref_ptr., 2017 * dwarf2loc.c (dwarf2_evaluate_loc_desc_full): Use gdb_value_ref. --- gdb/ChangeLog | 7 +++++++ gdb/dwarf2loc.c | 2 +- gdb/value.h | 17 +++++++++++------ 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/gdb/dwarf2loc.c b/gdb/dwarf2loc.c index fe2fea0d0e..0ae604e9ce 100644 --- a/gdb/dwarf2loc.c +++ b/gdb/dwarf2loc.c @@ -2487,7 +2487,7 @@ dwarf2_evaluate_loc_desc_full (struct type *type, struct frame_info *frame, below. */ value_incref (value); free_values.free_to_mark (); - gdb_value_up value_holder (value); + gdb_value_ref value_holder (value); retval = allocate_value (subobj_type); diff --git a/gdb/value.h b/gdb/value.h index cfc8caea05..f581071812 100644 --- a/gdb/value.h +++ b/gdb/value.h @@ -22,6 +22,7 @@ #include "doublest.h" #include "frame.h" /* For struct frame_id. */ +#include "common/gdb_ref_ptr.h" struct block; struct expression; @@ -1022,20 +1023,24 @@ extern void value_incref (struct value *val); extern void value_free (struct value *val); -/* A free policy class to interface std::unique_ptr with - value_free. */ +/* A policy class to interface gdb::ref_ptr with value. */ -struct value_deleter +struct value_ref_policy { - void operator() (struct value *value) const + static void incref (struct value *value) + { + value_incref (value); + } + + static void decref (struct value *value) { value_free (value); } }; -/* A unique pointer to a struct value. */ +/* A refcounted pointer to a struct value. */ -typedef std::unique_ptr gdb_value_up; +typedef gdb::ref_ptr gdb_value_ref; extern void free_all_values (void);