public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [RFA 08/12] Remove value::next and value::released
Date: Thu, 05 Apr 2018 21:16:00 -0000	[thread overview]
Message-ID: <20180405211507.6103-9-tom@tromey.com> (raw)
In-Reply-To: <20180405211507.6103-1-tom@tromey.com>

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  <tom@tromey.com>

	* value.c (struct value) <released, next>: 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_ref_ptr> 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<value_ref_ptr> 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<value_ref_ptr>::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_ref_ptr>
 value_release_to_mark (const struct value *mark)
 {
   std::vector<value_ref_ptr> 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

  reply	other threads:[~2018-04-05 21:16 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-05 21:16 [RFA 00/12] (somewhat) clean up struct value ownership Tom Tromey
2018-04-05 21:16 ` Tom Tromey [this message]
2018-04-06 19:32   ` [RFA 08/12] Remove value::next and value::released Pedro Alves
2018-04-06 21:40     ` Tom Tromey
2018-04-05 21:16 ` [RFA 10/12] Change value::parent to a value_ref_ptr Tom Tromey
2018-04-05 21:16 ` [RFA 06/12] Remove free_all_values Tom Tromey
2018-04-05 21:16 ` [RFA 04/12] Change varobj to use value_ref_ptr Tom Tromey
2018-04-05 21:16 ` [RFA 12/12] Change value::contents to be a unique_xmalloc_ptr Tom Tromey
2018-04-05 21:16 ` [RFA 01/12] Introduce a gdb_ref_ptr specialization for struct value Tom Tromey
2018-04-06 19:29   ` Pedro Alves
2018-04-05 21:16 ` [RFA 05/12] Change value history to use value_ref_ptr Tom Tromey
2018-04-05 21:16 ` [RFA 09/12] Use new and delete for values Tom Tromey
2018-04-05 21:16 ` [RFA 03/12] Change last_examine_value to value_ref_ptr Tom Tromey
2018-04-05 21:16 ` [RFA 11/12] Remove range_s VEC Tom Tromey
2018-04-05 21:16 ` [RFA 07/12] Remove free_value_chain Tom Tromey
2018-04-05 21:16 ` [RFA 02/12] Change breakpoints to use value_ref_ptr Tom Tromey
2018-04-06 19:31   ` Pedro Alves
2018-04-06 21:31     ` Tom Tromey
2018-04-06 19:33 ` [RFA 00/12] (somewhat) clean up struct value ownership Pedro Alves
2018-04-06 21:20   ` Tom Tromey
2018-04-06 21:44   ` Tom Tromey
2018-04-08 21:32   ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180405211507.6103-9-tom@tromey.com \
    --to=tom@tromey.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).