public inbox for archer-commits@sourceware.org
help / color / mirror / Atom feed
* [SCM] archer-tromey-python: use doubly-linked list for Value objects; also a bug fix
@ 2009-08-13 18:26 tromey
0 siblings, 0 replies; only message in thread
From: tromey @ 2009-08-13 18:26 UTC (permalink / raw)
To: archer-commits
The branch, archer-tromey-python has been updated
via e2437de2e3cbaba928ff64e9c967fa633de55c00 (commit)
from f5e13c8a13824cb1851fa2f7ad972d4b764b1b8a (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email.
- Log -----------------------------------------------------------------
commit e2437de2e3cbaba928ff64e9c967fa633de55c00
Author: Tom Tromey <tromey@redhat.com>
Date: Thu Aug 13 12:25:00 2009 -0600
use doubly-linked list for Value objects; also a bug fix
* value.h (value_prepend_to_list): Remove.
(value_remove_from_list): Remove.
* value.c (value_prepend_to_list): Remove.
(value_remove_from_list): Remove.
* python/python-value.c (value_object) <next, prev>: New fields.
(valpy_dealloc): Update.
(note_value): New function.
(valpy_new): Use note_value.
(value_to_value_object): Likewise.
(convert_value_from_python): Update comment. Use value_copy, not
value_incref.
-----------------------------------------------------------------------
Summary of changes:
gdb/python/python-value.c | 48 ++++++++++++++++++++++++++------------------
gdb/value.c | 25 -----------------------
gdb/value.h | 5 ----
3 files changed, 28 insertions(+), 50 deletions(-)
First 500 lines of diff:
diff --git a/gdb/python/python-value.c b/gdb/python/python-value.c
index 6d0d924..3a42710 100644
--- a/gdb/python/python-value.c
+++ b/gdb/python/python-value.c
@@ -56,6 +56,7 @@
typedef struct value_object {
PyObject_HEAD
struct value_object *next;
+ struct value_object *prev;
struct value *value;
PyObject *address;
PyObject *type;
@@ -73,13 +74,17 @@ static void
valpy_dealloc (PyObject *obj)
{
value_object *self = (value_object *) obj;
- value_object **iter;
- /* Remove OBJ from the global list. */
- iter = &values_in_python;
- while (*iter != self)
- iter = &(*iter)->next;
- *iter = (*iter)->next;
+ /* Remove SELF from the global list. */
+ if (self->prev)
+ self->prev->next = self->next;
+ else
+ {
+ gdb_assert (values_in_python == self);
+ values_in_python = self->next;
+ }
+ if (self->next)
+ self->next->prev = self->prev;
value_free (self->value);
@@ -97,6 +102,17 @@ valpy_dealloc (PyObject *obj)
self->ob_type->tp_free (self);
}
+/* Helper to push a Value object on the global list. */
+static void
+note_value (value_object *value_obj)
+{
+ value_obj->next = values_in_python;
+ if (value_obj->next)
+ value_obj->next->prev = value_obj;
+ value_obj->prev = NULL;
+ values_in_python = value_obj;
+}
+
/* Called when a new gdb.Value object needs to be allocated. */
static PyObject *
valpy_new (PyTypeObject *subtype, PyObject *args, PyObject *keywords)
@@ -127,11 +143,10 @@ valpy_new (PyTypeObject *subtype, PyObject *args, PyObject *keywords)
}
value_obj->value = value;
+ value_incref (value);
value_obj->address = NULL;
value_obj->type = NULL;
- value_incref (value);
- value_obj->next = values_in_python;
- values_in_python = value_obj;
+ note_value (value_obj);
return (PyObject *) value_obj;
}
@@ -818,11 +833,10 @@ value_to_value_object (struct value *val)
if (val_obj != NULL)
{
val_obj->value = val;
+ value_incref (val);
val_obj->address = NULL;
val_obj->type = NULL;
- value_incref (val);
- val_obj->next = values_in_python;
- values_in_python = val_obj;
+ note_value (val_obj);
}
return (PyObject *) val_obj;
@@ -842,7 +856,7 @@ value_object_to_value (PyObject *self)
/* Try to convert a Python value to a gdb value. If the value cannot
be converted, set a Python exception and return NULL. Returns a
- borrowed reference to the resulting struct value. */
+ reference to a new value on the all_values chain. */
struct value *
convert_value_from_python (PyObject *obj)
@@ -924,13 +938,7 @@ convert_value_from_python (PyObject *obj)
}
}
else if (PyObject_TypeCheck (obj, &value_object_type))
- {
- /* This lets callers freely decref the Value wrapper object
- and not worry about whether or not the value will
- disappear. */
- value = ((value_object *) obj)->value;
- value_incref (value);
- }
+ value = value_copy (((value_object *) obj)->value);
else
PyErr_Format (PyExc_TypeError, _("Could not convert Python object: %s"),
PyString_AsString (PyObject_Str (obj)));
diff --git a/gdb/value.c b/gdb/value.c
index 4140e20..71a2502 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -323,31 +323,6 @@ allocate_repeat_value (struct type *type, int count)
return allocate_value (array_type);
}
-/* Needed if another module needs to maintain its on list of values. */
-void
-value_prepend_to_list (struct value **head, struct value *val)
-{
- val->next = *head;
- *head = val;
-}
-
-/* Needed if another module needs to maintain its on list of values. */
-void
-value_remove_from_list (struct value **head, struct value *val)
-{
- struct value *prev;
-
- if (*head == val)
- *head = (*head)->next;
- else
- for (prev = *head; prev->next; prev = prev->next)
- if (prev->next == val)
- {
- prev->next = val->next;
- break;
- }
-}
-
struct value *
allocate_computed_value (struct type *type,
struct lval_funcs *funcs,
diff --git a/gdb/value.h b/gdb/value.h
index 35f5fc7..de7d4dd 100644
--- a/gdb/value.h
+++ b/gdb/value.h
@@ -41,11 +41,6 @@ struct value_print_options;
struct value;
-/* Needed if another module needs to maintain its own list of values. */
-
-void value_prepend_to_list (struct value **head, struct value *val);
-void value_remove_from_list (struct value **head, struct value *val);
-
/* 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
hooks/post-receive
--
Repository for Project Archer.
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2009-08-13 18:26 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-08-13 18:26 [SCM] archer-tromey-python: use doubly-linked list for Value objects; also a bug fix tromey
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).