diff options
author | Tom Tromey <tromey@adacore.com> | 2025-08-01 11:11:41 -0600 |
---|---|---|
committer | Tom Tromey <tromey@adacore.com> | 2025-08-12 08:30:37 -0600 |
commit | 89495c33260b3f637acb8f79181cc6db08771f90 (patch) | |
tree | 525da36fc4d6846f8b8b34ae12c449b414d38dbc /gdb/python | |
parent | 55c91b7e5c7f7829ff69738f159e0380383a7356 (diff) | |
download | binutils-89495c33260b3f637acb8f79181cc6db08771f90.zip binutils-89495c33260b3f637acb8f79181cc6db08771f90.tar.gz binutils-89495c33260b3f637acb8f79181cc6db08771f90.tar.bz2 |
Change type::fields to return an array_view
This patch changes type::fields to return an array_view of the fields,
then fixes up the fallout.
More cleanups would be possible here (in particular in the field
initialization code) but I haven't done so.
The main motivation for this patch was to make it simpler to iterate
over the fields of a type.
Regression tested on x86-64 Fedora 41.
Approved-By: Simon Marchi <simon.marchi@efficios.com>
Diffstat (limited to 'gdb/python')
-rw-r--r-- | gdb/python/py-type.c | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c index c546aa7..10ae636 100644 --- a/gdb/python/py-type.c +++ b/gdb/python/py-type.c @@ -1312,10 +1312,9 @@ static PyObject * typy_has_key (PyObject *self, PyObject *args) { struct type *type = ((type_object *) self)->type; - const char *field; - int i; + const char *field_name; - if (!PyArg_ParseTuple (args, "s", &field)) + if (!PyArg_ParseTuple (args, "s", &field_name)) return NULL; /* We want just fields of this type, not of base types, so instead of @@ -1326,11 +1325,11 @@ typy_has_key (PyObject *self, PyObject *args) if (type == NULL) return NULL; - for (i = 0; i < type->num_fields (); i++) + for (const auto &field : type->fields ()) { - const char *t_field_name = type->field (i).name (); + const char *t_field_name = field.name (); - if (t_field_name && (strcmp_iw (t_field_name, field) == 0)) + if (t_field_name && (strcmp_iw (t_field_name, field_name) == 0)) Py_RETURN_TRUE; } Py_RETURN_FALSE; |