Small event ownership clean up in Python layer
authorTom Tromey <tom@tromey.com>
Fri, 8 Sep 2017 20:26:43 +0000 (14:26 -0600)
committerTom Tromey <tom@tromey.com>
Mon, 11 Sep 2017 20:15:21 +0000 (14:15 -0600)
It seems cleaner to me for functions like create_thread_event_object,
which pass object ownership to their callers, to directly return a
gdb_ref<>.  This way the ownership transfer is part of the API.  This
patch makes this change.

ChangeLog
2017-09-11  Tom Tromey  <tom@tromey.com>

* python/py-threadevent.c (create_thread_event_object): Return
gdbpy_ref.
* python/py-stopevent.h (create_stop_event_object)
(create_breakpoint_event_object, create_signal_event_object):
Update.
* python/py-stopevent.c (create_stop_event_object): Return
gdbpy_ref.
(emit_stop_event): Update.
* python/py-signalevent.c (create_signal_event_object): Return
gdbpy_ref.
* python/py-infevents.c (create_inferior_call_event_object):
Update.
* python/py-event.h (create_event_object)
(create_thread_event_object): Update.
* python/py-event.c (create_event_object): Return gdbpy_ref.
* python/py-continueevent.c: Return gdbpy_ref.
* python/py-bpevent.c (create_breakpoint_event_object): Return
gdbpy_ref.

gdb/ChangeLog
gdb/python/py-bpevent.c
gdb/python/py-continueevent.c
gdb/python/py-event.c
gdb/python/py-event.h
gdb/python/py-infevents.c
gdb/python/py-signalevent.c
gdb/python/py-stopevent.c
gdb/python/py-stopevent.h
gdb/python/py-threadevent.c

index 086fff5aff5aa3afb811d220cb3f8142349d2be9..61fb77efe9bcf0580d46a2869a31aeeb7bde7593 100644 (file)
@@ -1,3 +1,24 @@
+2017-09-11  Tom Tromey  <tom@tromey.com>
+
+       * python/py-threadevent.c (create_thread_event_object): Return
+       gdbpy_ref.
+       * python/py-stopevent.h (create_stop_event_object)
+       (create_breakpoint_event_object, create_signal_event_object):
+       Update.
+       * python/py-stopevent.c (create_stop_event_object): Return
+       gdbpy_ref.
+       (emit_stop_event): Update.
+       * python/py-signalevent.c (create_signal_event_object): Return
+       gdbpy_ref.
+       * python/py-infevents.c (create_inferior_call_event_object):
+       Update.
+       * python/py-event.h (create_event_object)
+       (create_thread_event_object): Update.
+       * python/py-event.c (create_event_object): Return gdbpy_ref.
+       * python/py-continueevent.c: Return gdbpy_ref.
+       * python/py-bpevent.c (create_breakpoint_event_object): Return
+       gdbpy_ref.
+
 2017-09-11  Tom Tromey  <tom@tromey.com>
 
        PR python/15622:
index c5a85b6b4c2af674b6e93b08c160204b776cd7af..021c83aff9236d5577e46cbd770a304db2143ae2 100644 (file)
@@ -27,7 +27,7 @@ extern PyTypeObject breakpoint_event_object_type
 /* Create and initialize a BreakpointEvent object.  This acquires new
    references to BREAKPOINT_LIST and FIRST_BP.  */
 
-PyObject *
+gdbpy_ref<>
 create_breakpoint_event_object (PyObject *breakpoint_list, PyObject *first_bp)
 {
   gdbpy_ref<> breakpoint_event_obj
@@ -45,7 +45,7 @@ create_breakpoint_event_object (PyObject *breakpoint_list, PyObject *first_bp)
                           breakpoint_list) < 0)
     return NULL;
 
-  return breakpoint_event_obj.release ();
+  return breakpoint_event_obj;
 }
 
 GDBPY_NEW_EVENT_TYPE (breakpoint,
index 8be28c2cd2bbb4c9aa5adc1e264b0e8240f4b0cd..ca2927fcf35a4fe02ed31d23ac44b701c1f2937f 100644 (file)
@@ -24,7 +24,7 @@
 extern PyTypeObject continue_event_object_type
     CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("event_object");
 
-static PyObject *
+static gdbpy_ref<>
 create_continue_event_object (void)
 {
   return create_thread_event_object (&continue_event_object_type);
index b349891269fc859be44908434e06fe13d937a093..9d84e33c87c621d99ba2558a2daa840b8b0b32ee 100644 (file)
@@ -27,7 +27,7 @@ evpy_dealloc (PyObject *self)
   Py_TYPE (self)->tp_free (self);
 }
 
-PyObject *
+gdbpy_ref<>
 create_event_object (PyTypeObject *py_type)
 {
   gdbpy_ref<event_object> event_obj (PyObject_New (event_object, py_type));
@@ -38,7 +38,7 @@ create_event_object (PyTypeObject *py_type)
   if (!event_obj->dict)
     return NULL;
 
-  return (PyObject*) event_obj.release ();
+  return gdbpy_ref<> ((PyObject *) event_obj.release ());
 }
 
 /* Add the attribute ATTR to the event object EVENT.  In
index 2f02c5f861c2d03acdcbf6a4a7c6b156184e535c..27db8287bb5839e11913410bb3730ec19fe6c3b3 100644 (file)
@@ -124,9 +124,9 @@ extern int emit_memory_changed_event (CORE_ADDR addr, ssize_t len);
 extern int evpy_emit_event (PyObject *event,
                             eventregistry_object *registry);
 
-extern PyObject *create_event_object (PyTypeObject *py_type);
-extern PyObject *create_thread_event_object (PyTypeObject *py_type,
-                                            PyObject *thread = nullptr);
+extern gdbpy_ref<> create_event_object (PyTypeObject *py_type);
+extern gdbpy_ref<> create_thread_event_object (PyTypeObject *py_type,
+                                              PyObject *thread = nullptr);
 extern int emit_new_objfile_event (struct objfile *objfile);
 extern int emit_clear_objfiles_event (void);
 
index 6e3c8c85105c55e95ae9aba806aa7239d9776572..8a63b79450e414d62de43c5fda7b097b31420f25 100644 (file)
@@ -43,10 +43,10 @@ create_inferior_call_event_object (inferior_call_kind flag, ptid_t ptid,
   switch (flag)
     {
     case INFERIOR_CALL_PRE:
-      event.reset (create_event_object (&inferior_call_pre_event_object_type));
+      event = create_event_object (&inferior_call_pre_event_object_type);
       break;
     case INFERIOR_CALL_POST:
-      event.reset (create_event_object (&inferior_call_post_event_object_type));
+      event = create_event_object (&inferior_call_post_event_object_type);
       break;
     default:
       gdb_assert_not_reached ("invalid inferior_call_kind");
index a8f41c29b58712a3d8e0f1a32db2138258deb8ab..c2391def087850a939f2065ceac6ba9e403622fc 100644 (file)
@@ -23,7 +23,7 @@
 extern PyTypeObject signal_event_object_type
     CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("event_object");
 
-PyObject *
+gdbpy_ref<>
 create_signal_event_object (enum gdb_signal stop_signal)
 {
   const char *signal_name;
@@ -43,7 +43,7 @@ create_signal_event_object (enum gdb_signal stop_signal)
                           signal_name_obj.get ()) < 0)
     return NULL;
 
-  return signal_event_obj.release ();
+  return signal_event_obj;
 }
 
 GDBPY_NEW_EVENT_TYPE (signal,
index cfa45918625d3234aa665b4a6a6ba4896c484cb6..a0be5f2a26f6093b94621495d989b9c0266f6940 100644 (file)
@@ -20,7 +20,7 @@
 #include "defs.h"
 #include "py-stopevent.h"
 
-PyObject *
+gdbpy_ref<>
 create_stop_event_object (PyTypeObject *py_type)
 {
   return create_thread_event_object (py_type);
@@ -70,8 +70,8 @@ emit_stop_event (struct bpstats *bs, enum gdb_signal stop_signal)
 
   if (list != NULL)
     {
-      stop_event_obj.reset (create_breakpoint_event_object (list.get (),
-                                                           first_bp));
+      stop_event_obj = create_breakpoint_event_object (list.get (),
+                                                      first_bp);
       if (stop_event_obj == NULL)
        return -1;
     }
@@ -80,7 +80,7 @@ emit_stop_event (struct bpstats *bs, enum gdb_signal stop_signal)
   if (stop_signal != GDB_SIGNAL_0
       && stop_signal != GDB_SIGNAL_TRAP)
     {
-      stop_event_obj.reset (create_signal_event_object (stop_signal));
+      stop_event_obj = create_signal_event_object (stop_signal);
       if (stop_event_obj == NULL)
        return -1;
     }
@@ -89,7 +89,7 @@ emit_stop_event (struct bpstats *bs, enum gdb_signal stop_signal)
      be known and this should eventually be unused.  */
   if (stop_event_obj == NULL)
     {
-      stop_event_obj.reset (create_stop_event_object (&stop_event_object_type));
+      stop_event_obj = create_stop_event_object (&stop_event_object_type);
       if (stop_event_obj == NULL)
        return -1;
     }
index a56ca7e7760ee47e554593da20eb7345c5f2f1d7..62c52d7de8e30cb4f9179a7062dfcf2f7be9b90d 100644 (file)
 
 #include "py-event.h"
 
-extern PyObject *create_stop_event_object (PyTypeObject *py_type);
+extern gdbpy_ref<> create_stop_event_object (PyTypeObject *py_type);
 extern void stop_evpy_dealloc (PyObject *self);
 
 extern int emit_stop_event (struct bpstats *bs,
                             enum gdb_signal stop_signal);
 
-extern PyObject *create_breakpoint_event_object (PyObject *breakpoint_list,
-                                                 PyObject *first_bp);
+extern gdbpy_ref<> create_breakpoint_event_object (PyObject *breakpoint_list,
+                                                  PyObject *first_bp);
 
-extern PyObject *create_signal_event_object (enum gdb_signal stop_signal);
+extern gdbpy_ref<> create_signal_event_object (enum gdb_signal stop_signal);
 
 #endif /* GDB_PY_STOPEVENT_H */
index 7211fa26da2a168846cf67474a800ed026a11868..8b742ca94a71eb717dc4860d6964904e5c52da89 100644 (file)
@@ -47,7 +47,7 @@ get_event_thread (void)
   return thread;
 }
 
-PyObject *
+gdbpy_ref<>
 create_thread_event_object (PyTypeObject *py_type, PyObject *thread)
 {
   gdbpy_ref<> thread_event_obj (create_event_object (py_type));
@@ -66,7 +66,7 @@ create_thread_event_object (PyTypeObject *py_type, PyObject *thread)
                           thread) < 0)
     return NULL;
 
-  return thread_event_obj.release ();
+  return thread_event_obj;
 }
 
 GDBPY_NEW_EVENT_TYPE (thread,