OSDN Git Service

* python/py-type.c (typy_make_iter): Add forward declaration.
authorpkoning <pkoning>
Tue, 4 Oct 2011 16:19:58 +0000 (16:19 +0000)
committerpkoning <pkoning>
Tue, 4 Oct 2011 16:19:58 +0000 (16:19 +0000)
(typy_fields_items):  Use the gdb.Type iterator.

gdb/ChangeLog
gdb/python/py-type.c

index 6c92b9e..29a61fe 100644 (file)
@@ -1,5 +1,10 @@
 2011-10-04  Paul Koning  <paul_koning@dell.com>
 
+       * python/py-type.c (typy_make_iter): Add forward declaration.
+       (typy_fields_items):  Use the gdb.Type iterator.
+
+2011-10-04  Paul Koning  <paul_koning@dell.com>
+
        * NEWS: Add entry for Python gdb.Type mapping methods.
 
 2011-10-04  Kevin Pouget  <kevin.pouget@st.com>
index 76415b3..c7fd25b 100644 (file)
@@ -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.  */