Use gdbpy_ref in python.c
authorTom Tromey <tom@tromey.com>
Mon, 7 Nov 2016 04:49:34 +0000 (21:49 -0700)
committerTom Tromey <tom@tromey.com>
Wed, 11 Jan 2017 02:13:36 +0000 (19:13 -0700)
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.

gdb/ChangeLog
gdb/python/python.c

index caf042c370665400702ec4ac69cbb27833dd23ac..cb4ffd2ac3cd416c67d9474fba89be7dda4313fc 100644 (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>
 
        * python/py-prettyprint.c (search_pp_list)
index c6e410a6d2bc1d1e851c487e76606d427035d5f1..a2f36249e4fa761fdd114a0af6d819b1026427cf 100644 (file)
@@ -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.  */
@@ -1266,24 +1267,20 @@ static PyObject *
 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
@@ -1366,24 +1363,20 @@ static PyObject *
 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
This page took 0.0485 seconds and 4 git commands to generate.