[libadwaita/msvc: 13/20] examples: Remove g_auto* usage




commit de9f93dceb6b316931f97126a7b381622115d583
Author: Chun-wei Fan <fanchunwei src gnome org>
Date:   Mon Jul 26 19:00:25 2021 +0800

    examples: Remove g_auto* usage
    
    It is unfortunately a GCCism, so use the traditional method instead.
    Unfortunately the autocleanup compiler extensions are not standard across the
    board.

 demo/adwaita-demo.c                              |  3 +-
 demo/pages/animations/adw-demo-page-animations.c |  3 +-
 demo/pages/avatar/adw-demo-page-avatar.c         | 35 +++++++++++++++++-------
 demo/pages/tab-view/adw-tab-view-demo-window.c   | 17 ++++++++----
 demo/pages/toasts/adw-demo-page-toasts.c         |  7 +++--
 examples/hello-world/hello.c                     |  8 ++++--
 6 files changed, 52 insertions(+), 21 deletions(-)
---
diff --git a/demo/adwaita-demo.c b/demo/adwaita-demo.c
index e00ca110..df9f693e 100644
--- a/demo/adwaita-demo.c
+++ b/demo/adwaita-demo.c
@@ -49,7 +49,7 @@ show_about (GSimpleAction *action,
 
   GtkApplication *app = GTK_APPLICATION (user_data);
   GtkWindow *window = gtk_application_get_active_window (app);
-  g_autofree char *version = NULL;
+  char *version = NULL;
 
   version = g_strdup_printf ("%s\nRunning against libadwaita %d.%d.%d, GTK %d.%d.%d",
                              ADW_VERSION_S,
@@ -73,6 +73,7 @@ show_about (GSimpleAction *action,
                          "artists", artists,
                          "translator-credits", _("translator-credits"),
                          NULL);
+  g_free (version);
 }
 
 static void
diff --git a/demo/pages/animations/adw-demo-page-animations.c 
b/demo/pages/animations/adw-demo-page-animations.c
index 62476053..db85d3b6 100644
--- a/demo/pages/animations/adw-demo-page-animations.c
+++ b/demo/pages/animations/adw-demo-page-animations.c
@@ -242,12 +242,13 @@ timed_animation_cb (double     value,
 static void
 notify_spring_params_change (AdwDemoPageAnimations *self)
 {
-  g_autoptr (AdwSpringParams) spring_params =
+  AdwSpringParams *spring_params =
     adw_spring_params_new_full (gtk_spin_button_get_value (self->spring_animation_damping),
                                 gtk_spin_button_get_value (self->spring_animation_mass),
                                 gtk_spin_button_get_value (self->spring_animation_stiffness));
 
   adw_spring_animation_set_spring_params (ADW_SPRING_ANIMATION (self->spring_animation), spring_params);
+  adw_spring_params_unref (spring_params);
 }
 
 static void
diff --git a/demo/pages/avatar/adw-demo-page-avatar.c b/demo/pages/avatar/adw-demo-page-avatar.c
index 05ad55c6..39efb2d3 100644
--- a/demo/pages/avatar/adw-demo-page-avatar.c
+++ b/demo/pages/avatar/adw-demo-page-avatar.c
@@ -68,7 +68,7 @@ static void
 populate_contacts (AdwDemoPageAvatar *self)
 {
   for (int i = 0; i < 30; i++) {
-    g_autofree char *name = create_random_name ();
+    char *name = create_random_name ();
     GtkWidget *contact = adw_action_row_new ();
     GtkWidget *avatar = adw_avatar_new (40, name, TRUE);
 
@@ -78,6 +78,7 @@ populate_contacts (AdwDemoPageAvatar *self)
     adw_preferences_row_set_title (ADW_PREFERENCES_ROW (contact), name);
     adw_action_row_add_prefix (ADW_ACTION_ROW (contact), avatar);
     gtk_list_box_append (self->contacts, contact);
+    g_free (name);
   }
 }
 
@@ -87,10 +88,10 @@ open_response_cb (AdwDemoPageAvatar *self,
                   GtkFileChooser    *chooser)
 {
   if (response == GTK_RESPONSE_ACCEPT) {
-    g_autoptr (GFile) file = gtk_file_chooser_get_file (chooser);
-    g_autoptr (GFileInfo) info = NULL;
-    g_autoptr (GdkTexture) texture = NULL;
-    g_autoptr (GError) error = NULL;
+    GFile *file = gtk_file_chooser_get_file (chooser);
+    GFileInfo *info = NULL;
+    GdkTexture *texture = NULL;
+    GError *error = NULL;
 
     info = g_file_query_info (file,
                               G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME,
@@ -99,8 +100,12 @@ open_response_cb (AdwDemoPageAvatar *self,
                               NULL);
 
     if (info)
-      gtk_label_set_label (self->file_chooser_label,
-                           g_file_info_get_display_name (info));
+      {
+        gtk_label_set_label (self->file_chooser_label,
+                             g_file_info_get_display_name (info));
+
+        g_object_unref (info);
+      }
 
     gtk_widget_action_set_enabled (GTK_WIDGET (self), "avatar.remove", TRUE);
 
@@ -108,7 +113,12 @@ open_response_cb (AdwDemoPageAvatar *self,
     if (error)
       g_critical ("Failed to create texture from file: %s", error->message);
 
+    g_clear_error (&error);
+
     adw_avatar_set_custom_image (self->avatar, texture ? GDK_PAINTABLE (texture) : NULL);
+
+    g_object_unref (texture);
+    g_object_unref (file);
   }
 
   gtk_native_dialog_destroy (GTK_NATIVE_DIALOG (chooser));
@@ -145,12 +155,15 @@ save_response_cb (AdwDemoPageAvatar *self,
                   GtkFileChooser    *chooser)
 {
   if (response == GTK_RESPONSE_ACCEPT) {
-    g_autoptr (GFile) file = gtk_file_chooser_get_file (chooser);
-    g_autoptr (GdkTexture) texture =
+    GFile *file = gtk_file_chooser_get_file (chooser);
+    GdkTexture *texture =
       adw_avatar_draw_to_texture (self->avatar,
                                   gtk_widget_get_scale_factor (GTK_WIDGET (self)));
 
     gdk_texture_save_to_png (texture, g_file_peek_path (file));
+
+    g_object_unref (texture);
+    g_object_unref (file);
   }
 
   gtk_native_dialog_destroy (GTK_NATIVE_DIALOG (chooser));
@@ -192,7 +205,7 @@ adw_demo_page_avatar_class_init (AdwDemoPageAvatarClass *klass)
 static void
 adw_demo_page_avatar_init (AdwDemoPageAvatar *self)
 {
-  g_autofree char *name = NULL;
+  char *name = NULL;
 
   gtk_widget_init_template (GTK_WIDGET (self));
 
@@ -201,4 +214,6 @@ adw_demo_page_avatar_init (AdwDemoPageAvatar *self)
 
   populate_contacts (self);
   avatar_remove_cb (self);
+
+  g_free (name);
 }
diff --git a/demo/pages/tab-view/adw-tab-view-demo-window.c b/demo/pages/tab-view/adw-tab-view-demo-window.c
index cda44c92..807e49d4 100644
--- a/demo/pages/tab-view/adw-tab-view-demo-window.c
+++ b/demo/pages/tab-view/adw-tab-view-demo-window.c
@@ -106,7 +106,7 @@ tab_new (GSimpleAction *action,
          gpointer       user_data)
 {
   AdwTabViewDemoWindow *self = ADW_TAB_VIEW_DEMO_WINDOW (user_data);
-  g_autofree char *title = NULL;
+  char *title = NULL;
   AdwTabPage *page;
   GtkWidget *content;
   GIcon *icon;
@@ -116,6 +116,7 @@ tab_new (GSimpleAction *action,
   icon = get_random_icon (self);
 
   page = add_page (self, NULL, title, icon);
+  g_free (title);
   content = adw_tab_page_get_child (page);
 
   adw_tab_view_set_selected_page (self->view, page);
@@ -256,13 +257,15 @@ tab_change_indicator (GSimpleAction *action,
 {
   AdwTabViewDemoWindow *self = ADW_TAB_VIEW_DEMO_WINDOW (user_data);
   gboolean indicator = g_variant_get_boolean (parameter);
-  g_autoptr (GIcon) icon = NULL;
+  GIcon *icon = NULL;
 
   if (indicator)
     icon = get_indicator_icon (get_current_page (self));
 
   adw_tab_page_set_indicator_icon (get_current_page (self), icon);
   g_simple_action_set_state (action, g_variant_new_boolean (indicator));
+
+  g_object_unref (icon);
 }
 
 static void
@@ -274,9 +277,11 @@ tab_change_icon (GSimpleAction *action,
   gboolean enable_icon = g_variant_get_boolean (parameter);
 
   if (enable_icon) {
-    g_autoptr (GIcon) icon = get_random_icon (self);
+    GIcon *icon = get_random_icon (self);
 
     adw_tab_page_set_icon (get_current_page (self), icon);
+
+    g_object_unref (icon);
   } else {
     adw_tab_page_set_icon (get_current_page (self), NULL);
   }
@@ -290,9 +295,11 @@ tab_refresh_icon (GSimpleAction *action,
                   gpointer       user_data)
 {
   AdwTabViewDemoWindow *self = ADW_TAB_VIEW_DEMO_WINDOW (user_data);
-  g_autoptr (GIcon) icon = get_random_icon (self);
+  GIcon * icon = get_random_icon (self);
 
   adw_tab_page_set_icon (get_current_page (self), icon);
+
+  g_object_unref (icon);
 }
 
 static void
@@ -436,7 +443,7 @@ static void
 indicator_activated_cb (AdwTabViewDemoWindow *self,
                         AdwTabPage           *page)
 {
-  g_autoptr (GIcon) icon = NULL;
+  GIcon *icon = NULL;
   gboolean muted;
 
   muted = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (page),
diff --git a/demo/pages/toasts/adw-demo-page-toasts.c b/demo/pages/toasts/adw-demo-page-toasts.c
index 4b679104..54137bac 100644
--- a/demo/pages/toasts/adw-demo-page-toasts.c
+++ b/demo/pages/toasts/adw-demo-page-toasts.c
@@ -44,7 +44,7 @@ toast_add_cb (AdwDemoPageToasts *self)
 static void
 toast_add_with_button_cb (AdwDemoPageToasts *self)
 {
-  g_autofree char *title = NULL;
+  char *title = NULL;
 
   self->toast_undo_items++;
 
@@ -62,6 +62,7 @@ toast_add_with_button_cb (AdwDemoPageToasts *self)
     add_toast (self, self->undo_toast);
 
     gtk_widget_action_set_enabled (GTK_WIDGET (self), "toast.dismiss", TRUE);
+    g_free (title);
 
     return;
   }
@@ -72,6 +73,7 @@ toast_add_with_button_cb (AdwDemoPageToasts *self)
                                self->toast_undo_items), self->toast_undo_items);
 
   adw_toast_set_title (self->undo_toast, title);
+  g_free (title);
 }
 
 static void
@@ -124,7 +126,7 @@ adw_demo_page_toasts_init (AdwDemoPageToasts *self)
 void
 adw_demo_page_toasts_undo (AdwDemoPageToasts *self)
 {
-  g_autofree char *title =
+  char *title =
     g_strdup_printf (ngettext ("Undoing deleting <span font_features='tnum=1'>%d</span> item…",
                                "Undoing deleting <span font_features='tnum=1'>%d</span> items…",
                                self->toast_undo_items), self->toast_undo_items);
@@ -133,4 +135,5 @@ adw_demo_page_toasts_undo (AdwDemoPageToasts *self)
   adw_toast_set_priority (toast, ADW_TOAST_PRIORITY_HIGH);
 
   add_toast (self, toast);
+  g_free (title);
 }
diff --git a/examples/hello-world/hello.c b/examples/hello-world/hello.c
index 7a1409e8..e6b2e70d 100644
--- a/examples/hello-world/hello.c
+++ b/examples/hello-world/hello.c
@@ -16,11 +16,15 @@ int
 main (int   argc,
       char *argv[])
 {
-  g_autoptr (AdwApplication) app = NULL;
+  AdwApplication *app = NULL;
+  int result;
 
   app = adw_application_new ("org.example.Hello", G_APPLICATION_FLAGS_NONE);
 
   g_signal_connect (app, "activate", G_CALLBACK (activate_cb), NULL);
 
-  return g_application_run (G_APPLICATION (app), argc, argv);
+  result = g_application_run (G_APPLICATION (app), argc, argv);
+
+  g_object_unref (app);
+  return result;
 }


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