This is the mail archive of the
archer@sourceware.org
mailing list for the Archer project.
[inferior events] cleanups in evpy_emit_event
- From: Tom Tromey <tromey at redhat dot com>
- To: Project Archer <archer at sourceware dot org>
- Date: Tue, 14 Dec 2010 14:35:31 -0700
- Subject: [inferior events] cleanups in evpy_emit_event
Sami --
This patch cleans up evpy_emit_event:
* It isn't ok to call error here
* Now we check all Python operations
* Now we call gdbpy_print_stack on error. This seems correct since
we don't actually want errors here to propagate -- just to be printed
if the user asked for that
* Now objects are properly deallocated
I needed this while debugging an event listener of mine.
Ok to push?
Tom
@@ -137,15 +145,31 @@ evpy_emit_event (event_object *event)
a notification. */
callback_list_copy = copy_py_list (callback_list);
if (!callback_list_copy)
- error(_("Cannot copy callback list."));
-
- args_tuple = PyTuple_New ((Py_ssize_t) 1);
- PyTuple_SetItem (args_tuple, (Py_ssize_t) 0, (PyObject *) event);
+ goto fail;
for (i = 0; i < PyList_Size (callback_list_copy); i++)
{
- PyObject_CallObject (PyList_GET_ITEM (callback_list_copy, i), args_tuple);
+ PyObject *func = PyList_GetItem (callback_list_copy, i);
+
+ if (func == NULL)
+ goto fail;
+
+ if (!PyObject_CallFunctionObjArgs (func, event_obj, NULL))
+ {
+ /* Print the trace here, but keep going -- we want to try to
+ call all of the callbacks even if one is broken. */
+ gdbpy_print_stack ();
+ }
}
+
+ Py_XDECREF (callback_list_copy);
+ Py_XDECREF (event_obj);
+ return;
+
+ fail:
+ gdbpy_print_stack ();
+ Py_XDECREF (callback_list_copy);
+ Py_XDECREF (event_obj);
}
static PyGetSetDef event_object_getset[] =