From: Tom Tromey Date: Fri, 8 Sep 2017 20:26:43 +0000 (-0600) Subject: Small event ownership clean up in Python layer X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=35c61a1dd5462ceab42618c48c9a60238245761b;p=binutils-gdb.git Small event ownership clean up in Python layer 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 * 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. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 086fff5aff5..61fb77efe9b 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,24 @@ +2017-09-11 Tom Tromey + + * 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 PR python/15622: diff --git a/gdb/python/py-bpevent.c b/gdb/python/py-bpevent.c index c5a85b6b4c2..021c83aff92 100644 --- a/gdb/python/py-bpevent.c +++ b/gdb/python/py-bpevent.c @@ -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, diff --git a/gdb/python/py-continueevent.c b/gdb/python/py-continueevent.c index 8be28c2cd2b..ca2927fcf35 100644 --- a/gdb/python/py-continueevent.c +++ b/gdb/python/py-continueevent.c @@ -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); diff --git a/gdb/python/py-event.c b/gdb/python/py-event.c index b349891269f..9d84e33c87c 100644 --- a/gdb/python/py-event.c +++ b/gdb/python/py-event.c @@ -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_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 diff --git a/gdb/python/py-event.h b/gdb/python/py-event.h index 2f02c5f861c..27db8287bb5 100644 --- a/gdb/python/py-event.h +++ b/gdb/python/py-event.h @@ -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); diff --git a/gdb/python/py-infevents.c b/gdb/python/py-infevents.c index 6e3c8c85105..8a63b79450e 100644 --- a/gdb/python/py-infevents.c +++ b/gdb/python/py-infevents.c @@ -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"); diff --git a/gdb/python/py-signalevent.c b/gdb/python/py-signalevent.c index a8f41c29b58..c2391def087 100644 --- a/gdb/python/py-signalevent.c +++ b/gdb/python/py-signalevent.c @@ -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, diff --git a/gdb/python/py-stopevent.c b/gdb/python/py-stopevent.c index cfa45918625..a0be5f2a26f 100644 --- a/gdb/python/py-stopevent.c +++ b/gdb/python/py-stopevent.c @@ -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; } diff --git a/gdb/python/py-stopevent.h b/gdb/python/py-stopevent.h index a56ca7e7760..62c52d7de8e 100644 --- a/gdb/python/py-stopevent.h +++ b/gdb/python/py-stopevent.h @@ -22,15 +22,15 @@ #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 */ diff --git a/gdb/python/py-threadevent.c b/gdb/python/py-threadevent.c index 7211fa26da2..8b742ca94a7 100644 --- a/gdb/python/py-threadevent.c +++ b/gdb/python/py-threadevent.c @@ -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,