Use gdbpy_ref in call_doc_function
authorTom Tromey <tom@tromey.com>
Mon, 7 Nov 2016 04:29:12 +0000 (21:29 -0700)
committerTom Tromey <tom@tromey.com>
Wed, 11 Jan 2017 02:13:35 +0000 (19:13 -0700)
This changes call_doc_function to use gdbpy_ref.

2017-01-10  Tom Tromey  <tom@tromey.com>

* python/py-param.c (call_doc_function): Use gdbpy_ref.

gdb/ChangeLog
gdb/python/py-param.c

index 849c3e1..a0bdd9c 100644 (file)
@@ -1,5 +1,9 @@
 2017-01-10  Tom Tromey  <tom@tromey.com>
 
+       * python/py-param.c (call_doc_function): Use gdbpy_ref.
+
+2017-01-10  Tom Tromey  <tom@tromey.com>
+
        * python/py-linetable.c (build_line_table_tuple_from_pcs)
        (ltpy_get_all_source_lines): Use gdbpy_ref.
 
index 7c3223f..d9d8baa 100644 (file)
@@ -27,6 +27,7 @@
 #include "completer.h"
 #include "language.h"
 #include "arch-utils.h"
+#include "py-ref.h"
 
 /* Parameter constants and their values.  */
 struct parm_constant
@@ -329,15 +330,14 @@ static gdb::unique_xmalloc_ptr<char>
 call_doc_function (PyObject *obj, PyObject *method, PyObject *arg)
 {
   gdb::unique_xmalloc_ptr<char> data;
-  PyObject *result = PyObject_CallMethodObjArgs (obj, method, arg, NULL);
+  gdbpy_ref result (PyObject_CallMethodObjArgs (obj, method, arg, NULL));
 
-  if (! result)
+  if (result == NULL)
     return NULL;
 
-  if (gdbpy_is_string (result))
+  if (gdbpy_is_string (result.get ()))
     {
-      data = python_string_to_host_string (result);
-      Py_DECREF (result);
+      data = python_string_to_host_string (result.get ());
       if (! data)
        return NULL;
     }
@@ -345,7 +345,6 @@ call_doc_function (PyObject *obj, PyObject *method, PyObject *arg)
     {
       PyErr_SetString (PyExc_RuntimeError,
                       _("Parameter must return a string value."));
-      Py_DECREF (result);
       return NULL;
     }