From: Paul Koning Date: Tue, 4 Oct 2011 16:20:03 +0000 (+0000) Subject: * python/py-type.c (typy_make_iter): Add forward declaration. X-Git-Tag: sid-snapshot-20111101~297 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0dab82e9b3346035364369b2a2cdd15fb929ab54;p=external%2Fbinutils.git * python/py-type.c (typy_make_iter): Add forward declaration. (typy_fields_items): Use the gdb.Type iterator. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 6c92b9e..29a61fe 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,10 @@ 2011-10-04 Paul Koning + * python/py-type.c (typy_make_iter): Add forward declaration. + (typy_fields_items): Use the gdb.Type iterator. + +2011-10-04 Paul Koning + * NEWS: Add entry for Python gdb.Type mapping methods. 2011-10-04 Kevin Pouget diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c index 76415b3..c7fd25b 100644 --- a/gdb/python/py-type.c +++ b/gdb/python/py-type.c @@ -77,6 +77,9 @@ struct pyty_code const char *name; }; +/* Forward declarations. */ +static PyObject *typy_make_iter (PyObject *self, enum gdbpy_iter_kind kind); + #define ENTRY(X) { X, #X } static struct pyty_code pyty_codes[] = @@ -290,40 +293,15 @@ make_fielditem (struct type *type, int i, enum gdbpy_iter_kind kind) static PyObject * typy_fields_items (PyObject *self, enum gdbpy_iter_kind kind) { - PyObject *result = NULL, *item = NULL; - int i; - struct type *type = ((type_object *) self)->type; - volatile struct gdb_exception except; - - TRY_CATCH (except, RETURN_MASK_ALL) - { - CHECK_TYPEDEF (type); - } - GDB_PY_HANDLE_EXCEPTION (except); - - /* We would like to make a tuple here, make fields immutable, and - then memoize the result (and perhaps make Field.type() lazy). - However, that can lead to cycles. */ - result = PyList_New (0); - if (result == NULL) - return NULL; + PyObject *result = NULL, *iter = NULL; - for (i = 0; i < TYPE_NFIELDS (type); ++i) - { - item = make_fielditem (type, i, kind); - if (!item) - goto fail; - if (PyList_Append (result, item)) - goto fail; - Py_DECREF (item); - } - + iter = typy_make_iter (self, kind); + if (iter == NULL) + return NULL; + + result = PySequence_List (iter); + Py_DECREF (iter); return result; - - fail: - Py_XDECREF (item); - Py_XDECREF (result); - return NULL; } /* Return a sequence of all fields. Each field is a gdb.Field object. */