Tom Tromey
2010-12-14 21:35:31 UTC
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[] =
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[] =