Remove more uses of explicit reference counting in Python
[deliverable/binutils-gdb.git] / gdb / python / py-type.c
index 88770fcc9f392923f381a66e0cc9f2cf984dbcfd..601d29fee76804f19e30679d818437b1764a1d61 100644 (file)
@@ -319,7 +319,6 @@ static PyObject *
 typy_fields_items (PyObject *self, enum gdbpy_iter_kind kind)
 {
   PyObject *py_type = self;
-  PyObject *result = NULL, *iter = NULL;
   struct type *type = ((type_object *) py_type)->type;
   struct type *checked_type = type;
 
@@ -333,22 +332,19 @@ typy_fields_items (PyObject *self, enum gdbpy_iter_kind kind)
     }
   END_CATCH
 
+  gdbpy_ref<> type_holder;
   if (checked_type != type)
-    py_type = type_to_type_object (checked_type);
-  iter = typy_make_iter (py_type, kind);
-  if (checked_type != type)
-    {
-      /* Need to wrap this in braces because Py_DECREF isn't wrapped
-        in a do{}while(0).  */
-      Py_DECREF (py_type);
-    }
-  if (iter != NULL)
     {
-      result = PySequence_List (iter);
-      Py_DECREF (iter);
+      type_holder.reset (type_to_type_object (checked_type));
+      if (type_holder == nullptr)
+       return nullptr;
+      py_type = type_holder.get ();
     }
+  gdbpy_ref<> iter (typy_make_iter (py_type, kind));
+  if (iter == nullptr)
+    return nullptr;
 
-  return result;
+  return PySequence_List (iter.get ());
 }
 
 /* Return a sequence of all fields.  Each field is a gdb.Field object.  */
This page took 0.025021 seconds and 4 git commands to generate.