From 278b57d9f4a1aed4f0296b17a94bde2a36145a45 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Wed, 7 Feb 2007 13:15:17 +0000 Subject: [PATCH] Audit tp_dealloc callbacks to make sure they preserve the exception state. * Connection: use PyErr_Fetch and PyErr_Restore to preserve exception state * MainLoop: add a comment indicating that the "free" callback needs to do the same if it might alter the exception state --- _dbus_bindings/conn.c | 5 +++++ _dbus_bindings/mainloop.c | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/_dbus_bindings/conn.c b/_dbus_bindings/conn.c index 51ed5f1..23b5447 100644 --- a/_dbus_bindings/conn.c +++ b/_dbus_bindings/conn.c @@ -328,9 +328,13 @@ Connection_tp_new(PyTypeObject *cls, PyObject *args, PyObject *kwargs) static void Connection_tp_dealloc(Connection *self) { DBusConnection *conn = self->conn; + PyObject *et, *ev, *etb; PyObject *filters = self->filters; PyObject *object_paths = self->object_paths; + /* avoid clobbering any pending exception */ + PyErr_Fetch(&et, &ev, &etb); + if (self->weaklist) { PyObject_ClearWeakRefs((PyObject *)self); } @@ -367,6 +371,7 @@ static void Connection_tp_dealloc(Connection *self) } DBG("Connection at %p: freeing self", self); + PyErr_Restore(et, ev, etb); (self->ob_type->tp_free)((PyObject *)self); } diff --git a/_dbus_bindings/mainloop.c b/_dbus_bindings/mainloop.c index ed486ed..9d7de07 100644 --- a/_dbus_bindings/mainloop.c +++ b/_dbus_bindings/mainloop.c @@ -381,7 +381,8 @@ typedef struct { /* Called with the GIL held, should set a Python exception on error */ dbus_bool_t (*set_up_connection_cb)(DBusConnection *, void *); dbus_bool_t (*set_up_server_cb)(DBusServer *, void *); - /* Called in a destructor. */ + /* Called in a destructor. Must not touch the exception state (use + * PyErr_Fetch and PyErr_Restore if necessary). */ void (*free_cb)(void *); void *data; } NativeMainLoop; -- 2.11.4.GIT