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-param.c


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

commit 97d83487d5fbffd04d68a049f97009e1df2562a3
Author: Tom Tromey <tom@tromey.com>
Date:   Sun Nov 20 10:34:34 2016 -0700

    Use gdbpy_ref in py-param.c
    
    This changes py-param.c to use gdbpy_ref in a couple more spots.
    
    2017-01-10  Tom Tromey  <tom@tromey.com>
    
    	* python/py-param.c (get_doc_string, compute_enum_values): Use
    	gdbpy_ref.

Diff:
---
 gdb/ChangeLog         |  5 +++++
 gdb/python/py-param.c | 18 ++++++++----------
 2 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index a124548..dea5d40 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,10 @@
 2017-01-10  Tom Tromey  <tom@tromey.com>
 
+	* python/py-param.c (get_doc_string, compute_enum_values): Use
+	gdbpy_ref.
+
+2017-01-10  Tom Tromey  <tom@tromey.com>
+
 	* python/py-inferior.c (find_thread_object, build_inferior_list):
 	Use gdbpy_ref.
 
diff --git a/gdb/python/py-param.c b/gdb/python/py-param.c
index b692824..c285bb5 100644
--- a/gdb/python/py-param.c
+++ b/gdb/python/py-param.c
@@ -307,15 +307,14 @@ get_doc_string (PyObject *object, PyObject *attr)
 
   if (PyObject_HasAttr (object, attr))
     {
-      PyObject *ds_obj = PyObject_GetAttr (object, attr);
+      gdbpy_ref ds_obj (PyObject_GetAttr (object, attr));
 
-      if (ds_obj && gdbpy_is_string (ds_obj))
+      if (ds_obj != NULL && gdbpy_is_string (ds_obj.get ()))
 	{
-	  result = python_string_to_host_string (ds_obj);
+	  result = python_string_to_host_string (ds_obj.get ());
 	  if (result == NULL)
 	    gdbpy_print_stack ();
 	}
-      Py_XDECREF (ds_obj);
     }
   if (! result)
     result.reset (xstrdup (_("This command is not documented.")));
@@ -587,23 +586,22 @@ compute_enum_values (parmpy_object *self, PyObject *enum_values)
 
   for (i = 0; i < size; ++i)
     {
-      PyObject *item = PySequence_GetItem (enum_values, i);
+      gdbpy_ref item (PySequence_GetItem (enum_values, i));
 
-      if (! item)
+      if (item == NULL)
 	{
 	  do_cleanups (back_to);
 	  return 0;
 	}
-      if (! gdbpy_is_string (item))
+      if (! gdbpy_is_string (item.get ()))
 	{
-	  Py_DECREF (item);
 	  do_cleanups (back_to);
 	  PyErr_SetString (PyExc_RuntimeError,
 			   _("The enumeration item not a string."));
 	  return 0;
 	}
-      self->enumeration[i] = python_string_to_host_string (item).release ();
-      Py_DECREF (item);
+      self->enumeration[i]
+	= python_string_to_host_string (item.get ()).release ();
       if (self->enumeration[i] == NULL)
 	{
 	  do_cleanups (back_to);


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