This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[4/4] clean up value parenting


This just fixes something I noticed while looking at further synthetic
pointer improvements that Jakub asked for.

Right now, refcounts for value parenting is handled by various callers.
It seems cleaner to me to have set_value_parent handle the details.

Built and regtested on x86-64 Fedora 18.

Tom

	* ada-lang.c (ada_value_primitive_packed_val): Don't
	call value_incref.
	* value.c (set_value_parent): Incref the new parent and decref
	the old parent.
	(value_copy, value_primitive_field): Use set_value_parent.
---
 gdb/ada-lang.c |  1 -
 gdb/value.c    | 12 +++++++-----
 2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 0329dd9..84fb34d 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -2325,7 +2325,6 @@ ada_value_primitive_packed_val (struct value *obj, const gdb_byte *valaddr,
       /* Also set the parent value.  This is needed when trying to
 	 assign a new value (in inferior memory).  */
       set_value_parent (v, obj);
-      value_incref (obj);
     }
   else
     set_value_bitsize (v, bit_size);
diff --git a/gdb/value.c b/gdb/value.c
index 90bc415..ee3c998 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -811,7 +811,12 @@ value_parent (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_free (old);
 }
 
 gdb_byte *
@@ -1398,9 +1403,7 @@ value_copy (struct value *arg)
 
     }
   val->unavailable = VEC_copy (range_s, arg->unavailable);
-  val->parent = arg->parent;
-  if (val->parent)
-    value_incref (val->parent);
+  set_value_parent (val, arg->parent);
   if (VALUE_LVAL (val) == lval_computed)
     {
       const struct lval_funcs *funcs = val->location.computed.funcs;
@@ -2652,8 +2655,7 @@ value_primitive_field (struct value *arg1, int offset,
       v->offset = (value_embedded_offset (arg1)
 		   + offset
 		   + (bitpos - v->bitpos) / 8);
-      v->parent = arg1;
-      value_incref (v->parent);
+      set_value_parent (v, arg1);
       if (!value_lazy (arg1))
 	value_fetch_lazy (v);
     }
-- 
1.8.1.4


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]