From ac6b983963d38f43b7838055b3305589609f1dde Mon Sep 17 00:00:00 2001 From: Chun-wei Fan Date: Mon, 26 Jul 2021 18:51:55 +0800 Subject: [PATCH 01/10] build: Force-include msvc_recommended_pragmas.h on MSVC This will cover much of the compiler flags that we use for GCC-like compilers to ensure that the code do not trigger compiler warnings that we want to be wary of. --- meson.build | 94 ++++++++++++++++++++++++++++------------------------- 1 file changed, 50 insertions(+), 44 deletions(-) diff --git a/meson.build b/meson.build index 41931b4c4..23a43a584 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 -- GitLab From 8c6e7336a6e0eb36127f932fa3b076ccd4d14433 Mon Sep 17 00:00:00 2001 From: Chun-wei Fan Date: Tue, 11 Jan 2022 17:13:45 +0800 Subject: [PATCH 02/10] build: Redo gen-public-types.sh in Python This way, we make builds easier in environments that do not have a unix-like shell and/or sed available, such as on Visual Studio and clang-cl. For Visual Studio builds, this means that we no longer need to have a separate Cygwin or MSYS2 installation to carry out the build. --- src/gen-public-types.py | 32 ++++++++++++++++++++++++++++++++ src/gen-public-types.sh | 22 ---------------------- src/meson.build | 3 +-- 3 files changed, 33 insertions(+), 24 deletions(-) create mode 100644 src/gen-public-types.py delete mode 100644 src/gen-public-types.sh diff --git a/src/gen-public-types.py b/src/gen-public-types.py new file mode 100644 index 000000000..04adc58c9 --- /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 b99aa87e2..000000000 --- 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 1ed528a09..cfd520540 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', -- GitLab From 9d290030e3150b0b169f2df45e1e3b04d26f1e26 Mon Sep 17 00:00:00 2001 From: Chun-wei Fan Date: Mon, 26 Jul 2021 18:55:43 +0800 Subject: [PATCH 03/10] build: Don't use PIE/PIC for MSVC-like compilers It's not supported nor needed. --- tests/meson.build | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/meson.build b/tests/meson.build index e133e7e26..6c2a20663 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 -- GitLab From 9fd002e0053047648ebcddae112704b5c1838f5b Mon Sep 17 00:00:00 2001 From: Chun-wei Fan Date: Tue, 18 Jan 2022 11:58:29 +0800 Subject: [PATCH 04/10] build: Skip building examples on MSVC ...and revert the changes to drop g_autoptr() there. --- examples/meson.build | 7 +++++++ meson_options.txt | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/examples/meson.build b/examples/meson.build index bbacb3f44..a2a05fc6a 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_options.txt b/meson_options.txt index a136a9636..b95d0ae4a 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)') -- GitLab From 9395f52a00694ffd8470fa8eed86b0a6d17f984e Mon Sep 17 00:00:00 2001 From: Chun-wei Fan Date: Fri, 29 Oct 2021 17:51:51 +0800 Subject: [PATCH 05/10] demo: Don't try building appstream items on Windows This simply does not exist on Windows --- demo/data/meson.build | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/demo/data/meson.build b/demo/data/meson.build index 612410c5f..27f977345 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() -- GitLab From 6aea1ea44bcea44e0664892a0624e847f2b7253e Mon Sep 17 00:00:00 2001 From: Chun-wei Fan Date: Thu, 30 Dec 2021 13:52:45 +0800 Subject: [PATCH 06/10] tab: Avoid empty initializers Visual Studio does not like empty initializers for structs, but since we are indeed initializing all fields of the struct before using it, just declare the variables unintialized instead. --- src/adw-tab.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/adw-tab.c b/src/adw-tab.c index 6d344cc6d..85fbc857b 100644 --- a/src/adw-tab.c +++ b/src/adw-tab.c @@ -410,7 +410,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; -- GitLab From 4aef389116a7b5de0ff72dde59544d2a6f370c56 Mon Sep 17 00:00:00 2001 From: Chun-wei Fan Date: Tue, 12 Oct 2021 16:08:08 +0800 Subject: [PATCH 07/10] settings: Don't use portal on Windows xdg-desktop-portal is not and will likely not be available for Windows --- src/adw-settings.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/adw-settings.c b/src/adw-settings.c index 6c4420fdd..0aa87b87b 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) { @@ -281,6 +282,7 @@ init_portal (AdwSettings *self) g_signal_connect (self->settings_portal, "g-signal", G_CALLBACK (settings_portal_changed_cb), self); } +#endif /* GSettings */ @@ -396,7 +398,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); -- GitLab From 4e1160cc3f30705e352aa35caac6a8b7bd7931f8 Mon Sep 17 00:00:00 2001 From: Chun-wei Fan Date: Wed, 19 Jan 2022 14:05:10 +0500 Subject: [PATCH 08/10] settings: Don't check for Flatpak on Windows --- src/adw-settings.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/adw-settings.c b/src/adw-settings.c index 0aa87b87b..4db10809b 100644 --- a/src/adw-settings.c +++ b/src/adw-settings.c @@ -286,11 +286,13 @@ init_portal (AdwSettings *self) /* 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) @@ -311,10 +313,12 @@ init_gsettings (AdwSettings *self) g_autoptr (GSettingsSchema) schema = NULL; g_autoptr (GSettingsSchema) a11y_schema = NULL; +#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 (); -- GitLab From c2d77ba76d02bd5351db50e501ff048c4ad691ba Mon Sep 17 00:00:00 2001 From: Chun-wei Fan Date: Mon, 26 Jul 2021 18:58:32 +0800 Subject: [PATCH 09/10] 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/adwaita-demo.c | 3 +- .../animations/adw-demo-page-animations.c | 4 +- demo/pages/avatar/adw-demo-page-avatar.c | 28 ++++-- .../pages/tab-view/adw-tab-view-demo-window.c | 20 +++- demo/pages/toasts/adw-demo-page-toasts.c | 24 ++--- src/adw-application.c | 10 +- src/adw-avatar.c | 39 +++++--- src/adw-carousel-indicator-dots.c | 11 ++- src/adw-carousel-indicator-lines.c | 11 ++- src/adw-combo-row.c | 15 ++- src/adw-fading-label.c | 8 +- src/adw-indicator-bin.c | 8 +- src/adw-preferences-window.c | 52 ++++++---- src/adw-settings.c | 98 +++++++++++-------- src/adw-style-manager.c | 4 +- src/adw-swipe-tracker.c | 27 +++-- src/adw-tab-box.c | 7 +- src/adw-tab-view.c | 8 +- src/adw-tab.c | 4 +- src/adw-toast.c | 18 ++-- src/adw-view-switcher.c | 7 +- tests/test-button-content.c | 6 +- tests/test-easing.c | 9 +- tests/test-leaflet.c | 6 +- tests/test-status-page.c | 6 +- tests/test-tab-view.c | 9 +- tests/test-toast.c | 23 +++-- tests/test-window-title.c | 6 +- 28 files changed, 306 insertions(+), 165 deletions(-) diff --git a/demo/adwaita-demo.c b/demo/adwaita-demo.c index e00ca1105..54bbb1def 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/pages/animations/adw-demo-page-animations.c b/demo/pages/animations/adw-demo-page-animations.c index 624760531..0ab807eaf 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 05ad55c68..fb935e063 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 cda44c92b..15078c247 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 4b6791047..f23043413 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/src/adw-application.c b/src/adw-application.c index 0c2dc412f..ee9c04ef4 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 dec89921b..bb19c5afb 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 b2c338934..a23b8ab81 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 c569268d1..bf851049b 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 2b541ad74..648781164 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 08d0cf014..e9a685e12 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 6f79f2bc7..cc2c7e168 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 3a074d416..bb69eeb5d 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 4db10809b..11a54bdb7 100644 --- a/src/adw-settings.c +++ b/src/adw-settings.c @@ -100,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", @@ -117,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; } @@ -147,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 @@ -201,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; @@ -213,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; } @@ -221,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; } @@ -228,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; } } @@ -235,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; @@ -253,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) @@ -310,8 +321,7 @@ 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 @@ -334,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"); @@ -348,6 +360,8 @@ init_gsettings (AdwSettings *self) "changed::high-contrast", G_CALLBACK (gsettings_high_contrast_changed_cb), self); + + g_settings_schema_unref (schema); } } @@ -356,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); @@ -365,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"); } diff --git a/src/adw-style-manager.c b/src/adw-style-manager.c index bf9dd5b6d..05cfc0f44 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 7825e8810..9c557b92e 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 14a1902a6..4afc11fee 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 e0032b2d1..b81beebab 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 85fbc857b..6d8a8ebda 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 diff --git a/src/adw-toast.c b/src/adw-toast.c index f72f74d4d..b996507a8 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 6f514c635..14812d806 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/tests/test-button-content.c b/tests/test-button-content.c index 5d5ba196b..139910383 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 58ba62871..470f13c8d 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 39f7aeed9..677a17dcf 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 7a4979614..3cb514f81 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 04687867b..f2c9417df 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 ad293e88b..26bdc59d7 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 0a5616fc6..ec6c871eb 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); } -- GitLab From 70d2b761f40a2a62557f7af4bc37bec677c27745 Mon Sep 17 00:00:00 2001 From: Alexander Mikhaylenko Date: Wed, 19 Jan 2022 15:46:11 +0500 Subject: [PATCH 10/10] hacking: Remove the automated cleanup section --- HACKING.md | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/HACKING.md b/HACKING.md index 81e02a8ca..487a5dcb0 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. -- GitLab