diff options
Diffstat (limited to 'dbus_bindings/conn-methods.c')
-rw-r--r-- | dbus_bindings/conn-methods.c | 47 |
1 files changed, 35 insertions, 12 deletions
diff --git a/dbus_bindings/conn-methods.c b/dbus_bindings/conn-methods.c index 424fdc4..ddd0766 100644 --- a/dbus_bindings/conn-methods.c +++ b/dbus_bindings/conn-methods.c @@ -3,6 +3,8 @@ * * Copyright (C) 2006 Collabora Ltd. <http://www.collabora.co.uk/> * + * SPDX-License-Identifier: MIT + * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation * files (the "Software"), to deal in the Software without @@ -32,9 +34,12 @@ static void _object_path_unregister(DBusConnection *conn, void *user_data) { PyGILState_STATE gil = PyGILState_Ensure(); + PyObject *et, *ev, *tb; PyObject *tuple = NULL; Connection *conn_obj = NULL; - PyObject *callable; + PyObject *callable = NULL; + + PyErr_Fetch(&et, &ev, &tb); conn_obj = (Connection *)DBusPyConnection_ExistingFromDBusConnection(conn); if (!conn_obj) goto out; @@ -57,13 +62,15 @@ _object_path_unregister(DBusConnection *conn, void *user_data) Py_XDECREF(PyObject_CallFunctionObjArgs(callable, conn_obj, NULL)); } out: + if (PyErr_Occurred()) { + PyErr_WriteUnraisable(callable); + } + Py_CLEAR(conn_obj); Py_CLEAR(tuple); /* the user_data (a Python str) is no longer ref'd by the DBusConnection */ Py_CLEAR(user_data); - if (PyErr_Occurred()) { - PyErr_Print(); - } + PyErr_Restore(et, ev, tb); PyGILState_Release(gil); } @@ -73,10 +80,13 @@ _object_path_message(DBusConnection *conn, DBusMessage *message, { DBusHandlerResult ret; PyGILState_STATE gil = PyGILState_Ensure(); + PyObject *et, *ev, *tb; Connection *conn_obj = NULL; PyObject *tuple = NULL; PyObject *msg_obj; - PyObject *callable; /* borrowed */ + PyObject *callable = NULL; /* borrowed */ + + PyErr_Fetch(&et, &ev, &tb); dbus_message_ref(message); msg_obj = DBusPyMessage_ConsumeDBusMessage(message); @@ -121,12 +131,14 @@ _object_path_message(DBusConnection *conn, DBusMessage *message, } out: + if (PyErr_Occurred()) { + PyErr_WriteUnraisable(callable); + } + Py_CLEAR(msg_obj); Py_CLEAR(conn_obj); Py_CLEAR(tuple); - if (PyErr_Occurred()) { - PyErr_Print(); - } + PyErr_Restore(et, ev, tb); PyGILState_Release(gil); return ret; } @@ -141,6 +153,7 @@ _filter_message(DBusConnection *conn, DBusMessage *message, void *user_data) { DBusHandlerResult ret; PyGILState_STATE gil = PyGILState_Ensure(); + PyObject *et, *ev, *tb; Connection *conn_obj = NULL; PyObject *callable = NULL; PyObject *msg_obj; @@ -148,6 +161,8 @@ _filter_message(DBusConnection *conn, DBusMessage *message, void *user_data) Py_ssize_t i, size; #endif + PyErr_Fetch(&et, &ev, &tb); + dbus_message_ref(message); msg_obj = DBusPyMessage_ConsumeDBusMessage(message); if (!msg_obj) { @@ -199,9 +214,14 @@ _filter_message(DBusConnection *conn, DBusMessage *message, void *user_data) ret = DBusPyConnection_HandleMessage(conn_obj, msg_obj, callable); out: + if (PyErr_Occurred()) { + PyErr_WriteUnraisable(callable); + } + Py_CLEAR(msg_obj); Py_CLEAR(conn_obj); Py_CLEAR(callable); + PyErr_Restore(et, ev, tb); PyGILState_Release(gil); return ret; } @@ -1033,7 +1053,10 @@ PyDoc_STRVAR(set_unique_name__doc__, "already been set.\n"); struct PyMethodDef DBusPyConnection_tp_methods[] = { -#define ENTRY(name, flags) {#name, (PyCFunction)Connection_##name, flags, Connection_##name##__doc__} +#define ENTRY(name, flags) {\ + #name, (PyCFunction) (void (*)(void)) Connection_##name, \ + flags, Connection_##name##__doc__ \ +} ENTRY(_require_main_loop, METH_NOARGS), ENTRY(close, METH_NOARGS), ENTRY(flush, METH_NOARGS), @@ -1051,13 +1074,13 @@ struct PyMethodDef DBusPyConnection_tp_methods[] = { ENTRY(send_message_with_reply_and_block, METH_VARARGS), ENTRY(_unregister_object_path, METH_VARARGS|METH_KEYWORDS), ENTRY(list_exported_child_objects, METH_VARARGS|METH_KEYWORDS), - {"_new_for_bus", (PyCFunction)DBusPyConnection_NewForBus, + {"_new_for_bus", (PyCFunction) (void (*)(void)) DBusPyConnection_NewForBus, METH_CLASS|METH_VARARGS|METH_KEYWORDS, new_for_bus__doc__}, - {"get_unique_name", (PyCFunction)DBusPyConnection_GetUniqueName, + {"get_unique_name", (PyCFunction) (void (*)(void)) DBusPyConnection_GetUniqueName, METH_NOARGS, get_unique_name__doc__}, - {"set_unique_name", (PyCFunction)DBusPyConnection_SetUniqueName, + {"set_unique_name", (PyCFunction) (void (*)(void)) DBusPyConnection_SetUniqueName, METH_VARARGS, set_unique_name__doc__}, ENTRY(set_allow_anonymous, METH_VARARGS), |