This is the mail archive of the gdb-cvs@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[binutils-gdb] Use gdbpy_ref in python.c


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=ff3724f5123b9d9c52a07f7c1a5d85852e666c48

commit ff3724f5123b9d9c52a07f7c1a5d85852e666c48
Author: Tom Tromey <tom@tromey.com>
Date:   Sun Nov 6 21:49:34 2016 -0700

    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.

Diff:
---
 gdb/ChangeLog       |  5 +++++
 gdb/python/python.c | 29 +++++++++++------------------
 2 files changed, 16 insertions(+), 18 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index caf042c..cb4ffd2 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,10 @@
 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)
 	(find_pretty_printer_from_objfiles)
 	(find_pretty_printer_from_progspace)
diff --git a/gdb/python/python.c b/gdb/python/python.c
index c6e410a..a2f3624 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.  */
@@ -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 ();
 }
 
 
@@ -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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]