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 py-inferior.c


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

commit 9205649a38c609a42ba52680a316fceaa08c1543
Author: Tom Tromey <tom@tromey.com>
Date:   Sun Nov 20 10:31:17 2016 -0700

    Use gdbpy_ref in py-inferior.c
    
    This changes py-inferior.c to use gdbpy_ref in more places.
    
    2017-01-10  Tom Tromey  <tom@tromey.com>
    
    	* python/py-inferior.c (find_thread_object, build_inferior_list):
    	Use gdbpy_ref.

Diff:
---
 gdb/ChangeLog            |  5 +++++
 gdb/python/py-inferior.c | 23 ++++++-----------------
 2 files changed, 11 insertions(+), 17 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index ce31184..a124548 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,10 @@
 2017-01-10  Tom Tromey  <tom@tromey.com>
 
+	* python/py-inferior.c (find_thread_object, build_inferior_list):
+	Use gdbpy_ref.
+
+2017-01-10  Tom Tromey  <tom@tromey.com>
+
 	* python/py-framefilter.c (py_print_frame): Use gdbpy_ref.
 
 2017-01-10  Tom Tromey  <tom@tromey.com>
diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c
index 4b3f8eef..9e10d62 100644
--- a/gdb/python/py-inferior.c
+++ b/gdb/python/py-inferior.c
@@ -251,19 +251,17 @@ find_thread_object (ptid_t ptid)
 {
   int pid;
   struct threadlist_entry *thread;
-  PyObject *inf_obj;
   thread_object *found = NULL;
 
   pid = ptid_get_pid (ptid);
   if (pid == 0)
     return NULL;
 
-  inf_obj = find_inferior_object (pid);
-
-  if (! inf_obj)
+  gdbpy_ref inf_obj (find_inferior_object (pid));
+  if (inf_obj == NULL)
     return NULL;
 
-  for (thread = ((inferior_object *)inf_obj)->threads; thread;
+  for (thread = ((inferior_object *)(inf_obj.get ()))->threads; thread;
        thread = thread->next)
     if (ptid_equal (thread->thread_obj->thread->ptid, ptid))
       {
@@ -271,8 +269,6 @@ find_thread_object (ptid_t ptid)
 	break;
       }
 
-  Py_DECREF (inf_obj);
-
   if (found)
     return found;
 
@@ -416,19 +412,12 @@ static int
 build_inferior_list (struct inferior *inf, void *arg)
 {
   PyObject *list = (PyObject *) arg;
-  PyObject *inferior = inferior_to_inferior_object (inf);
-  int success = 0;
+  gdbpy_ref inferior (inferior_to_inferior_object (inf));
 
-  if (! inferior)
+  if (inferior  == NULL)
     return 0;
 
-  success = PyList_Append (list, inferior);
-  Py_DECREF (inferior);
-
-  if (success)
-    return 1;
-
-  return 0;
+  return PyList_Append (list, inferior.get ()) ? 1 : 0;
 }
 
 /* Implementation of gdb.inferiors () -> (gdb.Inferior, ...).


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