[libadwaita/msvc: 14/17] examples: Remove g_auto* usage




commit 3ee40f1c9c8f0cdf99ccfa8620bd74e09d24a1c8
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/adw-demo-window.c          | 39 ++++++++++++++++++++++++++++-----------
 demo/adw-tab-view-demo-window.c | 17 ++++++++++++-----
 demo/adwaita-demo.c             |  3 ++-
 3 files changed, 42 insertions(+), 17 deletions(-)
---
diff --git a/demo/adw-demo-window.c b/demo/adw-demo-window.c
index 44205045..59867238 100644
--- a/demo/adw-demo-window.c
+++ b/demo/adw-demo-window.c
@@ -227,10 +227,10 @@ static void
 avatar_file_chooser_response_cb (AdwDemoWindow *self,
                                  int            response)
 {
-  g_autoptr (GFile) file = NULL;
-  g_autoptr (GFileInfo) info = NULL;
-  g_autoptr (GdkTexture) texture = NULL;
-  g_autoptr (GError) error = NULL;
+  GFile *file = NULL;
+  GFileInfo *info = NULL;
+  GdkTexture *texture = NULL;
+  GError *error = NULL;
 
   g_assert (ADW_IS_DEMO_WINDOW (self));
 
@@ -252,9 +252,16 @@ avatar_file_chooser_response_cb (AdwDemoWindow *self,
 
   texture = gdk_texture_new_from_file (file, &error);
   if (error)
-    g_critical ("Failed to create texture from file: %s", error->message);
+    {
+      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 (info);
+  g_object_unref (file);
 }
 
 static void
@@ -269,12 +276,15 @@ file_chooser_response_cb (AdwDemoWindow  *self,
                           GtkFileChooser *chooser)
 {
   if (response_id == GTK_RESPONSE_ACCEPT) {
-    g_autoptr (GFile) file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (chooser));
-    g_autoptr (GdkTexture) texture =
+    GFile *file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (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);
   }
 
   g_object_unref (chooser);
@@ -357,7 +367,7 @@ avatar_update_contacts (AdwDemoWindow *self)
     gtk_list_box_remove (self->avatar_contacts, row);
 
   for (int i = 0; i < 30; i++) {
-    g_autofree char *name = avatar_new_random_name ();
+    char *name = avatar_new_random_name ();
     GtkWidget *contact = adw_action_row_new ();
     GtkWidget *avatar = adw_avatar_new (40, name, TRUE);
 
@@ -367,6 +377,7 @@ avatar_update_contacts (AdwDemoWindow *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->avatar_contacts, contact);
+    g_free (name);
   }
 }
 
@@ -420,7 +431,7 @@ dismissed_cb (AdwDemoWindow *self)
 static void
 add_toast_with_button_cb (AdwDemoWindow *self)
 {
-  g_autofree char *title = NULL;
+  char *title = NULL;
 
   self->toast_undo_items++;
 
@@ -448,6 +459,8 @@ add_toast_with_button_cb (AdwDemoWindow *self)
                                self->toast_undo_items), self->toast_undo_items);
 
   adw_toast_set_title (self->undo_toast, title);
+
+  g_free (title);
 }
 
 static void
@@ -464,7 +477,7 @@ add_toast_with_long_title_cb (AdwDemoWindow *self)
 static void
 toast_undo_cb (AdwDemoWindow *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);
@@ -473,6 +486,8 @@ toast_undo_cb (AdwDemoWindow *self)
   adw_toast_set_priority (toast, ADW_TOAST_PRIORITY_HIGH);
 
   adw_toast_overlay_add_toast (self->toast_overlay, toast);
+
+  g_free (title);
 }
 
 static void
@@ -537,7 +552,7 @@ adw_demo_window_class_init (AdwDemoWindowClass *klass)
 static void
 avatar_page_init (AdwDemoWindow *self)
 {
-  g_autofree char *name = avatar_new_random_name ();
+  char *name = avatar_new_random_name ();
 
   gtk_editable_set_text (GTK_EDITABLE (self->avatar_text), name);
 
@@ -556,6 +571,8 @@ avatar_page_init (AdwDemoWindow *self)
                            G_CONNECT_SWAPPED);
 
   avatar_file_remove_cb (self);
+
+  g_free (name);
 }
 
 static void
diff --git a/demo/adw-tab-view-demo-window.c b/demo/adw-tab-view-demo-window.c
index ff05e764..8908c885 100644
--- a/demo/adw-tab-view-demo-window.c
+++ b/demo/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/adwaita-demo.c b/demo/adwaita-demo.c
index ec7e1683..cce0d93e 100644
--- a/demo/adwaita-demo.c
+++ b/demo/adwaita-demo.c
@@ -48,7 +48,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,
@@ -72,6 +72,7 @@ show_about (GSimpleAction *action,
                          "artists", artists,
                          "translator-credits", _("translator-credits"),
                          NULL);
+  g_free (version);
 }
 
 static void


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