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 3/4] Use new_reference for struct value
Date: Mon, 30 Apr 2018 04:21:00 -0000	[thread overview]
Message-ID: <20180430042147.28337-4-tom@tromey.com> (raw)
In-Reply-To: <20180430042147.28337-1-tom@tromey.com>

value_incref returned its argument just as a convenience, which in the
end turned out to only be used in precisely the cases where
new_reference helps.  So, this patch changes value_incref to return
void and changes some value-using code to use new_reference.

I also noticed that the comments for value_incref and value_decref
were swapped, so this patch fixes those.

2018-04-29  Tom Tromey  <tom@tromey.com>

	* varobj.c (install_new_value): Use new_reference.
	* value.h (value_incref): Return void.  Swap intro comment with
	value_decref.
	* value.c (set_value_parent): Use new_reference.
	(value_incref): Return void.  Update intro comment.
	(release_value): Use new_reference.
	* dwarf2loc.c (dwarf2_evaluate_loc_desc_full): Use new_reference.
---
 gdb/ChangeLog   | 10 ++++++++++
 gdb/dwarf2loc.c |  2 +-
 gdb/value.c     | 10 ++++------
 gdb/value.h     |  8 ++++----
 gdb/varobj.c    |  2 +-
 5 files changed, 20 insertions(+), 12 deletions(-)

diff --git a/gdb/dwarf2loc.c b/gdb/dwarf2loc.c
index 243e047b9a..78d46688bc 100644
--- a/gdb/dwarf2loc.c
+++ b/gdb/dwarf2loc.c
@@ -2482,7 +2482,7 @@ dwarf2_evaluate_loc_desc_full (struct type *type, struct frame_info *frame,
 	    /* Preserve VALUE because we are going to free values back
 	       to the mark, but we still need the value contents
 	       below.  */
-	    value_ref_ptr value_holder (value_incref (value));
+	    value_ref_ptr value_holder = value_ref_ptr::new_reference (value);
 	    free_values.free_to_mark ();
 
 	    retval = allocate_value (subobj_type);
diff --git a/gdb/value.c b/gdb/value.c
index 12aa2b8bb4..eefaaaab49 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -1133,7 +1133,7 @@ value_parent (const struct value *value)
 void
 set_value_parent (struct value *value, struct value *parent)
 {
-  value->parent = value_ref_ptr (value_incref (parent));
+  value->parent = value_ref_ptr::new_reference (parent);
 }
 
 gdb_byte *
@@ -1572,14 +1572,12 @@ value_mark (void)
   return all_values.back ().get ();
 }
 
-/* Take a reference to VAL.  VAL will not be deallocated until all
-   references are released.  */
+/* See value.h.  */
 
-struct value *
+void
 value_incref (struct value *val)
 {
   val->reference_count++;
-  return val;
 }
 
 /* Release a reference to VAL, which was acquired with value_incref.
@@ -1635,7 +1633,7 @@ release_value (struct value *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));
+  return value_ref_ptr::new_reference (val);
 }
 
 /* See value.h.  */
diff --git a/gdb/value.h b/gdb/value.h
index b58f78998a..060cef5639 100644
--- a/gdb/value.h
+++ b/gdb/value.h
@@ -88,12 +88,12 @@ struct value_print_options;
 
 struct value;
 
-/* Decrease VAL's reference count.  When the reference count drops to
-   0, VAL will be freed.  */
+/* Increase VAL's reference count.  VAL is returned.  */
 
-extern struct value *value_incref (struct value *val);
+extern void value_incref (struct value *val);
 
-/* Increate VAL's reference count.  VAL is returned.  */
+/* Decrease VAL's reference count.  When the reference count drops to
+   0, VAL will be freed.  */
 
 extern void value_decref (struct value *val);
 
diff --git a/gdb/varobj.c b/gdb/varobj.c
index 2d00964317..4656bfa6b9 100644
--- a/gdb/varobj.c
+++ b/gdb/varobj.c
@@ -1329,7 +1329,7 @@ install_new_value (struct varobj *var, struct value *value, bool initial)
      code that might release it.  */
   value_ref_ptr value_holder;
   if (value != NULL)
-    value_holder.reset (value_incref (value));
+    value_holder = value_ref_ptr::new_reference (value);
 
   /* Below, we'll be comparing string rendering of old and new
      values.  Don't get string rendering if the value is
-- 
2.13.6

  parent reply	other threads:[~2018-04-30  4:21 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-30  4:21 [RFA 0/4] add ref_ptr::new_reference Tom Tromey
2018-04-30  4:21 ` [RFA 4/4] Change Python code to use new_reference Tom Tromey
2018-04-30 13:34   ` Phil Muldoon
2018-04-30  4:21 ` Tom Tromey [this message]
2018-04-30 17:05   ` [RFA 3/4] Use new_reference for struct value Pedro Alves
2018-04-30 17:32     ` Tom Tromey
2018-04-30  4:21 ` [RFA 1/4] Introduce ref_ptr::new_reference Tom Tromey
2018-04-30  4:21 ` [RFA 2/4] Remove new_bfd_ref 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=20180430042147.28337-4-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).