[RFA,12/14] Use gdbpy_reference in python.c

Message ID 1478497656-11832-13-git-send-email-tom@tromey.com
State New, archived
Headers

Commit Message

Tom Tromey Nov. 7, 2016, 5:47 a.m. UTC
  This changes a couple of functions in python.c to use gdbpy_reference.

2016-11-06  Tom Tromey  <tom@tromey.com>

	* python/python.c (gdbpy_progspaces, gdbpy_objfiles): Use
	gdbpy_reference.
---
 gdb/ChangeLog       |  5 +++++
 gdb/python/python.c | 29 +++++++++++------------------
 2 files changed, 16 insertions(+), 18 deletions(-)
  

Patch

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 1b49750..f5392a3 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,10 @@ 
 2016-11-06  Tom Tromey  <tom@tromey.com>
 
+	* python/python.c (gdbpy_progspaces, gdbpy_objfiles): Use
+	gdbpy_reference.
+
+2016-11-06  Tom Tromey  <tom@tromey.com>
+
 	* python/py-prettyprint.c (search_pp_list)
 	(find_pretty_printer_from_objfiles)
 	(find_pretty_printer_from_progspace)
diff --git a/gdb/python/python.c b/gdb/python/python.c
index d6bd6bf..221bb4d 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -99,6 +99,7 @@  const struct extension_language_defn extension_language_python =
 #include "gdbthread.h"
 #include "interps.h"
 #include "event-top.h"
+#include "py-ref.h"
 
 /* True if Python has been successfully initialized, false
    otherwise.  */
@@ -1276,24 +1277,20 @@  static PyObject *
 gdbpy_progspaces (PyObject *unused1, PyObject *unused2)
 {
   struct program_space *ps;
-  PyObject *list;
 
-  list = PyList_New (0);
-  if (!list)
+  gdbpy_reference 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 ();
 }
 
 
@@ -1376,24 +1373,20 @@  static PyObject *
 gdbpy_objfiles (PyObject *unused1, PyObject *unused2)
 {
   struct objfile *objf;
-  PyObject *list;
 
-  list = PyList_New (0);
-  if (!list)
+  gdbpy_reference 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