[glib] GApplication: Use a WARNING if dbus_unregister is called by destructor
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] GApplication: Use a WARNING if dbus_unregister is called by destructor
- Date: Mon, 24 Jul 2017 17:53:25 +0000 (UTC)
commit b51a0e7c63313ecfc0c6bbb9f2a8d99f193e51ea
Author: Debarshi Ray <debarshir gnome org>
Date: Fri Jul 21 14:37:35 2017 +0200
GApplication: Use a WARNING if dbus_unregister is called by destructor
Unlike g_application_register, there is no public API to unregister the
GApplication from D-Bus. Therefore, if the GApplication is set up
manually without using g_application_run, then neither can the
GApplicationImpl be destroyed nor can dbus_unregister be called before
destruction.
This is fine as long as no sub-class has implemented dbus_unregister.
If they have, their method method will be called after destruction, and
they should be prepared to deal with the consequences.
As long as there is no public API for unregistering, let's demote the
assertion to a WARNING. Bravehearts who don't use g_application_run
can continue to implement dbus_unregister, but they would have been
adequately notified.
This reverts commit c1ae1170fa47483b9bcb30de8cd346cbc4fe10e3.
https://bugzilla.gnome.org/show_bug.cgi?id=725950
gio/gapplication.c | 22 +++++++++++++++++-----
1 files changed, 17 insertions(+), 5 deletions(-)
---
diff --git a/gio/gapplication.c b/gio/gapplication.c
index 991e5d8..500fb78 100644
--- a/gio/gapplication.c
+++ b/gio/gapplication.c
@@ -1247,10 +1247,21 @@ g_application_dispose (GObject *object)
{
GApplication *application = G_APPLICATION (object);
- g_assert_null (application->priv->impl);
+ if (application->priv->impl != NULL &&
+ G_APPLICATION_GET_CLASS (application)->dbus_unregister != g_application_real_dbus_unregister)
+ {
+ static gboolean warned;
- G_OBJECT_CLASS (g_application_parent_class)
- ->dispose (object);
+ if (!warned)
+ {
+ g_warning ("Your application did not unregister from D-Bus before destruction. "
+ "Consider using g_application_run().");
+ }
+
+ warned = TRUE;
+ }
+
+ G_OBJECT_CLASS (g_application_parent_class)->dispose (object);
}
static void
@@ -1258,8 +1269,6 @@ g_application_finalize (GObject *object)
{
GApplication *application = G_APPLICATION (object);
- g_assert_null (application->priv->impl);
-
g_slist_free_full (application->priv->option_groups, (GDestroyNotify) g_option_group_unref);
if (application->priv->main_options)
g_option_group_unref (application->priv->main_options);
@@ -1267,6 +1276,9 @@ g_application_finalize (GObject *object)
g_hash_table_unref (application->priv->packed_options);
g_slist_free_full (application->priv->option_strings, g_free);
+
+ if (application->priv->impl)
+ g_application_impl_destroy (application->priv->impl);
g_free (application->priv->id);
if (g_application_get_default () == application)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]