diff --git a/HACKING.md b/HACKING.md
index 81e02a8ca70735a9197483d61485fbf7d823bfc1..487a5dcb068f827322d61aeb95781b563ba14e53 100644
--- a/HACKING.md
+++ b/HACKING.md
@@ -392,25 +392,3 @@ Use minus signs instead of underscores in property names:
```xml
12
```
-
-### Automatic Cleanup
-
-It's recommended to use `g_auto()`, `g_autoptr()`, `g_autofree()` for
-automatic resource cleanup when possible.
-
-*Good*:
-
-```c
-g_autoptr(GdkPixbuf) sigterm = pixbuf = gtk_icon_info_load_icon (info, NULL);
-```
-
-*Bad*:
-
-```c
-GdkPixbuf *pixbuf = gtk_icon_info_load_icon (info, NULL);
-...
-g_object_unref (pixbuf);
-```
-
-Using the above is fine since libadwaita doesn't target any older glib versions
-or non GCC/Clang compilers at the moment.
diff --git a/demo/adwaita-demo.c b/demo/adwaita-demo.c
index e00ca1105691ecb3bce19529c2aa53b139783295..54bbb1defa14f6efd2f6015fab682907842a45b8 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;
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/data/meson.build b/demo/data/meson.build
index 612410c5f185f8c0766ea2657fbd5a892fe5c3d7..27f9773457262b6b5df0c2b6f91beddc0c6cb4c8 100644
--- a/demo/data/meson.build
+++ b/demo/data/meson.build
@@ -28,17 +28,19 @@ appdata_config = configuration_data()
appdata_config.set('BUILD_VERSION', meson.project_version())
appdata_config.set('BUILD_DATE', today)
-appstream_file = i18n.merge_file(
- input: configure_file(
- input: 'org.gnome.Adwaita1.Demo.metainfo.xml.in.in',
- output: 'org.gnome.Adwaita1.Demo.metainfo.xml.in',
- configuration: appdata_config
- ),
- output: 'org.gnome.Adwaita1.Demo.metainfo.xml',
- po_dir: '../../po',
- install: true,
- install_dir: datadir / 'metainfo'
-)
+if target_system != 'windows'
+ appstream_file = i18n.merge_file(
+ input: configure_file(
+ input: 'org.gnome.Adwaita1.Demo.metainfo.xml.in.in',
+ output: 'org.gnome.Adwaita1.Demo.metainfo.xml.in',
+ configuration: appdata_config
+ ),
+ output: 'org.gnome.Adwaita1.Demo.metainfo.xml',
+ po_dir: '../../po',
+ install: true,
+ install_dir: datadir / 'metainfo'
+ )
+endif
appstream_util = find_program('appstream-util', required: false)
if appstream_util.found()
diff --git a/demo/pages/animations/adw-demo-page-animations.c b/demo/pages/animations/adw-demo-page-animations.c
index 624760531c46f39ead0f8b3c04e365b46891efa8..0ab807eaf10eea907ebef76ba9674e574fdec1db 100644
--- a/demo/pages/animations/adw-demo-page-animations.c
+++ b/demo/pages/animations/adw-demo-page-animations.c
@@ -242,12 +242,14 @@ 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 05ad55c68df731ed19991a693b62cf0ba9811d45..fb935e063980d5533d9fb75b005b5e8b71a858b7 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,8 @@ 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 +89,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;
+ GdkTexture *texture;
+ GError *error = NULL;
info = g_file_query_info (file,
G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME,
@@ -109,6 +111,11 @@ open_response_cb (AdwDemoPageAvatar *self,
g_critical ("Failed to create texture from file: %s", error->message);
adw_avatar_set_custom_image (self->avatar, texture ? GDK_PAINTABLE (texture) : NULL);
+
+ g_clear_error (&error);
+ g_clear_object (&info);
+ g_object_unref (texture);
+ g_object_unref (file);
}
gtk_native_dialog_destroy (GTK_NATIVE_DIALOG (chooser));
@@ -145,12 +152,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 +202,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;
gtk_widget_init_template (GTK_WIDGET (self));
@@ -201,4 +211,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 cda44c92b718d45a53d9c539642fc5b11dbbdb6f..15078c24749db4c5993eee9770e0f4480fca24a5 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;
AdwTabPage *page;
GtkWidget *content;
GIcon *icon;
@@ -123,6 +123,8 @@ tab_new (GSimpleAction *action,
gtk_widget_grab_focus (content);
next_page++;
+
+ g_free (title);
}
static AdwTabPage *
@@ -256,13 +258,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_clear_object (&icon);
}
static void
@@ -274,9 +278,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 +296,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 +444,7 @@ static void
indicator_activated_cb (AdwTabViewDemoWindow *self,
AdwTabPage *page)
{
- g_autoptr (GIcon) icon = NULL;
+ GIcon *icon;
gboolean muted;
muted = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (page),
@@ -449,6 +457,8 @@ indicator_activated_cb (AdwTabViewDemoWindow *self,
icon = get_indicator_icon (page);
adw_tab_page_set_indicator_icon (page, icon);
+
+ g_object_unref (icon);
}
static gboolean
diff --git a/demo/pages/toasts/adw-demo-page-toasts.c b/demo/pages/toasts/adw-demo-page-toasts.c
index 4b6791047870c0883325f7096438286073845be9..f23043413366199838eaa562124848b6e3ddd5f3 100644
--- a/demo/pages/toasts/adw-demo-page-toasts.c
+++ b/demo/pages/toasts/adw-demo-page-toasts.c
@@ -44,11 +44,18 @@ toast_add_cb (AdwDemoPageToasts *self)
static void
toast_add_with_button_cb (AdwDemoPageToasts *self)
{
- g_autofree char *title = NULL;
+ char *title;
self->toast_undo_items++;
- if (!self->undo_toast) {
+ if (self->undo_toast) {
+ title =
+ g_strdup_printf (ngettext ("%d item deleted",
+ "%d items deleted",
+ self->toast_undo_items), self->toast_undo_items);
+
+ adw_toast_set_title (self->undo_toast, title);
+ } else {
title = g_strdup_printf (_("‘%s’ deleted"), "Lorem Ipsum");
self->undo_toast = adw_toast_new (title);
@@ -62,16 +69,9 @@ toast_add_with_button_cb (AdwDemoPageToasts *self)
add_toast (self, self->undo_toast);
gtk_widget_action_set_enabled (GTK_WIDGET (self), "toast.dismiss", TRUE);
-
- return;
}
- title =
- g_strdup_printf (ngettext ("%d item deleted",
- "%d items deleted",
- self->toast_undo_items), self->toast_undo_items);
-
- adw_toast_set_title (self->undo_toast, title);
+ g_free (title);
}
static void
@@ -124,7 +124,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 %d item…",
"Undoing deleting %d items…",
self->toast_undo_items), self->toast_undo_items);
@@ -133,4 +133,6 @@ 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/meson.build b/examples/meson.build
index bbacb3f44337d4010dde3df2544c1b530dda5757..a2a05fc6a5a9fa726729fe1638cf67220f984396 100644
--- a/examples/meson.build
+++ b/examples/meson.build
@@ -1,3 +1,10 @@
+if cc.get_id() == 'msvc'
+
+ message('Skipping examples while building with Visual Studio')
+ subdir_done()
+
+endif
+
if get_option('examples')
subdir('hello-world')
diff --git a/meson.build b/meson.build
index 41931b4c403dc61c63b58455b2f5a36b136d80cf..23a43a584d3f60ccd016f41c92e202d9d8375617 100644
--- a/meson.build
+++ b/meson.build
@@ -36,54 +36,60 @@ src_inc = include_directories('src')
cc = meson.get_compiler('c')
global_c_args = []
-test_c_args = [
- '-Wcast-align',
- '-Wdate-time',
- '-Wdeclaration-after-statement',
- ['-Werror=format-security', '-Werror=format=2'],
- '-Wendif-labels',
- '-Werror=incompatible-pointer-types',
- '-Werror=missing-declarations',
- '-Werror=overflow',
- '-Werror=return-type',
- '-Werror=shift-count-overflow',
- '-Werror=shift-overflow=2',
- '-Werror=implicit-fallthrough=3',
- '-Wformat-nonliteral',
- '-Wformat-security',
- '-Winit-self',
- '-Wmaybe-uninitialized',
- '-Wmissing-field-initializers',
- '-Wmissing-include-dirs',
- '-Wmissing-noreturn',
- '-Wnested-externs',
- '-Wno-missing-field-initializers',
- '-Wno-sign-compare',
- '-Wno-strict-aliasing',
- '-Wno-unused-parameter',
- '-Wold-style-definition',
- '-Wpointer-arith',
- '-Wredundant-decls',
- '-Wshadow',
- '-Wstrict-prototypes',
- '-Wswitch-default',
- '-Wswitch-enum',
- '-Wtype-limits',
- '-Wundef',
- '-Wunused-function',
-]
+test_c_args = []
target_system = target_machine.system()
-if get_option('buildtype') != 'plain'
- if target_system == 'windows'
- test_c_args += '-fstack-protector'
- else
- test_c_args += '-fstack-protector-strong'
+if cc.get_id() != 'msvc'
+ test_c_args += [
+ '-Wcast-align',
+ '-Wdate-time',
+ '-Wdeclaration-after-statement',
+ ['-Werror=format-security', '-Werror=format=2'],
+ '-Wendif-labels',
+ '-Werror=incompatible-pointer-types',
+ '-Werror=missing-declarations',
+ '-Werror=overflow',
+ '-Werror=return-type',
+ '-Werror=shift-count-overflow',
+ '-Werror=shift-overflow=2',
+ '-Werror=implicit-fallthrough=3',
+ '-Wformat-nonliteral',
+ '-Wformat-security',
+ '-Winit-self',
+ '-Wmaybe-uninitialized',
+ '-Wmissing-field-initializers',
+ '-Wmissing-include-dirs',
+ '-Wmissing-noreturn',
+ '-Wnested-externs',
+ '-Wno-missing-field-initializers',
+ '-Wno-sign-compare',
+ '-Wno-strict-aliasing',
+ '-Wno-unused-parameter',
+ '-Wold-style-definition',
+ '-Wpointer-arith',
+ '-Wredundant-decls',
+ '-Wshadow',
+ '-Wstrict-prototypes',
+ '-Wswitch-default',
+ '-Wswitch-enum',
+ '-Wtype-limits',
+ '-Wundef',
+ '-Wunused-function',
+ ]
+
+ if get_option('buildtype') != 'plain'
+ if target_system == 'windows'
+ test_c_args += '-fstack-protector'
+ else
+ test_c_args += '-fstack-protector-strong'
+ endif
endif
-endif
-if get_option('profiling')
- test_c_args += '-pg'
+ if get_option('profiling')
+ test_c_args += '-pg'
+ endif
+else
+ test_c_args += '-FImsvc_recommended_pragmas.h'
endif
foreach arg: test_c_args
diff --git a/meson_options.txt b/meson_options.txt
index a136a963634e66a4379c02cbb82efeb28969c5b0..b95d0ae4a856b6e9ac8e97a51ffb48c674c78acd 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -19,4 +19,4 @@ option('tests',
option('examples',
type: 'boolean', value: true,
- description: 'Build and install the examples and demo applications')
+ description: 'Build and install the examples and demo applications (currently not built for MSVC builds)')
diff --git a/src/adw-application.c b/src/adw-application.c
index 0c2dc412f8d23a6aac7393792918802090ae06c3..ee9c04ef4aaf82dd2f5ee063899f3d7020bcba7a 100644
--- a/src/adw-application.c
+++ b/src/adw-application.c
@@ -111,10 +111,9 @@ static void
init_providers (AdwApplication *self)
{
AdwApplicationPrivate *priv = adw_application_get_instance_private (self);
-
- const char *base_path = NULL;
- g_autofree char *base_uri = NULL;
- g_autoptr (GFile) base_file = NULL;
+ const char *base_path;
+ char *base_uri;
+ GFile *base_file;
base_path = g_application_get_resource_base_path (G_APPLICATION (self));
@@ -132,6 +131,9 @@ init_providers (AdwApplication *self)
g_file_get_child (base_file, "style-hc.css"));
init_provider_from_file (&priv->hc_dark_style_provider,
g_file_get_child (base_file, "style-hc-dark.css"));
+
+ g_object_unref (base_file);
+ g_free (base_uri);
}
static void
diff --git a/src/adw-avatar.c b/src/adw-avatar.c
index dec89921b248b86d8c3914e1e65538a0608a65bc..bb19c5afb7ca7a784bb5ecc48673e26e65abfeb6 100644
--- a/src/adw-avatar.c
+++ b/src/adw-avatar.c
@@ -83,11 +83,13 @@ 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;
+ g_clear_pointer (&p, g_free);
+
if (normalized == NULL)
return NULL;
@@ -104,6 +106,8 @@ extract_initials_from_text (const char *text)
g_string_append_unichar (initials, unichar);
}
+ g_free (normalized);
+
return g_string_free (initials, FALSE);
}
@@ -121,29 +125,33 @@ 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);
+ char *old_class, *new_class;
+ old_class = g_strdup_printf ("color%d", self->color_class);
gtk_widget_remove_css_class (self->gizmo, old_class);
if (self->text == NULL || strlen (self->text) == 0) {
/* Use a random color if we don't have a text */
- rand = g_rand_new ();
+ GRand *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;
}
new_class = g_strdup_printf ("color%d", self->color_class);
-
gtk_widget_add_css_class (self->gizmo, new_class);
+
+ g_free (old_class);
+ g_free (new_class);
}
static void
update_initials (AdwAvatar *self)
{
- g_autofree char *initials = NULL;
+ char *initials;
if (gtk_image_get_paintable (self->custom_image) != NULL ||
!self->show_initials ||
@@ -154,6 +162,8 @@ update_initials (AdwAvatar *self)
initials = extract_initials_from_text (self->text);
gtk_label_set_label (self->label, initials);
+
+ g_free (initials);
}
static void
@@ -633,7 +643,7 @@ adw_avatar_set_custom_image (AdwAvatar *self,
gtk_image_set_from_paintable (self->custom_image, custom_image);
} else {
GtkSnapshot *snapshot = gtk_snapshot_new ();
- g_autoptr (GdkPaintable) square_image = NULL;
+ GdkPaintable *square_image;
int size = MIN (width, height);
gtk_snapshot_translate (snapshot, &GRAPHENE_POINT_INIT ((size - width) / 2.f, (size - height) / 2.f));
@@ -641,6 +651,8 @@ adw_avatar_set_custom_image (AdwAvatar *self,
square_image = gtk_snapshot_free_to_paintable (snapshot, &GRAPHENE_SIZE_INIT (size, size));
gtk_image_set_from_paintable (self->custom_image, square_image);
+
+ g_object_unref (square_image);
}
gtk_widget_add_css_class (self->gizmo, "image");
@@ -724,7 +736,8 @@ GdkTexture *
adw_avatar_draw_to_texture (AdwAvatar *self,
int scale_factor)
{
- g_autoptr (GskRenderNode) node = NULL;
+ GdkTexture *result;
+ GskRenderNode *node;
GtkSnapshot *snapshot;
GtkNative *native;
GskRenderer *renderer;
@@ -744,5 +757,9 @@ 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 b2c338934aa236201d5c3bfdb43f9336db83071d..a23b8ab816fb0413133e3714677b38c3c51755b4 100644
--- a/src/adw-carousel-indicator-dots.c
+++ b/src/adw-carousel-indicator-dots.c
@@ -222,8 +222,7 @@ 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, *sizes;
if (!self->carousel)
return;
@@ -231,8 +230,11 @@ adw_carousel_indicator_dots_snapshot (GtkWidget *widget,
points = adw_swipeable_get_snap_points (ADW_SWIPEABLE (self->carousel), &n_points);
position = adw_carousel_get_position (self->carousel);
- if (n_points < 2)
+ if (n_points < 2) {
+ g_free (points);
+
return;
+ }
if (self->orientation == GTK_ORIENTATION_HORIZONTAL &&
gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
@@ -245,6 +247,9 @@ 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 c569268d16ae8278eb40f1271d165407d3a205b9..bf851049bfdd2535a60e1128ec526c4dd7121bef 100644
--- a/src/adw-carousel-indicator-lines.c
+++ b/src/adw-carousel-indicator-lines.c
@@ -207,8 +207,7 @@ 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, *sizes;
if (!self->carousel)
return;
@@ -216,8 +215,11 @@ adw_carousel_indicator_lines_snapshot (GtkWidget *widget,
points = adw_swipeable_get_snap_points (ADW_SWIPEABLE (self->carousel), &n_points);
position = adw_carousel_get_position (self->carousel);
- if (n_points < 2)
+ if (n_points < 2) {
+ g_free (points);
+
return;
+ }
if (self->orientation == GTK_ORIENTATION_HORIZONTAL &&
gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
@@ -230,6 +232,9 @@ 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 2b541ad742b908a01d2265713d69658265835832..648781164aa4debaeb3166dc9aa697517f66cb1f 100644
--- a/src/adw-combo-row.c
+++ b/src/adw-combo-row.c
@@ -119,10 +119,13 @@ 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);
}
@@ -226,7 +229,7 @@ bind_item (GtkSignalListItemFactory *factory,
gpointer item;
GtkWidget *box;
GtkWidget *icon;
- g_autofree char *repr = NULL;
+ char *repr;
item = gtk_list_item_get_item (list_item);
box = gtk_list_item_get_child (list_item);
@@ -250,6 +253,8 @@ bind_item (GtkSignalListItemFactory *factory,
} else {
gtk_widget_hide (icon);
}
+
+ g_clear_pointer (&repr, g_free);
}
static void
@@ -263,13 +268,15 @@ unbind_item (GtkSignalListItemFactory *factory,
static void
set_default_factory (AdwComboRow *self)
{
- g_autoptr (GtkListItemFactory) factory = gtk_signal_list_item_factory_new ();
+ GtkListItemFactory *factory = gtk_signal_list_item_factory_new ();
g_signal_connect (factory, "setup", G_CALLBACK (setup_item), self);
g_signal_connect (factory, "bind", G_CALLBACK (bind_item), self);
g_signal_connect (factory, "unbind", G_CALLBACK (unbind_item), self);
adw_combo_row_set_factory (self, factory);
+
+ g_object_unref (factory);
}
static void
diff --git a/src/adw-fading-label.c b/src/adw-fading-label.c
index 08d0cf014056845a437a47c29b65cf547901d1dd..e9a685e128687164a4870c26bacbe3e88bcc553f 100644
--- a/src/adw-fading-label.c
+++ b/src/adw-fading-label.c
@@ -60,7 +60,7 @@ ensure_shader (AdwFadingLabel *self)
{
GtkNative *native;
GskRenderer *renderer;
- g_autoptr (GError) error = NULL;
+ GError *error = NULL;
if (self->shader)
return;
@@ -78,6 +78,8 @@ ensure_shader (AdwFadingLabel *self)
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);
}
static void
@@ -128,7 +130,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;
graphene_rect_t bounds;
if (width <= 0)
@@ -170,6 +172,8 @@ 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 6f79f2bc7b3e8f6e8adfb2f598fdcca90ba082c4..cc2c7e168e42468474f0b4ee065432ca2154e02d 100644
--- a/src/adw-indicator-bin.c
+++ b/src/adw-indicator-bin.c
@@ -62,7 +62,7 @@ ensure_shader (AdwIndicatorBin *self)
{
GtkNative *native;
GskRenderer *renderer;
- g_autoptr (GError) error = NULL;
+ GError *error = NULL;
if (self->shader)
return;
@@ -80,6 +80,8 @@ ensure_shader (AdwIndicatorBin *self)
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);
}
static gboolean
@@ -167,7 +169,7 @@ adw_indicator_bin_snapshot (GtkWidget *widget,
if (self->child) {
GtkSnapshot *child_snapshot;
- g_autoptr (GskRenderNode) child_node = NULL;
+ GskRenderNode *child_node;
child_snapshot = gtk_snapshot_new ();
gtk_widget_snapshot_child (widget, self->child, child_snapshot);
@@ -193,6 +195,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 3a074d416d56ea297a4633fa2f8e18427d6a7a7a..bb69eeb5d4b9a4c179ad7ee426ecf862ee15ef64 100644
--- a/src/adw-preferences-window.c
+++ b/src/adw-preferences-window.c
@@ -89,7 +89,7 @@ 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;
gboolean underscore = FALSE;
@@ -101,6 +101,8 @@ strip_mnemonic (const char *src)
if (c == (gunichar) -1) {
g_warning ("Invalid input string");
+ g_free (new_str);
+
return NULL;
}
@@ -124,7 +126,7 @@ strip_mnemonic (const char *src)
*dest = 0;
- return g_steal_pointer (&new_str);
+ return new_str;
}
static gboolean
@@ -132,8 +134,8 @@ 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, *title;
+ gboolean result = FALSE;
g_assert (ADW_IS_PREFERENCES_ROW (row));
@@ -145,21 +147,26 @@ filter_search_results (AdwPreferencesRow *row,
if (stripped_title) {
g_free (title);
+
title = stripped_title;
}
}
- if (!!strstr (title, terms))
- return TRUE;
-
- if (ADW_IS_ACTION_ROW (row)) {
- g_autofree char *subtitle = g_utf8_casefold (adw_action_row_get_subtitle (ADW_ACTION_ROW (row)), -1);
+ if (!!strstr (title, terms)) {
+ result = TRUE;
+ } 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
@@ -187,7 +194,7 @@ create_search_row_subtitle (AdwPreferencesWindow *self,
{
GtkWidget *group, *page;
const char *group_title = NULL;
- g_autofree char *page_title = NULL;
+ char *page_title = NULL;
group = gtk_widget_get_ancestor (row, ADW_TYPE_PREFERENCES_GROUP);
@@ -209,20 +216,23 @@ create_search_row_subtitle (AdwPreferencesWindow *self,
page_title = g_strdup (title);
if (g_strcmp0 (page_title, "") == 0)
- page_title = NULL;
+ g_clear_pointer (&page_title, g_free);
}
if (group_title) {
+ gchar *result;
+
if (get_n_pages (self) > 1)
- return g_strdup_printf ("%s → %s", page_title ? page_title : _("Untitled page"), group_title);
+ result = g_strdup_printf ("%s → %s", page_title ? page_title : _("Untitled page"), group_title);
+ else
+ result = g_strdup (group_title);
- return g_strdup (group_title);
- }
+ g_free (page_title);
- if (page_title)
- return g_steal_pointer (&page_title);
+ return result;
+ }
- return NULL;
+ return page_title;
}
static GtkWidget *
@@ -231,7 +241,7 @@ new_search_row_for_preference (AdwPreferencesRow *row,
{
AdwActionRow *widget;
GtkWidget *page;
- g_autofree char *subtitle = NULL;
+ char *subtitle;
g_assert (ADW_IS_PREFERENCES_ROW (row));
@@ -247,6 +257,8 @@ new_search_row_for_preference (AdwPreferencesRow *row,
g_object_set_data (G_OBJECT (widget), "page", page);
g_object_set_data (G_OBJECT (widget), "row", row);
+ g_clear_pointer (&subtitle, g_free);
+
return GTK_WIDGET (widget);
}
diff --git a/src/adw-settings.c b/src/adw-settings.c
index 6c4420fdd5e28903a7060234ae70041daed726aa..11a54bdb7d787cfa2cc47fed76507e56c3328a84 100644
--- a/src/adw-settings.c
+++ b/src/adw-settings.c
@@ -84,6 +84,7 @@ set_high_contrast (AdwSettings *self,
/* Settings portal */
+#ifndef G_OS_WIN32
static gboolean
get_disable_portal (void)
{
@@ -99,11 +100,11 @@ read_portal_setting (AdwSettings *self,
const char *type,
GVariant **out)
{
- g_autoptr (GError) error = NULL;
- g_autoptr (GVariant) ret = NULL;
- g_autoptr (GVariant) child = NULL;
- g_autoptr (GVariant) child2 = NULL;
- g_autoptr (GVariantType) out_type = NULL;
+ GError *error = NULL;
+ GVariant *ret;
+ GVariant *child, *child2;
+ GVariantType *out_type;
+ gboolean result = FALSE;
ret = g_dbus_proxy_call_sync (self->settings_portal,
"Read",
@@ -116,29 +117,20 @@ read_portal_setting (AdwSettings *self,
if (error->domain == G_DBUS_ERROR &&
error->code == G_DBUS_ERROR_SERVICE_UNKNOWN) {
g_debug ("Portal not found: %s", error->message);
-
- return FALSE;
- }
-
- if (error->domain == G_DBUS_ERROR &&
- error->code == G_DBUS_ERROR_UNKNOWN_METHOD) {
+ } else if (error->domain == G_DBUS_ERROR &&
+ error->code == G_DBUS_ERROR_UNKNOWN_METHOD) {
g_debug ("Portal doesn't provide settings: %s", error->message);
-
- return FALSE;
- }
-
- if (g_dbus_error_is_remote_error (error)) {
- g_autofree char *remote_error = g_dbus_error_get_remote_error (error);
+ } else if (g_dbus_error_is_remote_error (error)) {
+ char *remote_error = g_dbus_error_get_remote_error (error);
if (!g_strcmp0 (remote_error, PORTAL_ERROR_NOT_FOUND)) {
g_debug ("Setting %s.%s of type %s not found", schema, name, type);
-
- return FALSE;
}
+ g_free (remote_error);
+ } else {
+ g_critical ("Couldn't read the %s setting: %s", name, error->message);
}
- g_critical ("Couldn't read the %s setting: %s", name, error->message);
-
return FALSE;
}
@@ -146,16 +138,23 @@ read_portal_setting (AdwSettings *self,
g_variant_get (child, "v", &child2);
out_type = g_variant_type_new (type);
- if (!g_variant_type_equal (g_variant_get_type (child2), out_type)) {
+ if (g_variant_type_equal (g_variant_get_type (child2), out_type)) {
+ *out = child2;
+
+ result = TRUE;
+ } else {
g_critical ("Invalid type for %s.%s: expected %s, got %s",
schema, name, type, g_variant_get_type_string (child2));
- return FALSE;
+ g_variant_unref (child2);
}
- *out = g_steal_pointer (&child2);
+ g_variant_type_free (out_type);
+ g_variant_unref (child);
+ g_variant_unref (ret);
+ g_clear_error (&error);
- return TRUE;
+ return result;
}
static AdwSystemColorScheme
@@ -200,7 +199,7 @@ settings_portal_changed_cb (GDBusProxy *proxy,
{
const char *namespace;
const char *name;
- g_autoptr (GVariant) value = NULL;
+ GVariant *value = NULL;
if (g_strcmp0 (signal_name, "SettingChanged"))
return;
@@ -212,6 +211,8 @@ settings_portal_changed_cb (GDBusProxy *proxy,
self->color_scheme_use_fdo_setting) {
set_color_scheme (self, get_fdo_color_scheme (value));
+ g_variant_unref (value);
+
return;
}
@@ -220,6 +221,8 @@ settings_portal_changed_cb (GDBusProxy *proxy,
!self->color_scheme_use_fdo_setting) {
set_color_scheme (self, get_gnome_color_scheme (value));
+ g_variant_unref (value);
+
return;
}
@@ -227,6 +230,8 @@ settings_portal_changed_cb (GDBusProxy *proxy,
!g_strcmp0 (name, "high-contrast")) {
set_high_contrast (self, g_variant_get_boolean (value));
+ g_variant_unref (value);
+
return;
}
}
@@ -234,9 +239,8 @@ settings_portal_changed_cb (GDBusProxy *proxy,
static void
init_portal (AdwSettings *self)
{
- g_autoptr (GError) error = NULL;
- g_autoptr (GVariant) color_scheme_variant = NULL;
- g_autoptr (GVariant) high_contrast_variant = NULL;
+ GError *error = NULL;
+ GVariant *variant;
if (get_disable_portal ())
return;
@@ -252,27 +256,35 @@ init_portal (AdwSettings *self)
if (error) {
g_debug ("Settings portal not found: %s", error->message);
+ g_error_free (error);
+
return;
}
if (read_portal_setting (self, "org.freedesktop.appearance",
- "color-scheme", "u", &color_scheme_variant)) {
+ "color-scheme", "u", &variant)) {
self->has_color_scheme = TRUE;
self->color_scheme_use_fdo_setting = TRUE;
- self->color_scheme = get_fdo_color_scheme (color_scheme_variant);
+ self->color_scheme = get_fdo_color_scheme (variant);
+
+ g_variant_unref (variant);
}
if (!self->has_color_scheme &&
read_portal_setting (self, "org.gnome.desktop.interface",
- "color-scheme", "s", &color_scheme_variant)) {
+ "color-scheme", "s", &variant)) {
self->has_color_scheme = TRUE;
- self->color_scheme = get_gnome_color_scheme (color_scheme_variant);
+ self->color_scheme = get_gnome_color_scheme (variant);
+
+ g_variant_unref (variant);
}
if (read_portal_setting (self, "org.gnome.desktop.interface.a11y",
- "high-contrast", "b", &high_contrast_variant)) {
+ "high-contrast", "b", &variant)) {
self->has_high_contrast = TRUE;
- self->high_contrast = g_variant_get_boolean (high_contrast_variant);
+ self->high_contrast = g_variant_get_boolean (variant);
+
+ g_variant_unref (variant);
}
if (!self->has_color_scheme && !self->has_high_contrast)
@@ -281,14 +293,17 @@ init_portal (AdwSettings *self)
g_signal_connect (self->settings_portal, "g-signal",
G_CALLBACK (settings_portal_changed_cb), self);
}
+#endif
/* GSettings */
+#ifndef G_OS_WIN32
static gboolean
is_running_in_flatpak (void)
{
return g_file_test ("/.flatpak-info", G_FILE_TEST_EXISTS);
}
+#endif
static void
gsettings_color_scheme_changed_cb (AdwSettings *self)
@@ -306,13 +321,14 @@ static void
init_gsettings (AdwSettings *self)
{
GSettingsSchemaSource *source;
- g_autoptr (GSettingsSchema) schema = NULL;
- g_autoptr (GSettingsSchema) a11y_schema = NULL;
+ GSettingsSchema *schema;
+#ifndef G_OS_WIN32
/* While we can access gsettings in flatpak, we can't do anything useful with
* them as they aren't propagated from the system. */
if (is_running_in_flatpak ())
return;
+#endif
source = g_settings_schema_source_get_default ();
@@ -328,12 +344,14 @@ init_gsettings (AdwSettings *self)
"changed::color-scheme",
G_CALLBACK (gsettings_color_scheme_changed_cb),
self);
+
+ g_settings_schema_unref (schema);
}
- a11y_schema = g_settings_schema_source_lookup (source, "org.gnome.desktop.a11y.interface", TRUE);
- if (a11y_schema &&
+ schema = g_settings_schema_source_lookup (source, "org.gnome.desktop.a11y.interface", TRUE);
+ if (schema &&
!self->has_high_contrast &&
- g_settings_schema_has_key (a11y_schema, "high-contrast")) {
+ g_settings_schema_has_key (schema, "high-contrast")) {
self->has_high_contrast = TRUE;
self->a11y_settings = g_settings_new ("org.gnome.desktop.a11y.interface");
self->high_contrast = g_settings_get_boolean (self->a11y_settings, "high-contrast");
@@ -342,6 +360,8 @@ init_gsettings (AdwSettings *self)
"changed::high-contrast",
G_CALLBACK (gsettings_high_contrast_changed_cb),
self);
+
+ g_settings_schema_unref (schema);
}
}
@@ -350,7 +370,7 @@ init_gsettings (AdwSettings *self)
static gboolean
is_theme_high_contrast (GdkDisplay *display)
{
- g_auto (GValue) value = G_VALUE_INIT;
+ GValue value = G_VALUE_INIT;
const char *theme_name;
g_value_init (&value, G_TYPE_STRING);
@@ -359,6 +379,8 @@ is_theme_high_contrast (GdkDisplay *display)
theme_name = g_value_get_string (&value);
+ g_value_unset (&value);
+
return !g_strcmp0 (theme_name, "HighContrast") ||
!g_strcmp0 (theme_name, "HighContrastInverse");
}
@@ -396,7 +418,9 @@ adw_settings_constructed (GObject *object)
G_OBJECT_CLASS (adw_settings_parent_class)->constructed (object);
+#ifndef G_OS_WIN32
init_portal (self);
+#endif
if (!self->has_color_scheme || !self->has_high_contrast)
init_gsettings (self);
diff --git a/src/adw-style-manager.c b/src/adw-style-manager.c
index bf9dd5b6df2057267f3162764c9ef0b39520a83a..05cfc0f44fbef347f79061d8eb8e74ce93461e1c 100644
--- a/src/adw-style-manager.c
+++ b/src/adw-style-manager.c
@@ -509,7 +509,7 @@ void
adw_style_manager_ensure (void)
{
GdkDisplayManager *display_manager = gdk_display_manager_get ();
- g_autoptr (GSList) displays = NULL;
+ GSList *displays;
GSList *l;
if (display_style_managers)
@@ -530,6 +530,8 @@ adw_style_manager_ensure (void)
"display-opened",
G_CALLBACK (register_display),
NULL);
+
+ g_slist_free (displays);
}
/**
diff --git a/src/adw-swipe-tracker.c b/src/adw-swipe-tracker.c
index 7825e8810236c741a4a8afcb8e1b6c6ef290ca6c..9c557b92e5445e94c84b84f9ca1b2d189356630f 100644
--- a/src/adw-swipe-tracker.c
+++ b/src/adw-swipe-tracker.c
@@ -169,13 +169,15 @@ get_range (AdwSwipeTracker *self,
double *first,
double *last)
{
- g_autofree double *points = NULL;
+ double *points;
int n;
points = adw_swipeable_get_snap_points (self->swipeable, &n);
*first = points[0];
*last = points[n - 1];
+
+ g_free (points);
}
static void
@@ -355,11 +357,13 @@ gesture_update (AdwSwipeTracker *self,
return;
if (!self->allow_long_swipes) {
- g_autofree double *points = NULL;
+ double *points;
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);
}
@@ -378,7 +382,7 @@ get_end_progress (AdwSwipeTracker *self,
gboolean is_touchpad)
{
double pos, decel, slope;
- g_autofree double *points = NULL;
+ double *points;
int n;
double lower, upper;
@@ -387,8 +391,13 @@ 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)];
+ if (ABS (velocity) < (is_touchpad ? VELOCITY_THRESHOLD_TOUCHPAD : VELOCITY_THRESHOLD_TOUCH)) {
+ 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;
@@ -406,16 +415,16 @@ get_end_progress (AdwSwipeTracker *self,
pos = (pos * SIGN (velocity)) + self->progress;
- if (!self->allow_long_swipes) {
-
+ if (!self->allow_long_swipes)
get_bounds (self, points, n, self->initial_progress, &lower, &upper);
- } else {
+ else
get_range (self, &lower, &upper);
- }
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 14a1902a6bd0c4e57eddc808f21285fad9dbd8c0..4afc11fee7ed17c426e89b9bb2b7aca1bc8578a9 100644
--- a/src/adw-tab-box.c
+++ b/src/adw-tab-box.c
@@ -1837,7 +1837,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;
self->tab_box->should_detach_into_new_window = TRUE;
@@ -1845,6 +1845,8 @@ 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
@@ -2344,7 +2346,7 @@ static void
begin_drag (AdwTabBox *self,
GdkDevice *device)
{
- g_autoptr (GdkContentProvider) content = NULL;
+ GdkContentProvider *content;
GtkNative *native;
GdkSurface *surface;
GdkDrag *drag;
@@ -2398,6 +2400,7 @@ begin_drag (AdwTabBox *self,
animate_scroll_relative (self, -self->placeholder_scroll_offset, CLOSE_ANIMATION_DURATION);
+ g_object_unref (content);
g_object_unref (detached_tab);
}
diff --git a/src/adw-tab-view.c b/src/adw-tab-view.c
index e0032b2d10a3af9c542d0b1c45b1a3bd3493d012..b81beebabae0f5453a7f199acfe5c151acd2c735 100644
--- a/src/adw-tab-view.c
+++ b/src/adw-tab-view.c
@@ -958,7 +958,7 @@ create_and_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,
@@ -968,6 +968,8 @@ create_and_insert_page (AdwTabView *self,
insert_page (self, page, position);
+ g_object_unref (page);
+
return page;
}
@@ -2594,7 +2596,7 @@ AdwTabPage *
adw_tab_view_get_nth_page (AdwTabView *self,
int position)
{
- g_autoptr (AdwTabPage) page = NULL;
+ AdwTabPage *page;
g_return_val_if_fail (ADW_IS_TAB_VIEW (self), NULL);
g_return_val_if_fail (position >= 0, NULL);
@@ -2602,6 +2604,8 @@ adw_tab_view_get_nth_page (AdwTabView *self,
page = g_list_model_get_item (G_LIST_MODEL (self->children), (guint) position);
+ g_object_unref (page);
+
return page;
}
diff --git a/src/adw-tab.c b/src/adw-tab.c
index 6d344cc6db0cb3c9aa5474f41b7c5b072e024900..6d8a8ebdad2d1dfd17c900b96a0fc469a4386161 100644
--- a/src/adw-tab.c
+++ b/src/adw-tab.c
@@ -307,7 +307,7 @@ ensure_shader (AdwTab *self)
{
GtkNative *native;
GskRenderer *renderer;
- g_autoptr (GError) error = NULL;
+ GError *error = NULL;
if (self->shader)
return;
@@ -325,6 +325,8 @@ ensure_shader (AdwTab *self)
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);
}
static gboolean
@@ -410,7 +412,7 @@ allocate_child (GtkWidget *child,
int width,
int baseline)
{
- GtkAllocation child_alloc = {};
+ GtkAllocation child_alloc;
if (gtk_widget_get_direction (child) == GTK_TEXT_DIR_RTL)
child_alloc.x = parent_width - width - x;
diff --git a/src/adw-toast.c b/src/adw-toast.c
index f72f74d4d9c5d4f5cded01e484b63830faf1ab3c..b996507a81c413423b1da1f9ae6721d3d2dbcab1 100644
--- a/src/adw-toast.c
+++ b/src/adw-toast.c
@@ -659,9 +659,9 @@ void
adw_toast_set_detailed_action_name (AdwToast *self,
const char *detailed_action_name)
{
- g_autofree char *name = NULL;
- g_autoptr (GVariant) target = NULL;
- g_autoptr (GError) error = NULL;
+ char *name;
+ GVariant *target;
+ GError *error = NULL;
g_return_if_fail (ADW_IS_TOAST (self));
@@ -672,14 +672,16 @@ adw_toast_set_detailed_action_name (AdwToast *self,
return;
}
- if (!g_action_parse_detailed_name (detailed_action_name, &name, &target, &error)) {
+ if (g_action_parse_detailed_name (detailed_action_name, &name, &target, &error)) {
+ adw_toast_set_action_name (self, name);
+ adw_toast_set_action_target_value (self, target);
+ } else {
g_critical ("Couldn't parse detailed action name: %s", error->message);
-
- return;
}
- adw_toast_set_action_name (self, name);
- adw_toast_set_action_target_value (self, target);
+ g_clear_error (&error);
+ g_clear_pointer (&target, g_variant_unref);
+ g_clear_pointer (&name, g_free);
}
/**
diff --git a/src/adw-view-switcher.c b/src/adw-view-switcher.c
index 6f514c6355f18918d0e91555005545cc665ebfdb..14812d80604e6fb34f4d01c22e3d362f46a59694 100644
--- a/src/adw-view-switcher.c
+++ b/src/adw-view-switcher.c
@@ -103,8 +103,8 @@ update_button (AdwViewSwitcher *self,
AdwViewStackPage *page,
GtkWidget *button)
{
- g_autofree char *title = NULL;
- g_autofree char *icon_name = NULL;
+ char *title;
+ char *icon_name;
gboolean needs_attention;
guint badge_number;
gboolean visible;
@@ -128,6 +128,9 @@ 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
diff --git a/src/gen-public-types.py b/src/gen-public-types.py
new file mode 100644
index 0000000000000000000000000000000000000000..04adc58c9cce58965d646256bca14f6629688280
--- /dev/null
+++ b/src/gen-public-types.py
@@ -0,0 +1,32 @@
+#!/bin/env python3
+
+import os
+import re
+import sys
+
+def main(argv):
+ ensure_types = []
+ print('/* This file was generated by gen-plublic-types.py, do not edit it. */\n')
+
+ # Run through the headers fed in to #include them and extract the ADW_TYPE_* macros
+ for header in argv[1:]:
+ print('#include "%s"' % os.path.basename(header))
+ with open(header, 'r') as file:
+ for line in file:
+ match = re.search(r'#define {1,}(ADW_TYPE_[A-Z0-9_]{1,}) {1,}.*', line)
+ if match:
+ ensure_types.append(match.group(1))
+
+ ensure_types.sort()
+
+ print('#include "adw-main-private.h"\n')
+ print('void')
+ print('adw_init_public_types (void)')
+ print('{')
+
+ for gtype in ensure_types:
+ print(' g_type_ensure (%s);' % gtype)
+
+ print('}')
+
+main(sys.argv)
diff --git a/src/gen-public-types.sh b/src/gen-public-types.sh
deleted file mode 100644
index b99aa87e29cf5a3c3f3167aad7c3176116d143f5..0000000000000000000000000000000000000000
--- a/src/gen-public-types.sh
+++ /dev/null
@@ -1,22 +0,0 @@
-#!/bin/sh
-
-set -e
-
-echo '/* This file was generated by gen-plublic-types.sh, do not edit it. */
-'
-
-for var in "$@"
-do
- echo "#include \"$(basename "$var")\""
-done
-
-echo '#include "adw-main-private.h"
-
-void
-adw_init_public_types (void)
-{'
-
-sed -ne 's/^#define \{1,\}\(ADW_TYPE_[A-Z0-9_]\{1,\}\) \{1,\}.*/ g_type_ensure (\1);/p' "$@" | sort
-
-echo '}
-'
diff --git a/src/meson.build b/src/meson.build
index 1ed528a09475dfcb9f431df1c378f95087898d51..cfd52054079eb2c73f8701612b8d08f361d3cfe4 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -131,8 +131,7 @@ src_headers = [
'adw-window-title.h',
]
-sed = find_program('sed', required: true)
-gen_public_types = find_program('gen-public-types.sh', required: true)
+gen_public_types = find_program('gen-public-types.py', required: true)
libadwaita_init_public_types = custom_target('adw-public-types.c',
output: 'adw-public-types.c',
diff --git a/tests/meson.build b/tests/meson.build
index e133e7e26249ab35ca2c40319c10e972afaff2f3..6c2a206639e7b11e65b3f68fb18f749f0f3ca52d 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -15,9 +15,13 @@ test_cflags = [
'-DTEST_DATA_DIR="@0@/data"'.format(meson.current_source_dir()),
]
-test_link_args = [
- '-fPIC',
-]
+test_link_args = []
+use_pie = false
+
+if cc.get_argument_syntax() != 'msvc'
+ test_link_args += '-fPIC'
+ use_pie = true
+endif
test_names = [
'test-action-row',
@@ -59,7 +63,7 @@ foreach test_name : test_names
c_args: test_cflags,
link_args: test_link_args,
dependencies: libadwaita_deps + [libadwaita_dep],
- pie: true,
+ pie: use_pie,
)
test(test_name, t, env: test_env)
endforeach
diff --git a/tests/test-button-content.c b/tests/test-button-content.c
index 5d5ba196b17de32fd2294844fdd6334eafb110ff..1399103838cae6c80910cbae11c750f323f7250c 100644
--- a/tests/test-button-content.c
+++ b/tests/test-button-content.c
@@ -20,7 +20,7 @@ static void
test_adw_button_content_icon_name (void)
{
AdwButtonContent *content = g_object_ref_sink (ADW_BUTTON_CONTENT (adw_button_content_new ()));
- g_autofree char *icon_name = NULL;
+ char *icon_name;
g_assert_nonnull (content);
@@ -41,6 +41,7 @@ test_adw_button_content_icon_name (void)
g_assert_cmpstr (adw_button_content_get_icon_name (content), ==, "");
g_assert_cmpint (notified, ==, 2);
+ g_free (icon_name);
g_assert_finalize_object (content);
}
@@ -48,7 +49,7 @@ static void
test_adw_button_content_label (void)
{
AdwButtonContent *content = g_object_ref_sink (ADW_BUTTON_CONTENT (adw_button_content_new ()));
- g_autofree char *label = NULL;
+ char *label;
g_assert_nonnull (content);
@@ -69,6 +70,7 @@ test_adw_button_content_label (void)
g_assert_cmpstr (adw_button_content_get_label (content), ==, "");
g_assert_cmpint (notified, ==, 2);
+ g_free (label);
g_assert_finalize_object (content);
}
diff --git a/tests/test-easing.c b/tests/test-easing.c
index 58ba62871e07c398082c1d0bd13fbbc682aa7d59..470f13c8d0a433f1e47f1b7a40552e72abc8de5e 100644
--- a/tests/test-easing.c
+++ b/tests/test-easing.c
@@ -21,7 +21,7 @@ int
main (int argc,
char *argv[])
{
- g_autoptr (GEnumClass) enum_class = NULL;
+ GEnumClass *enum_class;
guint i;
gtk_test_init (&argc, &argv, NULL);
@@ -31,11 +31,14 @@ main (int argc,
for (i = 0; i < enum_class->n_values; i++) {
GEnumValue *value = &enum_class->values[i];
- g_autofree char *path =
- g_strdup_printf ("/Adwaita/Easing/%s", value->value_nick);
+ char *path = g_strdup_printf ("/Adwaita/Easing/%s", value->value_nick);
g_test_add_data_func (path, GINT_TO_POINTER (value->value), test_easing_ease);
+
+ g_free (path);
}
+ g_type_class_unref (enum_class);
+
return g_test_run();
}
diff --git a/tests/test-leaflet.c b/tests/test-leaflet.c
index 39f7aeed9c48325eea7b0604012f5f63a1344d61..677a17dcf15fd537b8c98cd7b906cc53d63c6d7d 100644
--- a/tests/test-leaflet.c
+++ b/tests/test-leaflet.c
@@ -12,11 +12,11 @@ assert_page_position (GtkSelectionModel *pages,
GtkWidget *widget,
int position)
{
- g_autoptr (AdwLeafletPage) page = NULL;
-
- page = g_list_model_get_item (G_LIST_MODEL (pages), position);
+ AdwLeafletPage *page = g_list_model_get_item (G_LIST_MODEL (pages), position);
g_assert_true (widget == adw_leaflet_page_get_child (page));
+
+ g_object_unref (page);
}
diff --git a/tests/test-status-page.c b/tests/test-status-page.c
index 7a49796148f8b038f8ff66d9d67566920e118ce1..3cb514f81f6e5f2292a784dc4788a287d5d85cde 100644
--- a/tests/test-status-page.c
+++ b/tests/test-status-page.c
@@ -46,7 +46,7 @@ static void
test_adw_status_page_title (void)
{
AdwStatusPage *status_page = ADW_STATUS_PAGE (g_object_ref_sink (adw_status_page_new ()));
- g_autofree char *title = NULL;
+ char *title;
g_assert_nonnull (status_page);
@@ -67,6 +67,7 @@ test_adw_status_page_title (void)
g_assert_cmpstr (adw_status_page_get_title (status_page), ==, "Other Title");
g_assert_cmpint (notified, ==, 2);
+ g_free (title);
g_assert_finalize_object (status_page);
}
@@ -74,7 +75,7 @@ static void
test_adw_status_page_description (void)
{
AdwStatusPage *status_page = ADW_STATUS_PAGE (g_object_ref_sink (adw_status_page_new ()));
- g_autofree char *description = NULL;
+ char *description;
g_assert_nonnull (status_page);
@@ -95,6 +96,7 @@ test_adw_status_page_description (void)
g_assert_cmpstr (adw_status_page_get_description (status_page), ==, "Other description");
g_assert_cmpint (notified, ==, 2);
+ g_free (description);
g_assert_finalize_object (status_page);
}
diff --git a/tests/test-tab-view.c b/tests/test-tab-view.c
index 04687867b0bce4404bc859bc404cf6927cc8704d..f2c9417df6e40855653f25341b91c8d4f7dbc211 100644
--- a/tests/test-tab-view.c
+++ b/tests/test-tab-view.c
@@ -160,7 +160,7 @@ test_adw_tab_view_default_icon (void)
AdwTabView *view = g_object_ref_sink (ADW_TAB_VIEW (adw_tab_view_new ()));
GIcon *icon1 = g_themed_icon_new ("go-previous-symbolic");
GIcon *icon2 = g_themed_icon_new ("go-next-symbolic");
- g_autofree char *icon_str = NULL;
+ char *icon_str;
g_assert_nonnull (view);
@@ -179,6 +179,7 @@ test_adw_tab_view_default_icon (void)
g_assert_true (adw_tab_view_get_default_icon (view) == icon2);
g_assert_cmpint (notified, ==, 2);
+ g_free (icon_str);
g_assert_finalize_object (view);
g_assert_finalize_object (icon1);
g_assert_finalize_object (icon2);
@@ -932,7 +933,7 @@ test_adw_tab_page_title (void)
{
AdwTabView *view = g_object_ref_sink (ADW_TAB_VIEW (adw_tab_view_new ()));
AdwTabPage *page;
- g_autofree char *title = NULL;
+ char *title;
g_assert_nonnull (view);
@@ -954,6 +955,7 @@ test_adw_tab_page_title (void)
g_assert_cmpstr (adw_tab_page_get_title (page), ==, "Some other title");
g_assert_cmpint (notified, ==, 2);
+ g_free (title);
g_assert_finalize_object (view);
}
@@ -962,7 +964,7 @@ test_adw_tab_page_tooltip (void)
{
AdwTabView *view = g_object_ref_sink (ADW_TAB_VIEW (adw_tab_view_new ()));
AdwTabPage *page;
- g_autofree char *tooltip = NULL;
+ char *tooltip;
g_assert_nonnull (view);
@@ -984,6 +986,7 @@ test_adw_tab_page_tooltip (void)
g_assert_cmpstr (adw_tab_page_get_tooltip (page), ==, "Some other tooltip");
g_assert_cmpint (notified, ==, 2);
+ g_free (tooltip);
g_assert_finalize_object (view);
}
diff --git a/tests/test-toast.c b/tests/test-toast.c
index ad293e88b03cb3350e615efefe6e8a3ebed5b6a6..26bdc59d7dd3b49c37e60341bf3c10b4205c0d0d 100644
--- a/tests/test-toast.c
+++ b/tests/test-toast.c
@@ -20,7 +20,7 @@ static void
test_adw_toast_title (void)
{
AdwToast *toast = adw_toast_new ("Title");
- g_autofree char *title = NULL;
+ char *title;
g_assert_nonnull (toast);
@@ -38,6 +38,7 @@ test_adw_toast_title (void)
g_assert_cmpstr (adw_toast_get_title (toast), ==, "Title");
g_assert_cmpint (notified, ==, 2);
+ g_free (title);
g_assert_finalize_object (toast);
}
@@ -95,10 +96,7 @@ static void
test_adw_toast_action_target (void)
{
AdwToast *toast = adw_toast_new ("Title");
- GVariant *action_target;
- g_autoptr (GVariant) variant1 = g_variant_ref_sink (g_variant_new_int32 (1));
- g_autoptr (GVariant) variant2 = g_variant_ref_sink (g_variant_new_int32 (2));
- g_autoptr (GVariant) variant3 = g_variant_ref_sink (g_variant_new_int32 (3));
+ GVariant *action_target, *variant;
g_assert_nonnull (toast);
@@ -108,17 +106,23 @@ test_adw_toast_action_target (void)
g_object_get (toast, "action-target", &action_target, NULL);
g_assert_null (action_target);
+ variant = g_variant_ref_sink (g_variant_new_int32 (1));
adw_toast_set_action_target_value (toast, g_variant_new_int32 (1));
- g_assert_cmpvariant (adw_toast_get_action_target_value (toast), variant1);
+ g_assert_cmpvariant (adw_toast_get_action_target_value (toast), variant);
g_assert_cmpint (notified, ==, 1);
+ g_variant_unref (variant);
+ variant = g_variant_ref_sink (g_variant_new_int32 (2));
g_object_set (toast, "action-target", g_variant_new_int32 (2), NULL);
- g_assert_cmpvariant (adw_toast_get_action_target_value (toast), variant2);
+ g_assert_cmpvariant (adw_toast_get_action_target_value (toast), variant);
g_assert_cmpint (notified, ==, 2);
+ g_variant_unref (variant);
+ variant = g_variant_ref_sink (g_variant_new_int32 (3));
adw_toast_set_action_target (toast, "i", 3);
- g_assert_cmpvariant (adw_toast_get_action_target_value (toast), variant3);
+ g_assert_cmpvariant (adw_toast_get_action_target_value (toast), variant);
g_assert_cmpint (notified, ==, 3);
+ g_variant_unref (variant);
g_assert_finalize_object (toast);
}
@@ -127,7 +131,7 @@ static void
test_adw_toast_detailed_action_name (void)
{
AdwToast *toast = adw_toast_new ("Title");
- g_autoptr (GVariant) variant = g_variant_ref_sink (g_variant_new_int32 (2));
+ GVariant *variant = g_variant_ref_sink (g_variant_new_int32 (2));
g_assert_nonnull (toast);
@@ -142,6 +146,7 @@ test_adw_toast_detailed_action_name (void)
g_assert_cmpstr (adw_toast_get_action_name (toast), ==, "win.something");
g_assert_cmpvariant (adw_toast_get_action_target_value (toast), variant);
+ g_variant_unref (variant);
g_assert_finalize_object (toast);
}
diff --git a/tests/test-window-title.c b/tests/test-window-title.c
index 0a5616fc6261d12716fda27eeffcca1243560b82..ec6c871eb40917f3f74208f34da7d8cc35d51925 100644
--- a/tests/test-window-title.c
+++ b/tests/test-window-title.c
@@ -20,7 +20,7 @@ static void
test_adw_window_title_title (void)
{
AdwWindowTitle *window_title = g_object_ref_sink (ADW_WINDOW_TITLE (adw_window_title_new ("Some title", NULL)));
- g_autofree char *title = NULL;
+ char *title;
g_assert_nonnull (window_title);
@@ -41,6 +41,7 @@ test_adw_window_title_title (void)
g_assert_cmpstr (adw_window_title_get_title (window_title), ==, "Yet another title");
g_assert_cmpint (notified, ==, 2);
+ g_free (title);
g_assert_finalize_object (window_title);
}
@@ -48,7 +49,7 @@ static void
test_adw_window_title_subtitle (void)
{
AdwWindowTitle *window_title = g_object_ref_sink (ADW_WINDOW_TITLE (adw_window_title_new (NULL, "Some subtitle")));
- g_autofree char *subtitle = NULL;
+ char *subtitle;
g_assert_nonnull (window_title);
@@ -69,6 +70,7 @@ test_adw_window_title_subtitle (void)
g_assert_cmpstr (adw_window_title_get_subtitle (window_title), ==, "Yet another subtitle");
g_assert_cmpint (notified, ==, 2);
+ g_free (subtitle);
g_assert_finalize_object (window_title);
}