aboutsummaryrefslogtreecommitdiff
path: root/gdb/python
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2016-11-06 20:42:32 -0700
committerTom Tromey <tom@tromey.com>2017-01-10 19:13:29 -0700
commitabf5651e47c0396df58a37951bc03a349169c5f2 (patch)
treed2ff93fd1a4b9801b7c1407f78d370742de4e0a8 /gdb/python
parenta68ff33e0dcb4733584265088030d12a31e740e4 (diff)
downloadgdb-abf5651e47c0396df58a37951bc03a349169c5f2.zip
gdb-abf5651e47c0396df58a37951bc03a349169c5f2.tar.gz
gdb-abf5651e47c0396df58a37951bc03a349169c5f2.tar.bz2
Change event code to use gdbpy_ref
This changes the event code in the Python layer to use gdbpy_ref, simplifying the logic in many places. It also changes evpy_emit_event not to steal a reference to its argument. This is simpler to do now that gdbpy_ref is in use; it's also a reasonable cleanup in its own right. While doing this I realized that evpy_emit_event should not be calling gdbpy_print_stack (all the outermost callers do this if needed), so I removed this as well. 2017-01-10 Tom Tromey <tom@tromey.com> * python/py-threadevent.c (create_thread_event_object): Use gdbpy_ref. * python/py-stopevent.c (create_stop_event_object): Simplify. (emit_stop_event): Use gdbpy_ref. * python/py-signalevent.c (create_signal_event_object): Use gdbpy_ref. * python/py-newobjfileevent.c (create_new_objfile_event_object) (emit_new_objfile_event, create_clear_objfiles_event_object) (emit_clear_objfiles_event): Use gdbpy_ref. * python/py-infevents.c (create_inferior_call_event_object) (create_register_changed_event_object) (create_memory_changed_event_object, emit_inferior_call_event) (emit_memory_changed_event, emit_register_changed_event): Use gdbpy_ref. * python/py-exitedevent.c (create_exited_event_object) (emit_exited_event): Use gdbpy_ref. * python/py-event.h (evpy_emit_event): Remove CPYCHECKER_STEALS_REFERENCE_TO_ARG annotation. * python/py-event.c (evpy_emit_event): Use gdbpy_ref. * python/py-continueevent.c (emit_continue_event): Use gdbpy_ref. * python/py-breakpoint.c (gdbpy_breakpoint_created) (gdbpy_breakpoint_deleted, gdbpy_breakpoint_modified): Use gdbpy_ref. * python/py-bpevent.c (create_breakpoint_event_object): Use gdbpy_ref.
Diffstat (limited to 'gdb/python')
-rw-r--r--gdb/python/py-bpevent.c23
-rw-r--r--gdb/python/py-breakpoint.c7
-rw-r--r--gdb/python/py-continueevent.c9
-rw-r--r--gdb/python/py-event.c28
-rw-r--r--gdb/python/py-event.h4
-rw-r--r--gdb/python/py-exitedevent.c49
-rw-r--r--gdb/python/py-infevents.c138
-rw-r--r--gdb/python/py-newobjfileevent.c52
-rw-r--r--gdb/python/py-signalevent.c27
-rw-r--r--gdb/python/py-stopevent.c54
-rw-r--r--gdb/python/py-threadevent.c19
11 files changed, 138 insertions, 272 deletions
diff --git a/gdb/python/py-bpevent.c b/gdb/python/py-bpevent.c
index f9c7083..c9b53b5 100644
--- a/gdb/python/py-bpevent.c
+++ b/gdb/python/py-bpevent.c
@@ -19,6 +19,7 @@
#include "defs.h"
#include "py-stopevent.h"
+#include "py-ref.h"
extern PyTypeObject breakpoint_event_object_type
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("event_object");
@@ -29,26 +30,22 @@ extern PyTypeObject breakpoint_event_object_type
PyObject *
create_breakpoint_event_object (PyObject *breakpoint_list, PyObject *first_bp)
{
- PyObject *breakpoint_event_obj =
- create_stop_event_object (&breakpoint_event_object_type);
+ gdbpy_ref breakpoint_event_obj
+ (create_stop_event_object (&breakpoint_event_object_type));
- if (!breakpoint_event_obj)
- goto fail;
+ if (breakpoint_event_obj == NULL)
+ return NULL;
- if (evpy_add_attribute (breakpoint_event_obj,
+ if (evpy_add_attribute (breakpoint_event_obj.get (),
"breakpoint",
first_bp) < 0)
- goto fail;
- if (evpy_add_attribute (breakpoint_event_obj,
+ return NULL;
+ if (evpy_add_attribute (breakpoint_event_obj.get (),
"breakpoints",
breakpoint_list) < 0)
- goto fail;
+ return NULL;
- return breakpoint_event_obj;
-
- fail:
- Py_XDECREF (breakpoint_event_obj);
- return NULL;
+ return breakpoint_event_obj.release ();
}
GDBPY_NEW_EVENT_TYPE (breakpoint,
diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c
index 7c7099b..c8847ff 100644
--- a/gdb/python/py-breakpoint.c
+++ b/gdb/python/py-breakpoint.c
@@ -918,7 +918,6 @@ gdbpy_breakpoint_created (struct breakpoint *bp)
if (!evregpy_no_listeners_p (gdb_py_events.breakpoint_created))
{
- Py_INCREF (newbp);
if (evpy_emit_event ((PyObject *) newbp,
gdb_py_events.breakpoint_created) < 0)
gdbpy_print_stack ();
@@ -946,10 +945,7 @@ gdbpy_breakpoint_deleted (struct breakpoint *b)
{
if (!evregpy_no_listeners_p (gdb_py_events.breakpoint_deleted))
{
- PyObject *bp_obj_alias = (PyObject *) bp_obj;
-
- Py_INCREF (bp_obj_alias);
- if (evpy_emit_event (bp_obj_alias,
+ if (evpy_emit_event ((PyObject *) bp_obj,
gdb_py_events.breakpoint_deleted) < 0)
gdbpy_print_stack ();
}
@@ -981,7 +977,6 @@ gdbpy_breakpoint_modified (struct breakpoint *b)
{
if (!evregpy_no_listeners_p (gdb_py_events.breakpoint_modified))
{
- Py_INCREF (bp_obj);
if (evpy_emit_event (bp_obj,
gdb_py_events.breakpoint_modified) < 0)
gdbpy_print_stack ();
diff --git a/gdb/python/py-continueevent.c b/gdb/python/py-continueevent.c
index 50795bc..84d2352 100644
--- a/gdb/python/py-continueevent.c
+++ b/gdb/python/py-continueevent.c
@@ -19,6 +19,7 @@
#include "defs.h"
#include "py-event.h"
+#include "py-ref.h"
extern PyTypeObject continue_event_object_type
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("event_object");
@@ -36,14 +37,12 @@ create_continue_event_object (void)
int
emit_continue_event (ptid_t ptid)
{
- PyObject *event;
-
if (evregpy_no_listeners_p (gdb_py_events.cont))
return 0;
- event = create_continue_event_object ();
- if (event)
- return evpy_emit_event (event, gdb_py_events.cont);
+ gdbpy_ref event (create_continue_event_object ());
+ if (event != NULL)
+ return evpy_emit_event (event.get (), gdb_py_events.cont);
return -1;
}
diff --git a/gdb/python/py-event.c b/gdb/python/py-event.c
index 7905bcf..a50da1f 100644
--- a/gdb/python/py-event.c
+++ b/gdb/python/py-event.c
@@ -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[] =
diff --git a/gdb/python/py-event.h b/gdb/python/py-event.h
index 43c43ba..4b2f4c0 100644
--- a/gdb/python/py-event.h
+++ b/gdb/python/py-event.h
@@ -24,6 +24,7 @@
#include "command.h"
#include "python-internal.h"
#include "inferior.h"
+#include "py-ref.h"
/* This macro creates the following functions:
@@ -121,8 +122,7 @@ extern int emit_register_changed_event (struct frame_info *frame,
int regnum);
extern int emit_memory_changed_event (CORE_ADDR addr, ssize_t len);
extern int evpy_emit_event (PyObject *event,
- eventregistry_object *registry)
- CPYCHECKER_STEALS_REFERENCE_TO_ARG (1);
+ eventregistry_object *registry);
extern PyObject *create_event_object (PyTypeObject *py_type);
extern PyObject *create_thread_event_object (PyTypeObject *py_type);
diff --git a/gdb/python/py-exitedevent.c b/gdb/python/py-exitedevent.c
index 96a7463..4590077 100644
--- a/gdb/python/py-exitedevent.c
+++ b/gdb/python/py-exitedevent.c
@@ -26,42 +26,29 @@ extern PyTypeObject exited_event_object_type
static PyObject *
create_exited_event_object (const LONGEST *exit_code, struct inferior *inf)
{
- PyObject *exited_event;
- PyObject *inf_obj = NULL;
+ gdbpy_ref exited_event (create_event_object (&exited_event_object_type));
- exited_event = create_event_object (&exited_event_object_type);
-
- if (!exited_event)
- goto fail;
+ if (exited_event == NULL)
+ return NULL;
if (exit_code)
{
- PyObject *exit_code_obj = PyLong_FromLongLong (*exit_code);
- int failed;
+ gdbpy_ref exit_code_obj (PyLong_FromLongLong (*exit_code));
if (exit_code_obj == NULL)
- goto fail;
-
- failed = evpy_add_attribute (exited_event, "exit_code",
- exit_code_obj) < 0;
- Py_DECREF (exit_code_obj);
- if (failed)
- goto fail;
+ return NULL;
+ if (evpy_add_attribute (exited_event.get (), "exit_code",
+ exit_code_obj.get ()) < 0)
+ return NULL;
}
- inf_obj = inferior_to_inferior_object (inf);
- if (!inf_obj || evpy_add_attribute (exited_event,
- "inferior",
- inf_obj) < 0)
- goto fail;
- Py_DECREF (inf_obj);
+ gdbpy_ref inf_obj (inferior_to_inferior_object (inf));
+ if (inf_obj == NULL || evpy_add_attribute (exited_event.get (),
+ "inferior",
+ inf_obj.get ()) < 0)
+ return NULL;
- return exited_event;
-
- fail:
- Py_XDECREF (inf_obj);
- Py_XDECREF (exited_event);
- return NULL;
+ return exited_event.release ();
}
/* Callback that is used when an exit event occurs. This function
@@ -70,15 +57,13 @@ create_exited_event_object (const LONGEST *exit_code, struct inferior *inf)
int
emit_exited_event (const LONGEST *exit_code, struct inferior *inf)
{
- PyObject *event;
-
if (evregpy_no_listeners_p (gdb_py_events.exited))
return 0;
- event = create_exited_event_object (exit_code, inf);
+ gdbpy_ref event (create_exited_event_object (exit_code, inf));
- if (event)
- return evpy_emit_event (event, gdb_py_events.exited);
+ if (event != NULL)
+ return evpy_emit_event (event.get (), gdb_py_events.exited);
return -1;
}
diff --git a/gdb/python/py-infevents.c b/gdb/python/py-infevents.c
index 2e31871..23bf57b 100644
--- a/gdb/python/py-infevents.c
+++ b/gdb/python/py-infevents.c
@@ -19,6 +19,7 @@
#include "defs.h"
#include "py-event.h"
+#include "py-ref.h"
extern PyTypeObject inferior_call_pre_event_object_type
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("event_object");
@@ -36,52 +37,36 @@ static PyObject *
create_inferior_call_event_object (inferior_call_kind flag, ptid_t ptid,
CORE_ADDR addr)
{
- PyObject *event;
- PyObject *ptid_obj = NULL;
- PyObject *addr_obj = NULL;
+ gdbpy_ref event;
int failed;
- struct cleanup *cleanups;
- struct cleanup *member_cleanups;
switch (flag)
{
case INFERIOR_CALL_PRE:
- event = create_event_object (&inferior_call_pre_event_object_type);
+ event.reset (create_event_object (&inferior_call_pre_event_object_type));
break;
case INFERIOR_CALL_POST:
- event = create_event_object (&inferior_call_post_event_object_type);
+ event.reset (create_event_object (&inferior_call_post_event_object_type));
break;
default:
- return NULL;
+ gdb_assert_not_reached ("invalid inferior_call_kind");
}
- cleanups = make_cleanup_py_decref (event);
-
- ptid_obj = gdbpy_create_ptid_object (ptid);
+ gdbpy_ref ptid_obj (gdbpy_create_ptid_object (ptid));
if (ptid_obj == NULL)
- goto fail;
- member_cleanups = make_cleanup_py_decref (ptid_obj);
+ return NULL;
- failed = evpy_add_attribute (event, "ptid", ptid_obj) < 0;
- if (failed)
- goto fail;
+ if (evpy_add_attribute (event.get (), "ptid", ptid_obj.get ()) < 0)
+ return NULL;
- addr_obj = PyLong_FromLongLong (addr);
+ gdbpy_ref addr_obj (PyLong_FromLongLong (addr));
if (addr_obj == NULL)
- goto fail;
- make_cleanup_py_decref (addr_obj);
-
- failed = evpy_add_attribute (event, "address", addr_obj) < 0;
- if (failed)
- goto fail;
+ return NULL;
- do_cleanups (member_cleanups);
- discard_cleanups (cleanups);
- return event;
+ if (evpy_add_attribute (event.get (), "address", addr_obj.get ()) < 0)
+ return NULL;
- fail:
- do_cleanups (cleanups);
- return NULL;
+ return event.release ();
}
/* Construct a gdb.RegisterChangedEvent containing the affected
@@ -91,44 +76,25 @@ static PyObject *
create_register_changed_event_object (struct frame_info *frame,
int regnum)
{
- PyObject *event;
- PyObject *frame_obj = NULL;
- PyObject *regnum_obj = NULL;
- int failed;
- struct cleanup *cleanups;
- struct cleanup *member_cleanups;
-
- event = create_event_object (&register_changed_event_object_type);
+ gdbpy_ref event (create_event_object (&register_changed_event_object_type));
if (event == NULL)
return NULL;
- cleanups = make_cleanup_py_decref (event);
-
- frame_obj = frame_info_to_frame_object (frame);
+ gdbpy_ref frame_obj (frame_info_to_frame_object (frame));
if (frame_obj == NULL)
- goto fail;
- member_cleanups = make_cleanup_py_decref (frame_obj);
+ return NULL;
- failed = evpy_add_attribute (event, "frame", frame_obj) < 0;
- if (failed)
- goto fail;
+ if (evpy_add_attribute (event.get (), "frame", frame_obj.get ()) < 0)
+ return NULL;
- regnum_obj = PyLong_FromLongLong (regnum);
+ gdbpy_ref regnum_obj (PyLong_FromLongLong (regnum));
if (regnum_obj == NULL)
- goto fail;
- make_cleanup_py_decref (regnum_obj);
-
- failed = evpy_add_attribute (event, "regnum", regnum_obj) < 0;
- if (failed)
- goto fail;
+ return NULL;
- do_cleanups (member_cleanups);
- discard_cleanups (cleanups);
- return event;
+ if (evpy_add_attribute (event.get (), "regnum", regnum_obj.get ()) < 0)
+ return NULL;
- fail:
- do_cleanups (cleanups);
- return NULL;
+ return event.release ();
}
/* Construct a gdb.MemoryChangedEvent describing the extent of the
@@ -137,44 +103,26 @@ create_register_changed_event_object (struct frame_info *frame,
static PyObject *
create_memory_changed_event_object (CORE_ADDR addr, ssize_t len)
{
- PyObject *event;
- PyObject *addr_obj = NULL;
- PyObject *len_obj = NULL;
- int failed;
- struct cleanup *cleanups;
- struct cleanup *member_cleanups;
-
- event = create_event_object (&memory_changed_event_object_type);
+ gdbpy_ref event (create_event_object (&memory_changed_event_object_type));
if (event == NULL)
return NULL;
- cleanups = make_cleanup_py_decref (event);
- addr_obj = PyLong_FromLongLong (addr);
+ gdbpy_ref addr_obj (PyLong_FromLongLong (addr));
if (addr_obj == NULL)
- goto fail;
- member_cleanups = make_cleanup_py_decref (addr_obj);
+ return NULL;
- failed = evpy_add_attribute (event, "address", addr_obj) < 0;
- if (failed)
- goto fail;
+ if (evpy_add_attribute (event.get (), "address", addr_obj.get ()) < 0)
+ return NULL;
- len_obj = PyLong_FromLong (len);
+ gdbpy_ref len_obj (PyLong_FromLong (len));
if (len_obj == NULL)
- goto fail;
- make_cleanup_py_decref (len_obj);
-
- failed = evpy_add_attribute (event, "length", len_obj) < 0;
- if (failed)
- goto fail;
+ return NULL;
- do_cleanups (member_cleanups);
- discard_cleanups (cleanups);
- return event;
+ if (evpy_add_attribute (event.get (), "length", len_obj.get ()) < 0)
+ return NULL;
- fail:
- do_cleanups (cleanups);
- return NULL;
+ return event.release ();
}
/* Callback function which notifies observers when an event occurs which
@@ -186,14 +134,12 @@ int
emit_inferior_call_event (inferior_call_kind flag, ptid_t thread,
CORE_ADDR addr)
{
- PyObject *event;
-
if (evregpy_no_listeners_p (gdb_py_events.inferior_call))
return 0;
- event = create_inferior_call_event_object (flag, thread, addr);
+ gdbpy_ref event (create_inferior_call_event_object (flag, thread, addr));
if (event != NULL)
- return evpy_emit_event (event, gdb_py_events.inferior_call);
+ return evpy_emit_event (event.get (), gdb_py_events.inferior_call);
return -1;
}
@@ -203,14 +149,12 @@ emit_inferior_call_event (inferior_call_kind flag, ptid_t thread,
int
emit_memory_changed_event (CORE_ADDR addr, ssize_t len)
{
- PyObject *event;
-
if (evregpy_no_listeners_p (gdb_py_events.memory_changed))
return 0;
- event = create_memory_changed_event_object (addr, len);
+ gdbpy_ref event (create_memory_changed_event_object (addr, len));
if (event != NULL)
- return evpy_emit_event (event, gdb_py_events.memory_changed);
+ return evpy_emit_event (event.get (), gdb_py_events.memory_changed);
return -1;
}
@@ -220,14 +164,12 @@ emit_memory_changed_event (CORE_ADDR addr, ssize_t len)
int
emit_register_changed_event (struct frame_info* frame, int regnum)
{
- PyObject *event;
-
if (evregpy_no_listeners_p (gdb_py_events.register_changed))
return 0;
- event = create_register_changed_event_object (frame, regnum);
+ gdbpy_ref event (create_register_changed_event_object (frame, regnum));
if (event != NULL)
- return evpy_emit_event (event, gdb_py_events.register_changed);
+ return evpy_emit_event (event.get (), gdb_py_events.register_changed);
return -1;
}
diff --git a/gdb/python/py-newobjfileevent.c b/gdb/python/py-newobjfileevent.c
index 1012c13..b8f9774 100644
--- a/gdb/python/py-newobjfileevent.c
+++ b/gdb/python/py-newobjfileevent.c
@@ -28,26 +28,22 @@ extern PyTypeObject clear_objfiles_event_object_type
static PyObject *
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,
+ if (!py_objfile || evpy_add_attribute (objfile_event.get (),
"new_objfile",
py_objfile) < 0)
- goto fail;
+ return NULL;
- return objfile_event;
-
- fail:
- Py_XDECREF (objfile_event);
- return NULL;
+ return objfile_event.release ();
}
/* Callback function which notifies observers when a new objfile event occurs.
@@ -57,14 +53,12 @@ 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;
}
@@ -79,26 +73,22 @@ GDBPY_NEW_EVENT_TYPE (new_objfile,
static PyObject *
create_clear_objfiles_event_object (void)
{
- PyObject *objfile_event;
PyObject *py_progspace;
- objfile_event = create_event_object (&clear_objfiles_event_object_type);
- if (!objfile_event)
- goto fail;
+ gdbpy_ref objfile_event
+ (create_event_object (&clear_objfiles_event_object_type));
+ if (objfile_event == NULL)
+ return NULL;
/* 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,
+ if (!py_progspace || evpy_add_attribute (objfile_event.get (),
"progspace",
py_progspace) < 0)
- goto fail;
+ return NULL;
- return objfile_event;
-
- fail:
- Py_XDECREF (objfile_event);
- return NULL;
+ return objfile_event.release ();
}
/* Callback function which notifies observers when the "clear objfiles"
@@ -109,14 +99,12 @@ 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;
}
diff --git a/gdb/python/py-signalevent.c b/gdb/python/py-signalevent.c
index 9d21541..e4e9768 100644
--- a/gdb/python/py-signalevent.c
+++ b/gdb/python/py-signalevent.c
@@ -27,30 +27,23 @@ PyObject *
create_signal_event_object (enum gdb_signal stop_signal)
{
const char *signal_name;
- PyObject *signal_name_obj = NULL;
- PyObject *signal_event_obj =
- create_stop_event_object (&signal_event_object_type);
+ gdbpy_ref signal_event_obj
+ (create_stop_event_object (&signal_event_object_type));
- if (!signal_event_obj)
- goto fail;
+ if (signal_event_obj == NULL)
+ return NULL;
signal_name = gdb_signal_to_name (stop_signal);
- signal_name_obj = PyString_FromString (signal_name);
+ gdbpy_ref signal_name_obj (PyString_FromString (signal_name));
if (signal_name_obj == NULL)
- goto fail;
- if (evpy_add_attribute (signal_event_obj,
+ return NULL;
+ if (evpy_add_attribute (signal_event_obj.get (),
"stop_signal",
- signal_name_obj) < 0)
- goto fail;
- Py_DECREF (signal_name_obj);
+ signal_name_obj.get ()) < 0)
+ return NULL;
- return signal_event_obj;
-
- fail:
- Py_XDECREF (signal_name_obj);
- Py_XDECREF (signal_event_obj);
- return NULL;
+ return signal_event_obj.release ();
}
GDBPY_NEW_EVENT_TYPE (signal,
diff --git a/gdb/python/py-stopevent.c b/gdb/python/py-stopevent.c
index 640d99a..b87ebda 100644
--- a/gdb/python/py-stopevent.c
+++ b/gdb/python/py-stopevent.c
@@ -23,16 +23,7 @@
PyObject *
create_stop_event_object (PyTypeObject *py_type)
{
- PyObject *stop_event_obj = create_thread_event_object (py_type);
-
- if (!stop_event_obj)
- goto fail;
-
- return stop_event_obj;
-
- fail:
- Py_XDECREF (stop_event_obj);
- return NULL;
+ return create_thread_event_object (py_type);
}
/* Callback observers when a stop event occurs. This function will create a
@@ -45,8 +36,8 @@ create_stop_event_object (PyTypeObject *py_type)
int
emit_stop_event (struct bpstats *bs, enum gdb_signal stop_signal)
{
- PyObject *stop_event_obj = NULL; /* Appease GCC warning. */
- PyObject *list = NULL;
+ gdbpy_ref stop_event_obj;
+ gdbpy_ref list;
PyObject *first_bp = NULL;
struct bpstats *current_bs;
@@ -64,13 +55,13 @@ emit_stop_event (struct bpstats *bs, enum gdb_signal stop_signal)
if (list == NULL)
{
- list = PyList_New (0);
- if (!list)
- goto fail;
+ list.reset (PyList_New (0));
+ if (list == NULL)
+ return -1;
}
- if (PyList_Append (list, current_py_bp))
- goto fail;
+ if (PyList_Append (list.get (), current_py_bp))
+ return -1;
if (first_bp == NULL)
first_bp = current_py_bp;
@@ -79,36 +70,31 @@ emit_stop_event (struct bpstats *bs, enum gdb_signal stop_signal)
if (list != NULL)
{
- stop_event_obj = create_breakpoint_event_object (list, first_bp);
- if (!stop_event_obj)
- goto fail;
- Py_DECREF (list);
+ stop_event_obj.reset (create_breakpoint_event_object (list.get (),
+ first_bp));
+ if (stop_event_obj == NULL)
+ return -1;
}
/* Check if the signal is "Signal 0" or "Trace/breakpoint trap". */
if (stop_signal != GDB_SIGNAL_0
&& stop_signal != GDB_SIGNAL_TRAP)
{
- stop_event_obj =
- create_signal_event_object (stop_signal);
- if (!stop_event_obj)
- goto fail;
+ stop_event_obj.reset (create_signal_event_object (stop_signal));
+ if (stop_event_obj == NULL)
+ return -1;
}
/* If all fails emit an unknown stop event. All event types should
be known and this should eventually be unused. */
- if (!stop_event_obj)
+ if (stop_event_obj == NULL)
{
- stop_event_obj = create_stop_event_object (&stop_event_object_type);
- if (!stop_event_obj)
- goto fail;
+ stop_event_obj.reset (create_stop_event_object (&stop_event_object_type));
+ if (stop_event_obj == NULL)
+ return -1;
}
- return evpy_emit_event (stop_event_obj, gdb_py_events.stop);
-
- fail:
- Py_XDECREF (list);
- return -1;
+ return evpy_emit_event (stop_event_obj.get (), gdb_py_events.stop);
}
GDBPY_NEW_EVENT_TYPE (stop,
diff --git a/gdb/python/py-threadevent.c b/gdb/python/py-threadevent.c
index edcf3c0..bba974b 100644
--- a/gdb/python/py-threadevent.c
+++ b/gdb/python/py-threadevent.c
@@ -51,26 +51,21 @@ PyObject *
create_thread_event_object (PyTypeObject *py_type)
{
PyObject *thread = NULL;
- PyObject *thread_event_obj = NULL;
- thread_event_obj = create_event_object (py_type);
- if (!thread_event_obj)
- goto fail;
+ gdbpy_ref thread_event_obj (create_event_object (py_type));
+ if (thread_event_obj == NULL)
+ return NULL;
thread = get_event_thread ();
if (!thread)
- goto fail;
+ return NULL;
- if (evpy_add_attribute (thread_event_obj,
+ if (evpy_add_attribute (thread_event_obj.get (),
"inferior_thread",
thread) < 0)
- goto fail;
+ return NULL;
- return thread_event_obj;
-
- fail:
- Py_XDECREF (thread_event_obj);
- return NULL;
+ return thread_event_obj.release ();
}
GDBPY_NEW_EVENT_TYPE (thread,