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
{
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;
(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
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;
/* Values start out on the all_values chain. */
val->reference_count = 1;
+ all_values.emplace_back (val);
return val;
}
/* Accessor methods. */
-struct value *
-value_next (const struct value *value)
-{
- return value->next;
-}
-
struct type *
value_type (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
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
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));
}
/* See value.h. */
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;
}