]> Git Repo - binutils.git/blobdiff - gdb/python/py-progspace.c
Remove CPYCHECKER_RETURNS_BORROWED_REF
[binutils.git] / gdb / python / py-progspace.c
index b88ad3c17738e74f2b6e702c045c6484842d766b..1e16b845e0a5f461ffc696e76b8c94daa2c4a113 100644 (file)
@@ -344,9 +344,10 @@ pspy_get_objfiles (PyObject *self_, PyObject *args)
 
       ALL_PSPACE_OBJFILES (self->pspace, objf)
        {
-         PyObject *item = objfile_to_objfile_object (objf);
+         gdbpy_ref<> item = objfile_to_objfile_object (objf);
 
-         if (!item || PyList_Append (list.get (), item) == -1)
+         if (item == nullptr
+             || PyList_Append (list.get (), item.get ()) == -1)
            return NULL;
        }
     }
@@ -492,30 +493,31 @@ py_free_pspace (struct program_space *pspace, void *datum)
   object->pspace = NULL;
 }
 
-/* Return a borrowed reference to the Python object of type Pspace
+/* Return a new reference to the Python object of type Pspace
    representing PSPACE.  If the object has already been created,
    return it.  Otherwise, create it.  Return NULL and set the Python
    error on failure.  */
 
-PyObject *
+gdbpy_ref<>
 pspace_to_pspace_object (struct program_space *pspace)
 {
-  gdbpy_ref<pspace_object> object
-    ((pspace_object *) program_space_data (pspace, pspy_pspace_data_key));
-  if (object == NULL)
+  PyObject *result
+    ((PyObject *) program_space_data (pspace, pspy_pspace_data_key));
+  if (result == NULL)
     {
-      object.reset (PyObject_New (pspace_object, &pspace_object_type));
-      if (object != NULL)
-       {
-         if (!pspy_initialize (object.get ()))
-           return NULL;
+      gdbpy_ref<pspace_object> object
+       ((pspace_object *) PyObject_New (pspace_object, &pspace_object_type));
+      if (object == NULL)
+       return NULL;
+      if (!pspy_initialize (object.get ()))
+       return NULL;
 
-         object->pspace = pspace;
-         set_program_space_data (pspace, pspy_pspace_data_key, object.get ());
-       }
+      object->pspace = pspace;
+      set_program_space_data (pspace, pspy_pspace_data_key, object.get ());
+      result = (PyObject *) object.release ();
     }
 
-  return (PyObject *) object.release ();
+  return gdbpy_ref<>::new_reference (result);
 }
 
 int
This page took 0.026355 seconds and 4 git commands to generate.