+2017-01-10 Tom Tromey <tom@tromey.com>
+
+ * python/python.c (gdbpy_progspaces, gdbpy_objfiles): Use
+ gdbpy_ref.
+
2017-01-10 Tom Tromey <tom@tromey.com>
* python/py-prettyprint.c (search_pp_list)
#include "gdbthread.h"
#include "interps.h"
#include "event-top.h"
+#include "py-ref.h"
/* True if Python has been successfully initialized, false
otherwise. */
gdbpy_progspaces (PyObject *unused1, PyObject *unused2)
{
struct program_space *ps;
- PyObject *list;
- list = PyList_New (0);
- if (!list)
+ gdbpy_ref list (PyList_New (0));
+ if (list == NULL)
return NULL;
ALL_PSPACES (ps)
{
PyObject *item = pspace_to_pspace_object (ps);
- if (!item || PyList_Append (list, item) == -1)
- {
- Py_DECREF (list);
- return NULL;
- }
+ if (!item || PyList_Append (list.get (), item) == -1)
+ return NULL;
}
- return list;
+ return list.release ();
}
\f
gdbpy_objfiles (PyObject *unused1, PyObject *unused2)
{
struct objfile *objf;
- PyObject *list;
- list = PyList_New (0);
- if (!list)
+ gdbpy_ref list (PyList_New (0));
+ if (list == NULL)
return NULL;
ALL_OBJFILES (objf)
{
PyObject *item = objfile_to_objfile_object (objf);
- if (!item || PyList_Append (list, item) == -1)
- {
- Py_DECREF (list);
- return NULL;
- }
+ if (!item || PyList_Append (list.get (), item) == -1)
+ return NULL;
}
- return list;
+ return list.release ();
}
/* Compute the list of active python type printers and store them in