Use gdbpy_ref in py-param.c
authorTom Tromey <tom@tromey.com>
Sun, 20 Nov 2016 17:34:34 +0000 (10:34 -0700)
committerTom Tromey <tom@tromey.com>
Wed, 11 Jan 2017 02:14:04 +0000 (19:14 -0700)
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.

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

index a124548a2378c5b523ee77ec0e5f7d027c30234e..dea5d4032838f08d1286de6aef27f8f877a11e7c 100644 (file)
@@ -1,3 +1,8 @@
+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):
index b692824ae1f3be7fdd460ddaaba4fbc324b521e5..c285bb5c43d2f6465262a3b768992ae2f30758b6 100644 (file)
@@ -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);
This page took 0.035531 seconds and 4 git commands to generate.