Change event code to use gdbpy_ref
[deliverable/binutils-gdb.git] / gdb / python / py-event.c
index 7905bcfb1c101562c4e7cc713bef12811675ac07..a50da1f99d58bc2a068dfeda7f7df65d4e2f90e9 100644 (file)
@@ -89,26 +89,24 @@ int
 evpy_emit_event (PyObject *event,
                  eventregistry_object *registry)
 {
-  PyObject *callback_list_copy = NULL;
   Py_ssize_t i;
 
   /* Create a copy of call back list and use that for
      notifying listeners to avoid skipping callbacks
      in the case of a callback being disconnected during
      a notification.  */
-  callback_list_copy = PySequence_List (registry->callbacks);
-  if (!callback_list_copy)
-    goto fail;
+  gdbpy_ref callback_list_copy (PySequence_List (registry->callbacks));
+  if (callback_list_copy == NULL)
+    return -1;
 
-  for (i = 0; i < PyList_Size (callback_list_copy); i++)
+  for (i = 0; i < PyList_Size (callback_list_copy.get ()); i++)
     {
-      PyObject *func = PyList_GetItem (callback_list_copy, i);
-      PyObject *func_result;
+      PyObject *func = PyList_GetItem (callback_list_copy.get (), i);
 
       if (func == NULL)
-       goto fail;
+       return -1;
 
-      func_result = PyObject_CallFunctionObjArgs (func, event, NULL);
+      gdbpy_ref func_result (PyObject_CallFunctionObjArgs (func, event, NULL));
 
       if (func_result == NULL)
        {
@@ -116,21 +114,9 @@ evpy_emit_event (PyObject *event,
             call all of the callbacks even if one is broken.  */
          gdbpy_print_stack ();
        }
-      else
-       {
-         Py_DECREF (func_result);
-       }
     }
 
-  Py_XDECREF (callback_list_copy);
-  Py_XDECREF (event);
   return 0;
-
- fail:
-  gdbpy_print_stack ();
-  Py_XDECREF (callback_list_copy);
-  Py_XDECREF (event);
-  return -1;
 }
 
 static PyGetSetDef event_object_getset[] =
This page took 0.025182 seconds and 4 git commands to generate.