Skip to content

Commit 4e7a5ef

Browse files
author
Tom Tromey
committed
* varobj.c (update_dynamic_varobj_children): Don't use
value_copy. * value.h: (preserve_one_value): Declare. (value_prepend_to_list, value_remove_from_list): Remove. * value.c (preserve_one_value): No longer static. (preserve_values): Call preserve_python_values. (value_prepend_to_list): Remove. (value_remove_from_list): Remove. * python/python.h (values_in_python): Don't declare. (preserve_python_values): Declare. * python/python-value.c (values_in_python): Change type. Move lower. Now static. (struct value_object): Add struct tag. <next, prev>: New fields. (valpy_dealloc): Update. (note_value): New function. (valpy_new): Use value_incref, note_value. (preserve_python_values): New function. (valpy_positive): Don't use value_copy. (value_to_value_object): Use value_incref, note_value. (convert_value_from_python): Update comment.
1 parent ecd0ada commit 4e7a5ef

6 files changed

Lines changed: 90 additions & 65 deletions

File tree

‎gdb/ChangeLog‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
1+
2009-08-13 Tom Tromey <tromey@redhat.com>
2+
3+
* varobj.c (update_dynamic_varobj_children): Don't use
4+
value_copy.
5+
* value.h: (preserve_one_value): Declare.
6+
(value_prepend_to_list, value_remove_from_list): Remove.
7+
* value.c (preserve_one_value): No longer static.
8+
(preserve_values): Call preserve_python_values.
9+
(value_prepend_to_list): Remove.
10+
(value_remove_from_list): Remove.
11+
* python/python.h (values_in_python): Don't declare.
12+
(preserve_python_values): Declare.
13+
* python/python-value.c (values_in_python): Change type. Move
14+
lower. Now static.
15+
(struct value_object): Add struct tag.
16+
<next, prev>: New fields.
17+
(valpy_dealloc): Update.
18+
(note_value): New function.
19+
(valpy_new): Use value_incref, note_value.
20+
(preserve_python_values): New function.
21+
(valpy_positive): Don't use value_copy.
22+
(value_to_value_object): Use value_incref, note_value.
23+
(convert_value_from_python): Update comment.
24+
125
2009-08-13 Pedro Alves <pedro@codesourcery.com>
226

327
* remote.c (remote_pid_to_str): If printing a process id and we

‎gdb/python/python-value.c‎

Lines changed: 59 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,6 @@
2626
#include "dfp.h"
2727
#include "valprint.h"
2828

29-
/* List of all values which are currently exposed to Python. It is
30-
maintained so that when an objfile is discarded, preserve_values
31-
can copy the values' types if needed. This is declared
32-
unconditionally to reduce the number of uses of HAVE_PYTHON in the
33-
generic code. */
34-
/* This variable is unnecessarily initialized to NULL in order to
35-
work around a linker bug on MacOS. */
36-
struct value *values_in_python = NULL;
37-
3829
#ifdef HAVE_PYTHON
3930

4031
#include "python-internal.h"
@@ -58,20 +49,38 @@ struct value *values_in_python = NULL;
5849
#define builtin_type_pychar \
5950
language_string_char_type (python_language, python_gdbarch)
6051

61-
typedef struct {
52+
typedef struct value_object {
6253
PyObject_HEAD
54+
struct value_object *next;
55+
struct value_object *prev;
6356
struct value *value;
6457
PyObject *address;
6558
PyObject *type;
6659
} value_object;
6760

61+
/* List of all values which are currently exposed to Python. It is
62+
maintained so that when an objfile is discarded, preserve_values
63+
can copy the values' types if needed. */
64+
/* This variable is unnecessarily initialized to NULL in order to
65+
work around a linker bug on MacOS. */
66+
static value_object *values_in_python = NULL;
67+
6868
/* Called by the Python interpreter when deallocating a value object. */
6969
static void
7070
valpy_dealloc (PyObject *obj)
7171
{
7272
value_object *self = (value_object *) obj;
7373

74-
value_remove_from_list (&values_in_python, self->value);
74+
/* Remove SELF from the global list. */
75+
if (self->prev)
76+
self->prev->next = self->next;
77+
else
78+
{
79+
gdb_assert (values_in_python == self);
80+
values_in_python = self->next;
81+
}
82+
if (self->next)
83+
self->next->prev = self->prev;
7584

7685
value_free (self->value);
7786

@@ -89,6 +98,17 @@ valpy_dealloc (PyObject *obj)
8998
self->ob_type->tp_free (self);
9099
}
91100

101+
/* Helper to push a Value object on the global list. */
102+
static void
103+
note_value (value_object *value_obj)
104+
{
105+
value_obj->next = values_in_python;
106+
if (value_obj->next)
107+
value_obj->next->prev = value_obj;
108+
value_obj->prev = NULL;
109+
values_in_python = value_obj;
110+
}
111+
92112
/* Called when a new gdb.Value object needs to be allocated. */
93113
static PyObject *
94114
valpy_new (PyTypeObject *subtype, PyObject *args, PyObject *keywords)
@@ -119,14 +139,25 @@ valpy_new (PyTypeObject *subtype, PyObject *args, PyObject *keywords)
119139
}
120140

121141
value_obj->value = value;
142+
value_incref (value);
122143
value_obj->address = NULL;
123144
value_obj->type = NULL;
124-
release_value (value);
125-
value_prepend_to_list (&values_in_python, value);
145+
note_value (value_obj);
126146

127147
return (PyObject *) value_obj;
128148
}
129149

150+
/* Iterate over all the Value objects, calling preserve_one_value on
151+
each. */
152+
void
153+
preserve_python_values (struct objfile *objfile, htab_t copied_types)
154+
{
155+
value_object *iter;
156+
157+
for (iter = values_in_python; iter; iter = iter->next)
158+
preserve_one_value (iter->value, objfile, copied_types);
159+
}
160+
130161
/* Given a value of a pointer type, apply the C unary * operator to it. */
131162
static PyObject *
132163
valpy_dereference (PyObject *self, PyObject *args)
@@ -543,9 +574,7 @@ valpy_negative (PyObject *self)
543574
static PyObject *
544575
valpy_positive (PyObject *self)
545576
{
546-
struct value *copy = value_copy (((value_object *) self)->value);
547-
548-
return value_to_value_object (copy);
577+
return value_to_value_object (((value_object *) self)->value);
549578
}
550579

551580
static PyObject *
@@ -800,16 +829,17 @@ value_to_value_object (struct value *val)
800829
if (val_obj != NULL)
801830
{
802831
val_obj->value = val;
832+
value_incref (val);
803833
val_obj->address = NULL;
804834
val_obj->type = NULL;
805-
release_value (val);
806-
value_prepend_to_list (&values_in_python, val);
835+
note_value (val_obj);
807836
}
808837

809838
return (PyObject *) val_obj;
810839
}
811840

812-
/* Returns value structure corresponding to the given value object. */
841+
/* Returns a borrowed reference to the struct value corresponding to
842+
the given value object. */
813843
struct value *
814844
value_object_to_value (PyObject *self)
815845
{
@@ -821,7 +851,8 @@ value_object_to_value (PyObject *self)
821851
}
822852

823853
/* Try to convert a Python value to a gdb value. If the value cannot
824-
be converted, set a Python exception and return NULL. */
854+
be converted, set a Python exception and return NULL. Returns a
855+
reference to a new value on the all_values chain. */
825856

826857
struct value *
827858
convert_value_from_python (PyObject *obj)
@@ -1019,4 +1050,12 @@ PyTypeObject value_object_type = {
10191050
valpy_new /* tp_new */
10201051
};
10211052

1053+
#else
1054+
1055+
void
1056+
preserve_python_values (struct objfile *objfile, htab_t copied_types)
1057+
{
1058+
/* Nothing. */
1059+
}
1060+
10221061
#endif /* HAVE_PYTHON */

‎gdb/python/python.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222

2323
#include "value.h"
2424

25-
extern struct value *values_in_python;
26-
2725
void eval_python_from_control_command (struct command_line *);
2826

2927
int apply_val_pretty_printer (struct type *type, const gdb_byte *valaddr,
@@ -32,4 +30,6 @@ int apply_val_pretty_printer (struct type *type, const gdb_byte *valaddr,
3230
const struct value_print_options *options,
3331
const struct language_defn *language);
3432

33+
void preserve_python_values (struct objfile *objfile, htab_t copied_types);
34+
3535
#endif /* GDB_PYTHON_H */

‎gdb/value.c‎

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -312,31 +312,6 @@ allocate_repeat_value (struct type *type, int count)
312312
return allocate_value (array_type);
313313
}
314314

315-
/* Needed if another module needs to maintain its on list of values. */
316-
void
317-
value_prepend_to_list (struct value **head, struct value *val)
318-
{
319-
val->next = *head;
320-
*head = val;
321-
}
322-
323-
/* Needed if another module needs to maintain its on list of values. */
324-
void
325-
value_remove_from_list (struct value **head, struct value *val)
326-
{
327-
struct value *prev;
328-
329-
if (*head == val)
330-
*head = (*head)->next;
331-
else
332-
for (prev = *head; prev->next; prev = prev->next)
333-
if (prev->next == val)
334-
{
335-
prev->next = val->next;
336-
break;
337-
}
338-
}
339-
340315
struct value *
341316
allocate_computed_value (struct type *type,
342317
struct lval_funcs *funcs,
@@ -1430,7 +1405,7 @@ add_internal_function (const char *name, const char *doc,
14301405
/* Update VALUE before discarding OBJFILE. COPIED_TYPES is used to
14311406
prevent cycles / duplicates. */
14321407

1433-
static void
1408+
void
14341409
preserve_one_value (struct value *value, struct objfile *objfile,
14351410
htab_t copied_types)
14361411
{
@@ -1490,8 +1465,7 @@ preserve_values (struct objfile *objfile)
14901465
for (var = internalvars; var; var = var->next)
14911466
preserve_one_internalvar (var, objfile, copied_types);
14921467

1493-
for (val = values_in_python; val; val = val->next)
1494-
preserve_one_value (val, objfile, copied_types);
1468+
preserve_python_values (objfile, copied_types);
14951469

14961470
htab_delete (copied_types);
14971471
}

‎gdb/value.h‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,6 @@ struct value_print_options;
4141

4242
struct value;
4343

44-
/* Needed if another module needs to maintain its own list of values. */
45-
46-
void value_prepend_to_list (struct value **head, struct value *val);
47-
void value_remove_from_list (struct value **head, struct value *val);
48-
4944
/* Values are stored in a chain, so that they can be deleted easily
5045
over calls to the inferior. Values assigned to internal variables,
5146
put into the value history or exposed to Python are taken off this
@@ -664,6 +659,8 @@ extern void preserve_values (struct objfile *);
664659

665660
extern struct value *value_copy (struct value *);
666661

662+
extern void preserve_one_value (struct value *, struct objfile *, htab_t);
663+
667664
/* From valops.c */
668665

669666
extern struct value *varying_to_slice (struct value *);

‎gdb/varobj.c‎

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -899,16 +899,7 @@ update_dynamic_varobj_children (struct varobj *var,
899899
if (!PyArg_ParseTuple (item, "sO", &name, &py_v))
900900
error (_("Invalid item from the child list"));
901901

902-
if (PyObject_TypeCheck (py_v, &value_object_type))
903-
{
904-
/* If we just call convert_value_from_python for this type,
905-
we won't know who owns the result. For this one case we
906-
need to copy the resulting value. */
907-
v = value_object_to_value (py_v);
908-
v = value_copy (v);
909-
}
910-
else
911-
v = convert_value_from_python (py_v);
902+
v = convert_value_from_python (py_v);
912903

913904
/* TODO: This assume the name of the i-th child never changes. */
914905

0 commit comments

Comments
 (0)