From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 40727 invoked by alias); 5 Apr 2018 21:16:06 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 40257 invoked by uid 89); 5 Apr 2018 21:15:31 -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=sk:referen, 1989 X-HELO: gateway20.websitewelcome.com Received: from gateway20.websitewelcome.com (HELO gateway20.websitewelcome.com) (192.185.54.2) 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 gateway20.websitewelcome.com (Postfix) with ESMTP id 01D98400C5537 for ; Thu, 5 Apr 2018 16:15:19 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id 4CE2fBmVey2aL4CE2fb5N3; Thu, 05 Apr 2018 16:15:18 -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 1f4CE2-003niR-Pp; Thu, 05 Apr 2018 16:15:18 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 08/12] Remove value::next and value::released Date: Thu, 05 Apr 2018 21:16:00 -0000 Message-Id: <20180405211507.6103-9-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: 1f4CE2-003niR-Pp 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: 9 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-SW-Source: 2018-04/txt/msg00088.txt.bz2 This patch converts all_values to simply hold a list of references to values. Now, there's no need to have a value record whether or not it is released -- there is only a single reference-counting mechanism for values. So, this also removes value::next, value::released, and value_next. ChangeLog 2018-04-05 Tom Tromey * value.c (struct value) : Remove. (all_values): Now a std::vector. (allocate_value_lazy): Update. (value_next): Remove. (value_mark, value_free_to_mark, release_value) (value_release_to_mark): Update. --- gdb/ChangeLog | 9 ++++++ gdb/value.c | 95 +++++++++++++++++------------------------------------------ 2 files changed, 36 insertions(+), 68 deletions(-) diff --git a/gdb/value.c b/gdb/value.c index fed722da51..3137bf48f8 100644 --- a/gdb/value.c +++ b/gdb/value.c @@ -198,9 +198,6 @@ struct value used instead of read_memory to enable extra caching. */ unsigned int stack : 1; - /* If the value has been released. */ - unsigned int released : 1; - /* Location of value (if lval). */ union { @@ -309,12 +306,6 @@ struct value LONGEST embedded_offset; LONGEST pointed_to_offset; - /* Values are stored in a chain, so that they can be deleted easily - over calls to the inferior. Values assigned to internal - variables, put into the value history or exposed to Python are - taken off this list. */ - struct value *next; - /* Actual contents of the value. Target byte-order. NULL or not valid if lazy is nonzero. */ gdb_byte *contents; @@ -891,7 +882,7 @@ static std::vector value_history; (except for those released by calls to release_value) This is so they can be freed after each command. */ -static struct value *all_values; +static std::vector all_values; /* Allocate a lazy value for type TYPE. Its actual content is "lazily" allocated too: the content field of the return value is @@ -912,8 +903,6 @@ allocate_value_lazy (struct type *type) val = XCNEW (struct value); val->contents = NULL; - val->next = all_values; - all_values = val; val->type = type; val->enclosing_type = type; VALUE_LVAL (val) = not_lval; @@ -929,6 +918,7 @@ allocate_value_lazy (struct type *type) /* Values start out on the all_values chain. */ val->reference_count = 1; + all_values.emplace_back (val); return val; } @@ -1070,12 +1060,6 @@ allocate_optimized_out_value (struct type *type) /* Accessor methods. */ -struct value * -value_next (const struct value *value) -{ - return value->next; -} - struct type * value_type (const struct value *value) { @@ -1573,7 +1557,9 @@ deprecated_value_modifiable (const struct value *value) struct value * value_mark (void) { - return all_values; + if (all_values.empty ()) + return nullptr; + return all_values.back ().get (); } /* Take a reference to VAL. VAL will not be deallocated until all @@ -1626,16 +1612,11 @@ value_decref (struct value *val) void value_free_to_mark (const struct value *mark) { - struct value *val; - struct value *next; - - for (val = all_values; val && val != mark; val = next) - { - next = val->next; - val->released = 1; - value_decref (val); - } - all_values = val; + auto iter = std::find (all_values.begin (), all_values.end (), mark); + if (iter == all_values.end ()) + all_values.clear (); + else + all_values.erase (iter + 1, all_values.end ()); } /* Remove VAL from the chain all_values @@ -1645,40 +1626,25 @@ value_ref_ptr release_value (struct value *val) { struct value *v; - bool released = false; if (val == nullptr) return value_ref_ptr (); - if (all_values == val) - { - all_values = val->next; - val->next = NULL; - released = true; - } - else + std::vector::reverse_iterator iter; + for (iter = all_values.rbegin (); iter != all_values.rend (); ++iter) { - for (v = all_values; v; v = v->next) + if (*iter == val) { - if (v->next == val) - { - v->next = val->next; - val->next = NULL; - released = true; - break; - } + value_ref_ptr result = *iter; + all_values.erase (iter.base () - 1); + return result; } } - if (!released) - { - /* We must always return an owned reference. Normally this - happens because we transfer the reference from the value - chain, but in this case the value was not on the chain. */ - value_incref (val); - } - - return value_ref_ptr (val); + /* We must always return an owned reference. Normally this happens + because we transfer the reference from the value chain, but in + this case the value was not on the chain. */ + return value_ref_ptr (value_incref (val)); } /* Release all values up to mark */ @@ -1686,23 +1652,16 @@ std::vector value_release_to_mark (const struct value *mark) { std::vector result; - struct value *next; - for (next = all_values; next; next = next->next) + auto iter = std::find (all_values.begin (), all_values.end (), mark); + if (iter == all_values.end ()) + std::swap (result, all_values); + else { - next->released = 1; - result.emplace_back (next); - - if (next->next == mark) - { - struct value *save = next->next; - next->next = NULL; - next = save; - break; - } + std::move (iter + 1, all_values.end (), std::back_inserter (result)); + all_values.erase (iter + 1, all_values.end ()); } - - all_values = next; + std::reverse (result.begin (), result.end ()); return result; } -- 2.13.6