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


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

commit 80bd970a4b1388fc4373b3e087006e6c93d71f60
Author: Tom Tromey <tom@tromey.com>
Date:   Sun Nov 6 21:21:14 2016 -0700

    Use gdbpy_ref in py-function.c
    
    This changes some code in py-function.c to use gdbpy_ref.
    
    2017-01-10  Tom Tromey  <tom@tromey.com>
    
    	* python/py-function.c (convert_values_to_python, fnpy_init): Use
    	gdbpy_ref.

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

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 1e8ce99..dc6ef9a 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,10 @@
 2017-01-10  Tom Tromey  <tom@tromey.com>
 
+	* python/py-function.c (convert_values_to_python, fnpy_init): Use
+	gdbpy_ref.
+
+2017-01-10  Tom Tromey  <tom@tromey.com>
+
 	* python/py-cmd.c (gdbpy_string_to_argv): Use gdbpy_ref.
 
 2017-01-10  Tom Tromey  <tom@tromey.com>
diff --git a/gdb/python/py-function.c b/gdb/python/py-function.c
index 048e343..8db1ea6 100644
--- a/gdb/python/py-function.c
+++ b/gdb/python/py-function.c
@@ -27,6 +27,7 @@
 #include "completer.h"
 #include "expression.h"
 #include "language.h"
+#include "py-ref.h"
 
 extern PyTypeObject fnpy_object_type
     CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("PyObject");
@@ -37,22 +38,19 @@ static PyObject *
 convert_values_to_python (int argc, struct value **argv)
 {
   int i;
-  PyObject *result = PyTuple_New (argc);
+  gdbpy_ref result (PyTuple_New (argc));
 
-  if (! result)
+  if (result == NULL)
     return NULL;
 
   for (i = 0; i < argc; ++i)
     {
-      PyObject *elt = value_to_value_object (argv[i]);
-      if (! elt)
-	{
-	  Py_DECREF (result);
-	  return NULL;
-	}
-      PyTuple_SetItem (result, i, elt);
+      gdbpy_ref elt (value_to_value_object (argv[i]));
+      if (elt == NULL)
+	return NULL;
+      PyTuple_SetItem (result.get (), i, elt.release ());
     }
-  return result;
+  return result.release ();
 }
 
 /* Call a Python function object's invoke method.  */
@@ -172,21 +170,18 @@ fnpy_init (PyObject *self, PyObject *args, PyObject *kwds)
 
   if (PyObject_HasAttrString (self, "__doc__"))
     {
-      PyObject *ds_obj = PyObject_GetAttrString (self, "__doc__");
+      gdbpy_ref ds_obj (PyObject_GetAttrString (self, "__doc__"));
       if (ds_obj != NULL)
 	{
-	  if (gdbpy_is_string (ds_obj))
+	  if (gdbpy_is_string (ds_obj.get ()))
 	    {
-	      docstring = python_string_to_host_string (ds_obj);
+	      docstring = python_string_to_host_string (ds_obj.get ());
 	      if (docstring == NULL)
 		{
 		  Py_DECREF (self);
-		  Py_DECREF (ds_obj);
 		  return -1;
 		}
 	    }
-
-	  Py_DECREF (ds_obj);
 	}
     }
   if (! docstring)


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