[gnome-session/wip/modernize: 3/5] Use g_clear_object/g_clear_pointer



commit 655d9bdb797a518ae4fe78ac3a427d2e8b5a2fe5
Author: Colin Walters <walters verbum org>
Date:   Thu Oct 25 02:12:32 2012 -0400

    Use g_clear_object/g_clear_pointer
    
    Just makes the code feel more modern.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=687067

 gnome-session/gsm-autostart-app.c     |   36 +++++--------------------
 gnome-session/gsm-fail-whale-dialog.c |    5 +---
 gnome-session/gsm-inhibit-dialog.c    |   21 +++-----------
 gnome-session/gsm-logout-dialog.c     |    6 +---
 gnome-session/gsm-manager.c           |   47 +++++---------------------------
 gnome-session/gsm-shell-extensions.c  |    6 +---
 gnome-session/gsm-shell.c             |   33 +++++------------------
 gnome-session/gsm-util.c              |    4 +--
 gnome-session/main.c                  |   20 +++-----------
 tools/gnome-session-quit.c            |    8 +----
 10 files changed, 37 insertions(+), 149 deletions(-)
---
diff --git a/gnome-session/gsm-autostart-app.c b/gnome-session/gsm-autostart-app.c
index 7478dff..2cf1776 100644
--- a/gnome-session/gsm-autostart-app.c
+++ b/gnome-session/gsm-autostart-app.c
@@ -760,35 +760,17 @@ gsm_autostart_app_dispose (GObject *object)
 
         priv = GSM_AUTOSTART_APP (object)->priv;
 
-        if (priv->startup_id) {
-                g_free (priv->startup_id);
-                priv->startup_id = NULL;
-        }
+        g_clear_pointer (&priv->startup_id, g_free);
 
         if (priv->session_provides) {
                 g_slist_free_full (priv->session_provides, g_free);
                 priv->session_provides = NULL;
         }
 
-        if (priv->condition_string) {
-                g_free (priv->condition_string);
-                priv->condition_string = NULL;
-        }
-
-        if (priv->condition_settings) {
-                g_object_unref (priv->condition_settings);
-                priv->condition_settings = NULL;
-        }
-
-        if (priv->desktop_file) {
-                egg_desktop_file_free (priv->desktop_file);
-                priv->desktop_file = NULL;
-        }
-
-        if (priv->desktop_id) {
-                g_free (priv->desktop_id);
-                priv->desktop_id = NULL;
-        }
+        g_clear_pointer (&priv->condition_string, g_free);
+        g_clear_object (&priv->condition_settings);
+        g_clear_pointer (&priv->desktop_file, (GDestroyNotify) egg_desktop_file_free);
+        g_clear_pointer (&priv->desktop_id, g_free);
 
         if (priv->child_watch_id > 0) {
                 g_source_remove (priv->child_watch_id);
@@ -800,10 +782,7 @@ gsm_autostart_app_dispose (GObject *object)
                 priv->proxy_call = NULL;
         }
 
-        if (priv->proxy != NULL) {
-                g_object_unref (priv->proxy);
-                priv->proxy = NULL;
-        }
+        g_clear_object (&priv->proxy);
 
         if (priv->condition_monitor) {
                 g_file_monitor_cancel (priv->condition_monitor);
@@ -1161,8 +1140,7 @@ autostart_app_start_activate (GsmAutostartApp  *app,
                                                          G_TYPE_STRING, arguments,
                                                          G_TYPE_INVALID);
         if (app->priv->proxy_call == NULL) {
-                g_object_unref (app->priv->proxy);
-                app->priv->proxy = NULL;
+                g_clear_object (&app->priv->proxy);
                 g_set_error (error,
                              GSM_APP_ERROR,
                              GSM_APP_ERROR_START,
diff --git a/gnome-session/gsm-fail-whale-dialog.c b/gnome-session/gsm-fail-whale-dialog.c
index ee2527a..4736136 100644
--- a/gnome-session/gsm-fail-whale-dialog.c
+++ b/gnome-session/gsm-fail-whale-dialog.c
@@ -135,10 +135,7 @@ gsm_fail_whale_dialog_finalize (GObject *object)
         GsmFailWhaleDialog *fail_dialog = GSM_FAIL_WHALE_DIALOG (object);
         GsmFailWhaleDialogPrivate *priv = fail_dialog->priv;
 
-        if (priv->extensions != NULL) {
-                g_object_unref (priv->extensions);
-                priv->extensions = NULL;
-        }
+        g_clear_object (&priv->extensions);
 
         G_OBJECT_CLASS (gsm_fail_whale_dialog_parent_class)->finalize (object);
 }
diff --git a/gnome-session/gsm-inhibit-dialog.c b/gnome-session/gsm-inhibit-dialog.c
index 1ec3a8a..e2c39de 100644
--- a/gnome-session/gsm-inhibit-dialog.c
+++ b/gnome-session/gsm-inhibit-dialog.c
@@ -608,12 +608,8 @@ add_inhibitor (GsmInhibitDialog *dialog,
 
         g_free (desktop_filename);
         g_free (freeme);
-        if (pixbuf != NULL) {
-                g_object_unref (pixbuf);
-        }
-        if (desktop_file != NULL) {
-                egg_desktop_file_free (desktop_file);
-        }
+        g_clear_object (&pixbuf);
+        g_clear_pointer (&desktop_file, egg_desktop_file_free);
 }
 
 static gboolean
@@ -1000,10 +996,7 @@ gsm_inhibit_dialog_dispose (GObject *object)
 
         g_debug ("GsmInhibitDialog: dispose called");
 
-        if (dialog->priv->list_store != NULL) {
-                g_object_unref (dialog->priv->list_store);
-                dialog->priv->list_store = NULL;
-        }
+        g_clear_object (&dialog->priv->list_store);
 
         if (dialog->priv->inhibitors != NULL) {
                 g_signal_handlers_disconnect_by_func (dialog->priv->inhibitors,
@@ -1013,14 +1006,10 @@ gsm_inhibit_dialog_dispose (GObject *object)
                                                       on_store_inhibitor_removed,
                                                       dialog);
 
-                g_object_unref (dialog->priv->inhibitors);
-                dialog->priv->inhibitors = NULL;
+                g_clear_object (&dialog->priv->inhibitors);
         }
 
-        if (dialog->priv->xml != NULL) {
-                g_object_unref (dialog->priv->xml);
-                dialog->priv->xml = NULL;
-        }
+        g_clear_object (&dialog->priv->xml);
 
         G_OBJECT_CLASS (gsm_inhibit_dialog_parent_class)->dispose (object);
 }
diff --git a/gnome-session/gsm-logout-dialog.c b/gnome-session/gsm-logout-dialog.c
index e48afa7..3bddbab 100644
--- a/gnome-session/gsm-logout-dialog.c
+++ b/gnome-session/gsm-logout-dialog.c
@@ -163,11 +163,7 @@ gsm_logout_dialog_destroy (GsmLogoutDialog *logout_dialog,
                 logout_dialog->priv->timeout_id = 0;
         }
 
-        if (logout_dialog->priv->up_client) {
-                g_object_unref (logout_dialog->priv->up_client);
-                logout_dialog->priv->up_client = NULL;
-        }
-
+        g_clear_object (&logout_dialog->priv->up_client);
         g_clear_object (&logout_dialog->priv->system);
 
         current_dialog = NULL;
diff --git a/gnome-session/gsm-manager.c b/gnome-session/gsm-manager.c
index 9f7cff5..9c50c16 100644
--- a/gnome-session/gsm-manager.c
+++ b/gnome-session/gsm-manager.c
@@ -2515,11 +2515,7 @@ gsm_manager_dispose (GObject *object)
                 manager->priv->clients = NULL;
         }
 
-        if (manager->priv->apps != NULL) {
-                g_object_unref (manager->priv->apps);
-                manager->priv->apps = NULL;
-        }
-
+        g_clear_object (&manager->priv->apps);
         g_slist_free (manager->priv->required_apps);
         manager->priv->required_apps = NULL;
 
@@ -2535,40 +2531,13 @@ gsm_manager_dispose (GObject *object)
                 manager->priv->inhibitors = NULL;
         }
 
-        if (manager->priv->presence != NULL) {
-                g_object_unref (manager->priv->presence);
-                manager->priv->presence = NULL;
-        }
-
-        if (manager->priv->settings) {
-                g_object_unref (manager->priv->settings);
-                manager->priv->settings = NULL;
-        }
-
-        if (manager->priv->session_settings) {
-                g_object_unref (manager->priv->session_settings);
-                manager->priv->session_settings = NULL;
-        }
-
-        if (manager->priv->screensaver_settings) {
-                g_object_unref (manager->priv->screensaver_settings);
-                manager->priv->screensaver_settings = NULL;
-        }
-
-        if (manager->priv->lockdown_settings) {
-                g_object_unref (manager->priv->lockdown_settings);
-                manager->priv->lockdown_settings = NULL;
-        }
-
-        if (manager->priv->system != NULL) {
-                g_object_unref (manager->priv->system);
-                manager->priv->system = NULL;
-        }
-
-        if (manager->priv->shell != NULL) {
-                g_object_unref (manager->priv->shell);
-                manager->priv->shell = NULL;
-        }
+        g_clear_object (&manager->priv->presence);
+        g_clear_object (&manager->priv->settings);
+        g_clear_object (&manager->priv->session_settings);
+        g_clear_object (&manager->priv->screensaver_settings);
+        g_clear_object (&manager->priv->lockdown_settings);
+        g_clear_object (&manager->priv->system);
+        g_clear_object (&manager->priv->shell);
 
         G_OBJECT_CLASS (gsm_manager_parent_class)->dispose (object);
 }
diff --git a/gnome-session/gsm-shell-extensions.c b/gnome-session/gsm-shell-extensions.c
index 40d46fe..acc0eae 100644
--- a/gnome-session/gsm-shell-extensions.c
+++ b/gnome-session/gsm-shell-extensions.c
@@ -55,11 +55,7 @@ gsm_shell_extensions_finalize (GObject *object)
   GsmShellExtensions *extensions = GSM_SHELL_EXTENSIONS (object);
   GsmShellExtensionsPrivate *priv = extensions->priv;
 
-  if (priv->settings != NULL)
-    {
-      g_object_unref (priv->settings);
-      priv->settings = NULL;
-    }
+  g_clear_object (&priv->settings);
 
   G_OBJECT_CLASS (gsm_shell_extensions_parent_class)->finalize (object);
 }
diff --git a/gnome-session/gsm-shell.c b/gnome-session/gsm-shell.c
index 67d9597..4a5d49a 100644
--- a/gnome-session/gsm-shell.c
+++ b/gnome-session/gsm-shell.c
@@ -319,20 +319,10 @@ gsm_shell_ensure_connection (GsmShell  *shell,
                 g_debug ("GsmShell: Not connected to the shell");
 
                 if (shell->priv->bus_connection == NULL) {
-                        if (shell->priv->bus_proxy != NULL) {
-                                g_object_unref (shell->priv->bus_proxy);
-                                shell->priv->bus_proxy = NULL;
-                        }
-
-                        if (shell->priv->proxy != NULL) {
-                                g_object_unref (shell->priv->proxy);
-                                shell->priv->proxy = NULL;
-                        }
+                        g_clear_object (&shell->priv->bus_proxy);
+                        g_clear_object (&shell->priv->proxy);
                 } else if (shell->priv->bus_proxy == NULL) {
-                        if (shell->priv->proxy != NULL) {
-                                g_object_unref (shell->priv->proxy);
-                                shell->priv->proxy = NULL;
-                        }
+                        g_clear_object (&shell->priv->proxy);
                 }
         }
 
@@ -350,10 +340,7 @@ gsm_shell_on_name_owner_changed (DBusGProxy    *bus_proxy,
                 return;
         }
 
-        if (shell->priv->proxy != NULL) {
-                g_object_unref (shell->priv->proxy);
-                shell->priv->proxy = NULL;
-        }
+        g_clear_object (&shell->priv->proxy);
 
         gsm_shell_ensure_connection (shell, NULL);
 }
@@ -369,15 +356,8 @@ gsm_shell_init (GsmShell *shell)
 static void
 gsm_shell_disconnect_from_bus (GsmShell *shell)
 {
-        if (shell->priv->bus_proxy != NULL) {
-                g_object_unref (shell->priv->bus_proxy);
-                shell->priv->bus_proxy = NULL;
-        }
-
-        if (shell->priv->proxy != NULL) {
-                g_object_unref (shell->priv->proxy);
-                shell->priv->proxy = NULL;
-        }
+        g_clear_object (&shell->priv->bus_proxy);
+        g_clear_object (&shell->priv->proxy);
 
         if (shell->priv->bus_connection != NULL) {
                 DBusConnection *connection;
@@ -568,6 +548,7 @@ static void
 on_end_session_dialog_proxy_destroyed (DBusGProxy *proxy,
                                        GsmShell   *shell)
 {
+        /* FIXME - is this right? */
         if (shell->priv->end_session_dialog_proxy != NULL) {
                 g_object_unref (shell->priv->proxy);
                 shell->priv->end_session_dialog_proxy = NULL;
diff --git a/gnome-session/gsm-util.c b/gnome-session/gsm-util.c
index f5af61d..38844ea 100644
--- a/gnome-session/gsm-util.c
+++ b/gnome-session/gsm-util.c
@@ -544,9 +544,7 @@ gsm_util_update_activation_environment (const char  *variable,
 
  out:
 
-        if (bus_proxy != NULL) {
-                g_object_unref (bus_proxy);
-        }
+        g_clear_object (&bus_proxy);
 
         if (environment != NULL) {
                 g_hash_table_destroy (environment);
diff --git a/gnome-session/main.c b/gnome-session/main.c
index a0f8bb4..2d76b8e 100644
--- a/gnome-session/main.c
+++ b/gnome-session/main.c
@@ -345,22 +345,10 @@ main (int argc, char **argv)
 
         gtk_main ();
 
-        if (xsmp_server != NULL) {
-                g_object_unref (xsmp_server);
-        }
-
-        if (manager != NULL) {
-                g_debug ("Unreffing manager");
-                g_object_unref (manager);
-        }
-
-        if (client_store != NULL) {
-                g_object_unref (client_store);
-        }
-
-        if (bus_proxy != NULL) {
-                g_object_unref (bus_proxy);
-        }
+        g_clear_object (&xsmp_server);
+        g_clear_object (&manager);
+        g_clear_object (&client_store);
+        g_clear_object (&bus_proxy);
 
         gdm_log_shutdown ();
 
diff --git a/tools/gnome-session-quit.c b/tools/gnome-session-quit.c
index 268daec..5b94c74 100644
--- a/tools/gnome-session-quit.c
+++ b/tools/gnome-session-quit.c
@@ -135,9 +135,7 @@ do_logout (unsigned int mode)
                 }
         }
 
-        if (sm_proxy != NULL) {
-                g_object_unref (sm_proxy);
-        }
+        g_clear_object (&sm_proxy);
 }
 
 static void
@@ -169,9 +167,7 @@ do_power_off (const char *action)
                 }
         }
 
-        if (sm_proxy != NULL) {
-                g_object_unref (sm_proxy);
-        }
+        g_clear_object (&sm_proxy);
 }
 
 int



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]