[1/4] Use foreach in gdbpy_inferiors

Message ID 20190919212825.7586-2-tom@tromey.com
State New, archived
Headers

Commit Message

Tom Tromey Sept. 19, 2019, 9:28 p.m. UTC
  This changes gdbpy_inferiors to use foreach rather than a callback
function.

gdb/ChangeLog
2019-09-19  Tom Tromey  <tom@tromey.com>

	* python/py-inferior.c (build_inferior_list): Remove.
	(gdbpy_inferiors): Use foreach.
---
 gdb/ChangeLog            |  5 +++++
 gdb/python/py-inferior.c | 24 ++++++++++--------------
 2 files changed, 15 insertions(+), 14 deletions(-)
  

Patch

diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c
index 28882221a90..ecb95444a36 100644
--- a/gdb/python/py-inferior.c
+++ b/gdb/python/py-inferior.c
@@ -462,18 +462,6 @@  infpy_get_progspace (PyObject *self, void *closure)
   return pspace_to_pspace_object (pspace).release ();
 }
 
-static int
-build_inferior_list (struct inferior *inf, void *arg)
-{
-  PyObject *list = (PyObject *) arg;
-  gdbpy_ref<inferior_object> inferior = inferior_to_inferior_object (inf);
-
-  if (inferior == NULL)
-    return 0;
-
-  return PyList_Append (list, (PyObject *) inferior.get ()) ? 1 : 0;
-}
-
 /* Implementation of gdb.inferiors () -> (gdb.Inferior, ...).
    Returns a tuple of all inferiors.  */
 PyObject *
@@ -483,8 +471,16 @@  gdbpy_inferiors (PyObject *unused, PyObject *unused2)
   if (list == NULL)
     return NULL;
 
-  if (iterate_over_inferiors (build_inferior_list, list.get ()))
-    return NULL;
+  for (inferior *inf : all_inferiors_safe ())
+    {
+      gdbpy_ref<inferior_object> inferior = inferior_to_inferior_object (inf);
+
+      if (inferior == NULL)
+	continue;
+
+      if (PyList_Append (list.get (), (PyObject *) inferior.get ()) == -1)
+	return NULL;
+    }
 
   return PyList_AsTuple (list.get ());
 }