[libadwaita/msvc: 4/6] src: Remove g_auto* usage
- From: Chun-wei Fan <fanchunwei src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libadwaita/msvc: 4/6] src: Remove g_auto* usage
- Date: Mon, 26 Jul 2021 11:03:52 +0000 (UTC)
commit b1dc9cf10a168ed901993937e008a2a69e7b0a2f
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 | 41 ++++++++++++++++++++++++++------------
src/adw-carousel-indicator-dots.c | 6 ++++--
src/adw-carousel-indicator-lines.c | 11 +++++++---
src/adw-combo-row.c | 6 ++++--
src/adw-fading-label.c | 7 +++++--
src/adw-indicator-bin.c | 8 ++++++--
src/adw-main.c | 6 ++++--
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-value-object.c | 34 +++++++++++++++++++++----------
src/adw-view-switcher.c | 6 ++++--
14 files changed, 126 insertions(+), 58 deletions(-)
---
diff --git a/src/adw-avatar.c b/src/adw-avatar.c
index cad88ae2..0a72ae06 100644
--- a/src/adw-avatar.c
+++ b/src/adw-avatar.c
@@ -78,13 +78,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 ("");
@@ -99,6 +102,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);
}
@@ -116,9 +121,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);
@@ -126,6 +131,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;
}
@@ -133,12 +139,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 ||
@@ -149,6 +157,7 @@ update_initials (AdwAvatar *self)
initials = extract_initials_from_text (self->text);
gtk_label_set_label (self->label, initials);
+ g_free (initials);
}
static void
@@ -701,10 +710,11 @@ adw_avatar_draw_to_pixbuf (AdwAvatar *self,
int size,
int scale_factor)
{
+ GdkPixbuf *result = NULL;
GtkSnapshot *snapshot;
- g_autoptr (GskRenderNode) node = NULL;
- g_autoptr (cairo_surface_t) surface = NULL;
- g_autoptr (cairo_t) cr = NULL;
+ GskRenderNode *node = NULL;
+ cairo_surface_t *surface = NULL;
+ cairo_t *cr = NULL;
graphene_rect_t bounds;
g_return_val_if_fail (ADW_IS_AVATAR (self), NULL);
@@ -730,7 +740,12 @@ adw_avatar_draw_to_pixbuf (AdwAvatar *self,
gsk_render_node_draw (node, cr);
- return gdk_pixbuf_get_from_surface (surface, 0, 0,
- bounds.size.width,
- bounds.size.height);
+ result = gdk_pixbuf_get_from_surface (surface, 0, 0,
+ bounds.size.width,
+ bounds.size.height);
+
+ cairo_destroy (cr);
+ cairo_surface_destroy (surface);
+ gsk_render_node_unref (node);
+ return result;
}
diff --git a/src/adw-carousel-indicator-dots.c b/src/adw-carousel-indicator-dots.c
index 825fcf1e..286ca91c 100644
--- a/src/adw-carousel-indicator-dots.c
+++ b/src/adw-carousel-indicator-dots.c
@@ -242,8 +242,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;
@@ -265,6 +265,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 b715cab1..854d68c8 100644
--- a/src/adw-carousel-indicator-lines.c
+++ b/src/adw-carousel-indicator-lines.c
@@ -228,8 +228,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;
@@ -238,7 +238,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)
@@ -251,6 +254,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 f53be7bb..987b60c4 100644
--- a/src/adw-combo-row.c
+++ b/src/adw-combo-row.c
@@ -114,10 +114,11 @@ selection_changed (AdwComboRow *self)
if (priv->use_subtitle) {
if (g_list_model_get_n_items (G_LIST_MODEL (priv->current_selection)) > 0) {
GtkListItem *item = g_list_model_get_item (G_LIST_MODEL (priv->current_selection), 0);
- g_autofree char *repr = get_item_representation (self, item);
+ 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);
@@ -212,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);
@@ -224,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 5aeb6eb0..52be43de 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 b32aaba1..1f64edaa 100644
--- a/src/adw-indicator-bin.c
+++ b/src/adw-indicator-bin.c
@@ -60,7 +60,7 @@ ensure_shader (AdwIndicatorBin *self)
{
GtkNative *native;
GskRenderer *renderer;
- g_autoptr (GError) error = NULL;
+ GError *error = NULL;
if (self->shader)
return;
@@ -77,6 +77,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);
}
}
@@ -161,7 +163,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);
@@ -187,6 +189,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-main.c b/src/adw-main.c
index 2c9e3a5a..b2d5a55e 100644
--- a/src/adw-main.c
+++ b/src/adw-main.c
@@ -15,7 +15,7 @@ static gboolean
is_high_contrast (void)
{
GdkDisplay *display = gdk_display_get_default ();
- g_auto (GValue) value = G_VALUE_INIT;
+ GValue value = G_VALUE_INIT;
const char *theme_name;
g_value_init (&value, G_TYPE_STRING);
@@ -24,6 +24,7 @@ is_high_contrast (void)
theme_name = g_value_get_string (&value);
+ g_value_unset (&value);
/* TODO: HighContrast shouldn't be a theme */
return !g_strcmp0 (theme_name, "HighContrast") ||
!g_strcmp0 (theme_name, "HighContrastInverse");
@@ -33,7 +34,7 @@ static void
update_theme (void)
{
GtkSettings *settings = gtk_settings_get_default ();
- g_autofree char *new_theme_name = NULL;
+ char *new_theme_name = NULL;
gboolean prefer_dark_theme;
const char *variant;
@@ -49,6 +50,7 @@ update_theme (void)
new_theme_name = g_strdup_printf ("Adwaita-%s", variant);
g_object_set (settings, "gtk-theme-name", new_theme_name, NULL);
+ g_free (new_theme_name);
}
static void
diff --git a/src/adw-preferences-window.c b/src/adw-preferences-window.c
index b72cc9f6..51e0f43e 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 b5c589c7..68da7741 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 0967c7c0..1f15d04b 100644
--- a/src/adw-tab-box.c
+++ b/src/adw-tab-box.c
@@ -1822,7 +1822,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;
@@ -1830,6 +1830,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 c6ef244e..8780edf5 100644
--- a/src/adw-tab-view.c
+++ b/src/adw-tab-view.c
@@ -921,7 +921,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,
@@ -2651,7 +2651,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 8ac15719..6af51d05 100644
--- a/src/adw-tab.c
+++ b/src/adw-tab.c
@@ -319,7 +319,7 @@ ensure_shader (AdwTab *self)
{
GtkNative *native;
GskRenderer *renderer;
- g_autoptr (GError) error = NULL;
+ GError *error = NULL;
if (self->shader)
return;
@@ -336,6 +336,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-value-object.c b/src/adw-value-object.c
index dd9eefd2..3a6174d7 100644
--- a/src/adw-value-object.c
+++ b/src/adw-value-object.c
@@ -71,8 +71,9 @@ adw_value_object_new (const GValue *value)
AdwValueObject *
adw_value_object_new_collect (GType type, ...)
{
- g_auto(GValue) value = G_VALUE_INIT;
- g_autofree char *error = NULL;
+ AdwValueObject *obj;
+ GValue value = G_VALUE_INIT;
+ char *error = NULL;
va_list var_args;
va_start (var_args, type);
@@ -82,11 +83,16 @@ adw_value_object_new_collect (GType type, ...)
va_end (var_args);
if (error)
- g_critical ("%s: %s", G_STRFUNC, error);
+ {
+ g_critical ("%s: %s", G_STRFUNC, error);
+ g_free (error);
+ }
- return g_object_new (ADW_TYPE_VALUE_OBJECT,
- "value", &value,
- NULL);
+ obj = g_object_new (ADW_TYPE_VALUE_OBJECT,
+ "value", &value,
+ NULL);
+ g_value_unset (&value);
+ return obj;
}
/**
@@ -105,11 +111,15 @@ adw_value_object_new_collect (GType type, ...)
AdwValueObject *
adw_value_object_new_string (const char *string)
{
- g_auto(GValue) value = G_VALUE_INIT;
+ AdwValueObject *obj;
+ GValue value = G_VALUE_INIT;
g_value_init (&value, G_TYPE_STRING);
g_value_set_string (&value, string);
- return adw_value_object_new (&value);
+ obj = adw_value_object_new (&value);
+
+ g_value_unset (&value);
+ return obj;
}
/**
@@ -128,11 +138,15 @@ adw_value_object_new_string (const char *string)
AdwValueObject *
adw_value_object_new_take_string (char *string)
{
- g_auto(GValue) value = G_VALUE_INIT;
+ GValue value = G_VALUE_INIT;
+ AdwValueObject *obj;
g_value_init (&value, G_TYPE_STRING);
g_value_take_string (&value, string);
- return adw_value_object_new (&value);
+ obj = adw_value_object_new (&value);
+
+ g_value_unset (&value);
+ return obj;
}
static void
diff --git a/src/adw-view-switcher.c b/src/adw-view-switcher.c
index 97b5d2fa..b2306a04 100644
--- a/src/adw-view-switcher.c
+++ b/src/adw-view-switcher.c
@@ -100,8 +100,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;
@@ -125,6 +125,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]