[libadwaita/msvc: 269/271] src: Remove g_auto* usage




commit a6ba762971b99eb636169d1c7fe8837315b5fa06
Author: Chun-wei Fan <fanchunwei src gnome org>
Date:   Mon Jul 26 18:58:32 2021 +0800

    src: 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.

 src/adw-avatar.c                   | 30 +++++++++++++++++++++---------
 src/adw-carousel-indicator-dots.c  |  6 ++++--
 src/adw-carousel-indicator-lines.c | 11 ++++++++---
 src/adw-combo-row.c                |  9 ++++++---
 src/adw-fading-label.c             |  7 +++++--
 src/adw-indicator-bin.c            |  8 ++++++--
 src/adw-preferences-window.c       | 34 ++++++++++++++++++++++------------
 src/adw-swipe-tracker.c            | 15 +++++++++++----
 src/adw-tab-box.c                  |  3 ++-
 src/adw-tab-view.c                 |  4 ++--
 src/adw-tab.c                      |  3 ++-
 src/adw-view-switcher.c            |  6 ++++--
 12 files changed, 93 insertions(+), 43 deletions(-)
---
diff --git a/src/adw-avatar.c b/src/adw-avatar.c
index 34ece640..1b645c05 100644
--- a/src/adw-avatar.c
+++ b/src/adw-avatar.c
@@ -75,13 +75,16 @@ static char *
 extract_initials_from_text (const char *text)
 {
   GString *initials;
-  g_autofree char *p = g_utf8_strup (text, -1);
-  g_autofree char *normalized = g_utf8_normalize (g_strstrip (p), -1, G_NORMALIZE_DEFAULT_COMPOSE);
+  char *p = g_utf8_strup (text, -1);
+  char *normalized = g_utf8_normalize (g_strstrip (p), -1, G_NORMALIZE_DEFAULT_COMPOSE);
   gunichar unichar;
   char *q = NULL;
 
   if (normalized == NULL)
-    return NULL;
+    {
+      g_free (p);
+      return NULL;
+    }
 
   initials = g_string_new ("");
 
@@ -96,6 +99,8 @@ extract_initials_from_text (const char *text)
     g_string_append_unichar (initials, unichar);
   }
 
+  g_free (normalized);
+  g_free (p);
   return g_string_free (initials, FALSE);
 }
 
@@ -113,9 +118,9 @@ update_visibility (AdwAvatar *self)
 static void
 set_class_color (AdwAvatar *self)
 {
-  g_autofree GRand *rand = NULL;
-  g_autofree char *new_class = NULL;
-  g_autofree char *old_class = g_strdup_printf ("color%d", self->color_class);
+  GRand *rand = NULL;
+  char *new_class = NULL;
+  char *old_class = g_strdup_printf ("color%d", self->color_class);
 
   gtk_widget_remove_css_class (self->gizmo, old_class);
 
@@ -123,6 +128,7 @@ set_class_color (AdwAvatar *self)
     /* Use a random color if we don't have a text */
     rand = g_rand_new ();
     self->color_class = g_rand_int_range (rand, 1, NUMBER_OF_COLORS);
+    g_rand_free (rand);
   } else {
     self->color_class = (g_str_hash (self->text) % NUMBER_OF_COLORS) + 1;
   }
@@ -130,12 +136,14 @@ set_class_color (AdwAvatar *self)
   new_class = g_strdup_printf ("color%d", self->color_class);
 
   gtk_widget_add_css_class (self->gizmo, new_class);
+  g_free (new_class);
+  g_free (old_class);
 }
 
 static void
 update_initials (AdwAvatar *self)
 {
-  g_autofree char *initials = NULL;
+  char *initials = NULL;
 
   if (gtk_image_get_paintable (self->custom_image) != NULL ||
       !self->show_initials ||
@@ -146,6 +154,7 @@ update_initials (AdwAvatar *self)
   initials = extract_initials_from_text (self->text);
 
   gtk_label_set_label (self->label, initials);
+  g_free (initials);
 }
 
 static void
@@ -696,7 +705,8 @@ GdkTexture *
 adw_avatar_draw_to_texture (AdwAvatar *self,
                             int        scale_factor)
 {
-  g_autoptr (GskRenderNode) node = NULL;
+  GdkTexture *result = NULL;
+  GskRenderNode *node = NULL;
   GtkSnapshot *snapshot;
   GtkNative *native;
   GskRenderer *renderer;
@@ -716,5 +726,7 @@ adw_avatar_draw_to_texture (AdwAvatar *self,
   native = gtk_widget_get_native (GTK_WIDGET (self));
   renderer = gtk_native_get_renderer (native);
 
-  return gsk_renderer_render_texture (renderer, node, &GRAPHENE_RECT_INIT (0, 0, size, size));
+  result = gsk_renderer_render_texture (renderer, node, &GRAPHENE_RECT_INIT (0, 0, size, size));
+  gsk_render_node_unref (node);
+  return result;
 }
diff --git a/src/adw-carousel-indicator-dots.c b/src/adw-carousel-indicator-dots.c
index 99d1e085..bfb49e48 100644
--- a/src/adw-carousel-indicator-dots.c
+++ b/src/adw-carousel-indicator-dots.c
@@ -244,8 +244,8 @@ adw_carousel_indicator_dots_snapshot (GtkWidget   *widget,
   AdwCarouselIndicatorDots *self = ADW_CAROUSEL_INDICATOR_DOTS (widget);
   int i, n_points;
   double position;
-  g_autofree double *points = NULL;
-  g_autofree double *sizes = NULL;
+  double *points = NULL;
+  double *sizes = NULL;
 
   if (!self->carousel)
     return;
@@ -267,6 +267,8 @@ adw_carousel_indicator_dots_snapshot (GtkWidget   *widget,
     sizes[i] = points[i] - points[i - 1];
 
   snapshot_dots (widget, snapshot, self->orientation, position, sizes, n_points);
+  g_free (sizes);
+  g_free (points);
 }
 
 static void
diff --git a/src/adw-carousel-indicator-lines.c b/src/adw-carousel-indicator-lines.c
index 5095768e..3dd5ac90 100644
--- a/src/adw-carousel-indicator-lines.c
+++ b/src/adw-carousel-indicator-lines.c
@@ -229,8 +229,8 @@ adw_carousel_indicator_lines_snapshot (GtkWidget   *widget,
   AdwCarouselIndicatorLines *self = ADW_CAROUSEL_INDICATOR_LINES (widget);
   int i, n_points;
   double position;
-  g_autofree double *points = NULL;
-  g_autofree double *sizes = NULL;
+  double *points = NULL;
+  double *sizes = NULL;
 
   if (!self->carousel)
     return;
@@ -239,7 +239,10 @@ adw_carousel_indicator_lines_snapshot (GtkWidget   *widget,
   position = adw_carousel_get_position (self->carousel);
 
   if (n_points < 2)
-    return;
+    {
+      g_free (points);
+      return;
+    }    
 
   if (self->orientation == GTK_ORIENTATION_HORIZONTAL &&
       gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
@@ -252,6 +255,8 @@ adw_carousel_indicator_lines_snapshot (GtkWidget   *widget,
     sizes[i] = points[i] - points[i - 1];
 
   snapshot_lines (widget, snapshot, self->orientation, position, sizes, n_points);
+  g_free (sizes);
+  g_free (points);
 }
 
 static void
diff --git a/src/adw-combo-row.c b/src/adw-combo-row.c
index 4bd31bb6..d950f416 100644
--- a/src/adw-combo-row.c
+++ b/src/adw-combo-row.c
@@ -114,10 +114,12 @@ selection_changed (AdwComboRow *self)
 
   if (priv->use_subtitle) {
     if (g_list_model_get_n_items (G_LIST_MODEL (priv->current_selection)) > 0) {
-      g_autoptr (GtkListItem) item = g_list_model_get_item (G_LIST_MODEL (priv->current_selection), 0);
-      g_autofree char *repr = get_item_representation (self, item);
+      GtkListItem *item = g_list_model_get_item (G_LIST_MODEL (priv->current_selection), 0);
+      char *repr = get_item_representation (self, item);
 
       adw_action_row_set_subtitle (ADW_ACTION_ROW (self), repr);
+      g_free (repr);
+      g_object_unref (item);
     } else {
       adw_action_row_set_subtitle (ADW_ACTION_ROW (self), NULL);
     }
@@ -211,7 +213,7 @@ bind_item (GtkSignalListItemFactory *factory,
   gpointer item;
   GtkWidget *box;
   GtkWidget *icon;
-  g_autofree char *repr = NULL;
+  char *repr = NULL;
 
   item = gtk_list_item_get_item (list_item);
   box = gtk_list_item_get_child (list_item);
@@ -223,6 +225,7 @@ bind_item (GtkSignalListItemFactory *factory,
     GtkWidget *label = gtk_widget_get_first_child (box);
 
     gtk_label_set_label (GTK_LABEL (label), repr);
+    g_free (repr);
   } else {
     g_critical ("Either AdwComboRow:factory or AdwComboRow:expression must be set");
   }
diff --git a/src/adw-fading-label.c b/src/adw-fading-label.c
index f903ac46..f1408335 100644
--- a/src/adw-fading-label.c
+++ b/src/adw-fading-label.c
@@ -59,7 +59,7 @@ ensure_shader (AdwFadingLabel *self)
 {
   GtkNative *native;
   GskRenderer *renderer;
-  g_autoptr (GError) error = NULL;
+  GError *error = NULL;
 
   if (self->shader)
     return;
@@ -76,6 +76,8 @@ ensure_shader (AdwFadingLabel *self)
      * silently fall back */
     if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED))
       g_critical ("Couldn't compile shader: %s\n", error->message);
+
+    g_clear_error (&error);
   }
 }
 
@@ -127,7 +129,7 @@ adw_fading_label_snapshot (GtkWidget   *widget,
   int width = gtk_widget_get_width (widget);
   int clipped_size;
   GtkSnapshot *child_snapshot;
-  g_autoptr (GskRenderNode) node = NULL;
+  GskRenderNode *node = NULL;
   graphene_rect_t bounds;
 
   if (width <= 0)
@@ -169,6 +171,7 @@ adw_fading_label_snapshot (GtkWidget   *widget,
     gtk_snapshot_gl_shader_pop_texture (snapshot);
 
   gtk_snapshot_pop (snapshot);
+  gsk_render_node_unref (node);
 }
 
 static void
diff --git a/src/adw-indicator-bin.c b/src/adw-indicator-bin.c
index 3e60d67e..98b9dc08 100644
--- a/src/adw-indicator-bin.c
+++ b/src/adw-indicator-bin.c
@@ -61,7 +61,7 @@ ensure_shader (AdwIndicatorBin *self)
 {
   GtkNative *native;
   GskRenderer *renderer;
-  g_autoptr (GError) error = NULL;
+  GError *error = NULL;
 
   if (self->shader)
     return;
@@ -78,6 +78,8 @@ ensure_shader (AdwIndicatorBin *self)
      * silently fall back */
     if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED))
       g_critical ("Couldn't compile shader: %s\n", error->message);
+
+    g_clear_error (&error);
   }
 }
 
@@ -162,7 +164,7 @@ adw_indicator_bin_snapshot (GtkWidget   *widget,
 
   if (self->child) {
     GtkSnapshot *child_snapshot;
-    g_autoptr (GskRenderNode) child_node = NULL;
+    GskRenderNode *child_node = NULL;
 
     child_snapshot = gtk_snapshot_new ();
     gtk_widget_snapshot_child (widget, self->child, child_snapshot);
@@ -188,6 +190,8 @@ adw_indicator_bin_snapshot (GtkWidget   *widget,
 
       gtk_snapshot_pop (snapshot);
     }
+
+    gsk_render_node_unref (child_node);
   }
 
   gtk_widget_snapshot_child (widget, self->indicator, snapshot);
diff --git a/src/adw-preferences-window.c b/src/adw-preferences-window.c
index d68502de..df3e6b4e 100644
--- a/src/adw-preferences-window.c
+++ b/src/adw-preferences-window.c
@@ -82,8 +82,9 @@ static GParamSpec *props[LAST_PROP];
 static char *
 strip_mnemonic (const char *src)
 {
-  g_autofree char *new_str = g_new (char, strlen (src) + 1);
+  char *new_str = g_new (char, strlen (src) + 1);
   char *dest = new_str;
+  char *result = NULL;
   gboolean underscore = FALSE;
 
   while (*src) {
@@ -94,6 +95,7 @@ strip_mnemonic (const char *src)
     if (c == (gunichar) -1) {
       g_warning ("Invalid input string");
 
+      g_free (new_str);
       return NULL;
     }
 
@@ -125,8 +127,9 @@ filter_search_results (AdwPreferencesRow    *row,
                        AdwPreferencesWindow *self)
 {
   AdwPreferencesWindowPrivate *priv = adw_preferences_window_get_instance_private (self);
-  g_autofree char *terms = NULL;
-  g_autofree char *title = NULL;
+  char *terms = NULL;
+  char *title = NULL;
+  gboolean result = FALSE;
 
   g_assert (ADW_IS_PREFERENCES_ROW (row));
 
@@ -143,16 +146,20 @@ filter_search_results (AdwPreferencesRow    *row,
   }
 
   if (!!strstr (title, terms))
-    return TRUE;
+    result = TRUE;
 
-  if (ADW_IS_ACTION_ROW (row)) {
-    g_autofree char *subtitle = g_utf8_casefold (adw_action_row_get_subtitle (ADW_ACTION_ROW (row)), -1);
+  else if (ADW_IS_ACTION_ROW (row)) {
+    char *subtitle = g_utf8_casefold (adw_action_row_get_subtitle (ADW_ACTION_ROW (row)), -1);
 
     if (!!strstr (subtitle, terms))
-      return TRUE;
+      result = TRUE;
+
+    g_free (subtitle);
   }
 
-  return FALSE;
+  g_free (title);
+  g_free (terms);
+  return result;
 }
 
 static int
@@ -180,7 +187,8 @@ create_search_row_subtitle (AdwPreferencesWindow *self,
 {
   GtkWidget *group, *page;
   const char *group_title = NULL;
-  g_autofree char *page_title = NULL;
+  char *page_title = NULL;
+  gchar *result = NULL;
 
   group = gtk_widget_get_ancestor (row, ADW_TYPE_PREFERENCES_GROUP);
 
@@ -213,9 +221,10 @@ create_search_row_subtitle (AdwPreferencesWindow *self,
   }
 
   if (page_title)
-    return g_steal_pointer (&page_title);
+    result = g_steal_pointer (&page_title);
 
-  return NULL;
+  g_free (page_title);
+  return result;
 }
 
 static GtkWidget *
@@ -224,7 +233,7 @@ new_search_row_for_preference (AdwPreferencesRow    *row,
 {
   AdwActionRow *widget;
   GtkWidget *page;
-  g_autofree char *subtitle = NULL;
+  char *subtitle = NULL;
 
   g_assert (ADW_IS_PREFERENCES_ROW (row));
 
@@ -236,6 +245,7 @@ new_search_row_for_preference (AdwPreferencesRow    *row,
   g_object_bind_property (row, "title", widget, "title", G_BINDING_SYNC_CREATE);
   g_object_bind_property (row, "use-underline", widget, "use-underline", G_BINDING_SYNC_CREATE);
   adw_action_row_set_subtitle (widget, subtitle);
+  g_free (subtitle);
 
   g_object_set_data (G_OBJECT (widget), "page", page);
   g_object_set_data (G_OBJECT (widget), "row", row);
diff --git a/src/adw-swipe-tracker.c b/src/adw-swipe-tracker.c
index 418f49cd..55056f8e 100644
--- a/src/adw-swipe-tracker.c
+++ b/src/adw-swipe-tracker.c
@@ -137,13 +137,14 @@ get_range (AdwSwipeTracker *self,
            double          *first,
            double          *last)
 {
-  g_autofree double *points = NULL;
+  double *points = NULL;
   int n;
 
   points = adw_swipeable_get_snap_points (self->swipeable, &n);
 
   *first = points[0];
   *last = points[n - 1];
+  g_free (points);
 }
 
 static void
@@ -321,11 +322,12 @@ gesture_update (AdwSwipeTracker *self,
     return;
 
   if (!self->allow_long_swipes) {
-    g_autofree double *points = NULL;
+    double *points = NULL;
     int n;
 
     points = adw_swipeable_get_snap_points (self->swipeable, &n);
     get_bounds (self, points, n, self->initial_progress, &lower, &upper);
+    g_free (points);
   } else {
     get_range (self, &lower, &upper);
   }
@@ -344,7 +346,7 @@ get_end_progress (AdwSwipeTracker *self,
                   gboolean         is_touchpad)
 {
   double pos, decel, slope;
-  g_autofree double *points = NULL;
+  double *points = NULL;
   int n;
   double lower, upper;
 
@@ -354,7 +356,11 @@ get_end_progress (AdwSwipeTracker *self,
   points = adw_swipeable_get_snap_points (self->swipeable, &n);
 
   if (ABS (velocity) < (is_touchpad ? VELOCITY_THRESHOLD_TOUCHPAD : VELOCITY_THRESHOLD_TOUCH))
-    return points[find_closest_point (points, n, self->progress)];
+    {
+      pos = points[find_closest_point (points, n, self->progress)];
+      g_free (points);
+      return pos;
+    }
 
   decel = is_touchpad ? DECELERATION_TOUCHPAD : DECELERATION_TOUCH;
   slope = decel / (1.0 - decel) / 1000.0;
@@ -382,6 +388,7 @@ get_end_progress (AdwSwipeTracker *self,
   pos = CLAMP (pos, lower, upper);
   pos = points[find_point_for_projection (self, points, n, pos, velocity)];
 
+  g_free (points);
   return pos;
 }
 
diff --git a/src/adw-tab-box.c b/src/adw-tab-box.c
index af6fc84f..37f413b7 100644
--- a/src/adw-tab-box.c
+++ b/src/adw-tab-box.c
@@ -1825,7 +1825,7 @@ adw_tab_box_root_content_write_mime_type_async (GdkContentProvider  *provider,
                                                 gpointer             user_data)
 {
   AdwTabBoxRootContent *self = ADW_TAB_BOX_ROOT_CONTENT (provider);
-  g_autoptr (GTask) task = NULL;
+  GTask *task = NULL;
 
   self->tab_box->should_detach_into_new_window = TRUE;
 
@@ -1833,6 +1833,7 @@ adw_tab_box_root_content_write_mime_type_async (GdkContentProvider  *provider,
   g_task_set_priority (task, io_priority);
   g_task_set_source_tag (task, adw_tab_box_root_content_write_mime_type_async);
   g_task_return_boolean (task, TRUE);
+  g_object_unref (task);
 }
 
 static gboolean
diff --git a/src/adw-tab-view.c b/src/adw-tab-view.c
index fd781986..1ce92e9e 100644
--- a/src/adw-tab-view.c
+++ b/src/adw-tab-view.c
@@ -922,7 +922,7 @@ insert_page (AdwTabView *self,
              int         position,
              gboolean    pinned)
 {
-  g_autoptr (AdwTabPage) page =
+  AdwTabPage *page =
     g_object_new (ADW_TYPE_TAB_PAGE,
                   "child", child,
                   "parent", parent,
@@ -2654,7 +2654,7 @@ AdwTabPage *
 adw_tab_view_get_nth_page (AdwTabView *self,
                            int         position)
 {
-  g_autoptr (AdwTabPage) page = NULL;
+  AdwTabPage *page = NULL;
 
   g_return_val_if_fail (ADW_IS_TAB_VIEW (self), NULL);
   g_return_val_if_fail (position >= 0, NULL);
diff --git a/src/adw-tab.c b/src/adw-tab.c
index c295c3b5..cdf86c35 100644
--- a/src/adw-tab.c
+++ b/src/adw-tab.c
@@ -323,7 +323,7 @@ ensure_shader (AdwTab *self)
 {
   GtkNative *native;
   GskRenderer *renderer;
-  g_autoptr (GError) error = NULL;
+  GError *error = NULL;
 
   if (self->shader)
     return;
@@ -340,6 +340,7 @@ ensure_shader (AdwTab *self)
      * silently fall back */
     if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED))
       g_critical ("Couldn't compile shader: %s\n", error->message);
+    g_clear_error (&error);
   }
 }
 
diff --git a/src/adw-view-switcher.c b/src/adw-view-switcher.c
index 8170a328..a07b5ea2 100644
--- a/src/adw-view-switcher.c
+++ b/src/adw-view-switcher.c
@@ -94,8 +94,8 @@ update_button (AdwViewSwitcher  *self,
                AdwViewStackPage *page,
                GtkWidget        *button)
 {
-  g_autofree char *title = NULL;
-  g_autofree char *icon_name = NULL;
+  char *title = NULL;
+  char *icon_name = NULL;
   gboolean needs_attention;
   guint badge_number;
   gboolean visible;
@@ -119,6 +119,8 @@ update_button (AdwViewSwitcher  *self,
                 NULL);
 
   gtk_widget_set_visible (button, visible && (title != NULL || icon_name != NULL));
+  g_free (title);
+  g_free (icon_name);
 }
 
 static void


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