Use gdbpy_ref in python.c

This changes a couple of functions in python.c to use gdbpy_ref.

2017-01-10  Tom Tromey  <tom@tromey.com>

	* python/python.c (gdbpy_progspaces, gdbpy_objfiles): Use
	gdbpy_ref.
This commit is contained in:
Tom Tromey 2016-11-06 21:49:34 -07:00
parent 0700aea50c
commit ff3724f512
2 changed files with 16 additions and 18 deletions

View file

@ -1,3 +1,8 @@
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> 2017-01-10 Tom Tromey <tom@tromey.com>
* python/py-prettyprint.c (search_pp_list) * python/py-prettyprint.c (search_pp_list)

View file

@ -99,6 +99,7 @@ const struct extension_language_defn extension_language_python =
#include "gdbthread.h" #include "gdbthread.h"
#include "interps.h" #include "interps.h"
#include "event-top.h" #include "event-top.h"
#include "py-ref.h"
/* True if Python has been successfully initialized, false /* True if Python has been successfully initialized, false
otherwise. */ otherwise. */
@ -1266,24 +1267,20 @@ static PyObject *
gdbpy_progspaces (PyObject *unused1, PyObject *unused2) gdbpy_progspaces (PyObject *unused1, PyObject *unused2)
{ {
struct program_space *ps; struct program_space *ps;
PyObject *list;
list = PyList_New (0); gdbpy_ref list (PyList_New (0));
if (!list) if (list == NULL)
return NULL; return NULL;
ALL_PSPACES (ps) ALL_PSPACES (ps)
{ {
PyObject *item = pspace_to_pspace_object (ps); PyObject *item = pspace_to_pspace_object (ps);
if (!item || PyList_Append (list, item) == -1) if (!item || PyList_Append (list.get (), item) == -1)
{ return NULL;
Py_DECREF (list);
return NULL;
}
} }
return list; return list.release ();
} }
@ -1366,24 +1363,20 @@ static PyObject *
gdbpy_objfiles (PyObject *unused1, PyObject *unused2) gdbpy_objfiles (PyObject *unused1, PyObject *unused2)
{ {
struct objfile *objf; struct objfile *objf;
PyObject *list;
list = PyList_New (0); gdbpy_ref list (PyList_New (0));
if (!list) if (list == NULL)
return NULL; return NULL;
ALL_OBJFILES (objf) ALL_OBJFILES (objf)
{ {
PyObject *item = objfile_to_objfile_object (objf); PyObject *item = objfile_to_objfile_object (objf);
if (!item || PyList_Append (list, item) == -1) if (!item || PyList_Append (list.get (), item) == -1)
{ return NULL;
Py_DECREF (list);
return NULL;
}
} }
return list; return list.release ();
} }
/* Compute the list of active python type printers and store them in /* Compute the list of active python type printers and store them in