[libadwaita/msvc: 86/88] examples: Remove g_auto* usage
- From: Chun-wei Fan <fanchunwei src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libadwaita/msvc: 86/88] examples: Remove g_auto* usage
- Date: Fri, 29 Oct 2021 09:53:03 +0000 (UTC)
commit 3a024673dc2b8ce34aa7439041c0b128bf983328
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 | 34 ++++++++++++++++++++++++----------
demo/adw-tab-view-demo-window.c | 17 ++++++++++++-----
demo/adwaita-demo.c | 3 ++-
3 files changed, 38 insertions(+), 16 deletions(-)
---
diff --git a/demo/adw-demo-window.c b/demo/adw-demo-window.c
index 049e77be..843b498e 100644
--- a/demo/adw-demo-window.c
+++ b/demo/adw-demo-window.c
@@ -224,10 +224,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));
@@ -249,9 +249,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
@@ -266,14 +273,18 @@ 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)));
- g_autofree char *path = g_file_get_path (file);
+ char *path = g_file_get_path (file);
gdk_texture_save_to_png (texture, path);
+
+ g_free (path);
+ g_object_unref (texture);
+ g_object_unref (file);
}
g_object_unref (chooser);
@@ -356,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);
@@ -366,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);
}
}
@@ -448,7 +460,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);
@@ -467,6 +479,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 250e26c3..a921ae4f 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;
+ char *version;
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]