Let commands free "name"
[deliverable/binutils-gdb.git] / gdb / python / py-newobjfileevent.c
index 1012c1312a1b4b8c5d82e23ab4c146e471bab790..bd12a1686e3eb7987e411800af6e6c1be89a684e 100644 (file)
@@ -1,6 +1,6 @@
 /* Python interface to new object file loading events.
 
-   Copyright (C) 2011-2017 Free Software Foundation, Inc.
+   Copyright (C) 2011-2019 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
 #include "defs.h"
 #include "py-event.h"
 
-extern PyTypeObject new_objfile_event_object_type
-    CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("event_object");
-extern PyTypeObject clear_objfiles_event_object_type
-    CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("event_object");
-
-static PyObject *
+static gdbpy_ref<>
 create_new_objfile_event_object (struct objfile *objfile)
 {
-  PyObject *objfile_event;
-  PyObject *py_objfile;
-
-  objfile_event = create_event_object (&new_objfile_event_object_type);
-  if (!objfile_event)
-    goto fail;
+  gdbpy_ref<> objfile_event
+    = create_event_object (&new_objfile_event_object_type);
+  if (objfile_event == NULL)
+    return NULL;
 
-  /* Note that objfile_to_objfile_object returns a borrowed reference,
-     so we don't need a decref here.  */
-  py_objfile = objfile_to_objfile_object (objfile);
-  if (!py_objfile || evpy_add_attribute (objfile_event,
-                                         "new_objfile",
-                                         py_objfile) < 0)
-    goto fail;
+  gdbpy_ref<> py_objfile = objfile_to_objfile_object (objfile);
+  if (py_objfile == NULL || evpy_add_attribute (objfile_event.get (),
+                                               "new_objfile",
+                                               py_objfile.get ()) < 0)
+    return NULL;
 
   return objfile_event;
-
- fail:
-  Py_XDECREF (objfile_event);
-  return NULL;
 }
 
 /* Callback function which notifies observers when a new objfile event occurs.
@@ -57,48 +44,33 @@ create_new_objfile_event_object (struct objfile *objfile)
 int
 emit_new_objfile_event (struct objfile *objfile)
 {
-  PyObject *event;
-
   if (evregpy_no_listeners_p (gdb_py_events.new_objfile))
     return 0;
 
-  event = create_new_objfile_event_object (objfile);
-  if (event)
-    return evpy_emit_event (event, gdb_py_events.new_objfile);
+  gdbpy_ref<> event = create_new_objfile_event_object (objfile);
+  if (event != NULL)
+    return evpy_emit_event (event.get (), gdb_py_events.new_objfile);
   return -1;
 }
 
-GDBPY_NEW_EVENT_TYPE (new_objfile,
-                      "gdb.NewObjFileEvent",
-                      "NewObjFileEvent",
-                      "GDB new object file event object",
-                      event_object_type);
 \f
 /* Subroutine of emit_clear_objfiles_event to simplify it.  */
 
-static PyObject *
+static gdbpy_ref<>
 create_clear_objfiles_event_object (void)
 {
-  PyObject *objfile_event;
-  PyObject *py_progspace;
+  gdbpy_ref<> objfile_event
+    = create_event_object (&clear_objfiles_event_object_type);
+  if (objfile_event == NULL)
+    return NULL;
 
-  objfile_event = create_event_object (&clear_objfiles_event_object_type);
-  if (!objfile_event)
-    goto fail;
-
-  /* Note that pspace_to_pspace_object returns a borrowed reference,
-     so we don't need a decref here.  */
-  py_progspace = pspace_to_pspace_object (current_program_space);
-  if (!py_progspace || evpy_add_attribute (objfile_event,
-                                          "progspace",
-                                          py_progspace) < 0)
-    goto fail;
+  gdbpy_ref<> py_progspace = pspace_to_pspace_object (current_program_space);
+  if (py_progspace == NULL || evpy_add_attribute (objfile_event.get (),
+                                                 "progspace",
+                                                 py_progspace.get ()) < 0)
+    return NULL;
 
   return objfile_event;
-
- fail:
-  Py_XDECREF (objfile_event);
-  return NULL;
 }
 
 /* Callback function which notifies observers when the "clear objfiles"
@@ -109,19 +81,11 @@ create_clear_objfiles_event_object (void)
 int
 emit_clear_objfiles_event (void)
 {
-  PyObject *event;
-
   if (evregpy_no_listeners_p (gdb_py_events.clear_objfiles))
     return 0;
 
-  event = create_clear_objfiles_event_object ();
-  if (event)
-    return evpy_emit_event (event, gdb_py_events.clear_objfiles);
+  gdbpy_ref<> event = create_clear_objfiles_event_object ();
+  if (event != NULL)
+    return evpy_emit_event (event.get (), gdb_py_events.clear_objfiles);
   return -1;
 }
-
-GDBPY_NEW_EVENT_TYPE (clear_objfiles,
-                     "gdb.ClearObjFilesEvent",
-                     "ClearObjFilesEvent",
-                     "GDB clear object files event object",
-                     event_object_type);
This page took 0.039618 seconds and 4 git commands to generate.