From 97c28f7fe1ffa7bc33cda0a0de20b375db9f6594 Mon Sep 17 00:00:00 2001 From: Christoph Reiter Date: Wed, 25 Apr 2018 16:07:59 +0200 Subject: [PATCH] ci: fix warnings and enable --werror for the mingw build Fix various warnings regarding unused variables, duplicated branches etc by adjusting the ifdeffery and some missing casts. gnulib triggers -Wduplicated-branches in one of the copied files, disable as that just makes updating the code harder. The warning indicating missing features are made none fatal through pragmas. They still show but don't abort the build. https://bugzilla.gnome.org/show_bug.cgi?id=793729 --- .gitlab-ci/test-msys2.sh | 3 +-- gio/gcredentials.c | 3 +++ gio/gdbusauthmechanismexternal.c | 3 +++ gio/gdbusauthmechanismsha1.c | 3 +++ gio/glocalfile.c | 2 ++ gio/glocalfileinfo.c | 6 ++++-- gio/glocalvfs.c | 13 +++++++++---- gio/gregistrysettingsbackend.c | 2 +- gio/gsocket.c | 4 ++-- glib/gmessages.c | 1 - glib/gnulib/meson.build | 3 ++- glib/gslice.c | 6 ++++++ glib/gspawn-win32.c | 1 - glib/tests/mainloop.c | 4 ++++ 14 files changed, 40 insertions(+), 14 deletions(-) diff --git a/.gitlab-ci/test-msys2.sh b/.gitlab-ci/test-msys2.sh index 91384cf44..44b32e654 100755 --- a/.gitlab-ci/test-msys2.sh +++ b/.gitlab-ci/test-msys2.sh @@ -26,8 +26,7 @@ mkdir -p _ccache export CCACHE_BASEDIR="$(pwd)" export CCACHE_DIR="${CCACHE_BASEDIR}/_ccache" -# FIXME: Add --werror -meson --buildtype debug _build +meson --werror --buildtype debug _build cd _build ninja diff --git a/gio/gcredentials.c b/gio/gcredentials.c index 2e050776c..cc0cd82ce 100644 --- a/gio/gcredentials.c +++ b/gio/gcredentials.c @@ -95,7 +95,10 @@ struct _GCredentials ucred_t *native; #else #ifdef __GNUC__ + #pragma GCC diagnostic push + #pragma GCC diagnostic warning "-Wcpp" #warning Please add GCredentials support for your OS + #pragma GCC diagnostic pop #endif #endif }; diff --git a/gio/gdbusauthmechanismexternal.c b/gio/gdbusauthmechanismexternal.c index ec23dde09..182c57278 100644 --- a/gio/gdbusauthmechanismexternal.c +++ b/gio/gdbusauthmechanismexternal.c @@ -348,7 +348,10 @@ mechanism_client_initiate (GDBusAuthMechanism *mechanism, *out_initial_response_len = strlen (initial_response); #elif defined(G_OS_WIN32) #ifdef __GNUC__ +#pragma GCC diagnostic push +#pragma GCC diagnostic warning "-Wcpp" #warning Dont know how to send credentials on this OS. The EXTERNAL D-Bus authentication mechanism will not work. +#pragma GCC diagnostic pop #endif m->priv->state = G_DBUS_AUTH_MECHANISM_STATE_REJECTED; #endif diff --git a/gio/gdbusauthmechanismsha1.c b/gio/gdbusauthmechanismsha1.c index f6525c07d..aba9cea59 100644 --- a/gio/gdbusauthmechanismsha1.c +++ b/gio/gdbusauthmechanismsha1.c @@ -280,7 +280,10 @@ ensure_keyring_directory (GError **error) } #else #ifdef __GNUC__ +#pragma GCC diagnostic push +#pragma GCC diagnostic warning "-Wcpp" #warning Please implement permission checking on this non-UNIX platform +#pragma GCC diagnostic pop #endif #endif } diff --git a/gio/glocalfile.c b/gio/glocalfile.c index e7481454e..652f2d7ad 100644 --- a/gio/glocalfile.c +++ b/gio/glocalfile.c @@ -2819,7 +2819,9 @@ g_local_file_measure_size_of_file (gint parent_fd, if (S_ISDIR (buf.st_mode)) { int dir_fd = -1; +#ifdef AT_FDCWD int errsv; +#endif if (g_cancellable_set_error_if_cancelled (state->cancellable, error)) return FALSE; diff --git a/gio/glocalfileinfo.c b/gio/glocalfileinfo.c index 50d870fb7..801695ad0 100644 --- a/gio/glocalfileinfo.c +++ b/gio/glocalfileinfo.c @@ -897,19 +897,21 @@ get_access_rights (GFileAttributeMatcher *attribute_matcher, writable = FALSE; if (parent_info->writable) { +#ifdef G_OS_WIN32 + writable = TRUE; +#else if (parent_info->is_sticky) { -#ifndef G_OS_WIN32 uid_t uid = geteuid (); if (uid == statbuf->st_uid || uid == parent_info->owner || uid == 0) -#endif writable = TRUE; } else writable = TRUE; +#endif } if (_g_file_attribute_matcher_matches_id (attribute_matcher, G_FILE_ATTRIBUTE_ID_ACCESS_CAN_RENAME)) diff --git a/gio/glocalvfs.c b/gio/glocalvfs.c index 4f1462de9..c29d071b7 100644 --- a/gio/glocalvfs.c +++ b/gio/glocalvfs.c @@ -129,7 +129,7 @@ g_local_vfs_parse_name (GVfs *vfs, GFile *file; char *filename; char *user_prefix; - const char *user_start, *user_end; + const char *user_end; char *rest; g_return_val_if_fail (G_IS_VFS (vfs), NULL); @@ -141,19 +141,22 @@ g_local_vfs_parse_name (GVfs *vfs, { if (*parse_name == '~') { +#ifdef G_OS_UNIX + const char *user_start; + user_start = parse_name + 1; +#endif parse_name ++; - user_start = parse_name; while (*parse_name != 0 && *parse_name != '/') parse_name++; user_end = parse_name; +#ifdef G_OS_UNIX if (user_end == user_start) user_prefix = g_strdup (g_get_home_dir ()); else { -#ifdef G_OS_UNIX struct passwd *passwd_file_entry; char *user_name; @@ -165,9 +168,11 @@ g_local_vfs_parse_name (GVfs *vfs, passwd_file_entry->pw_dir != NULL) user_prefix = g_strdup (passwd_file_entry->pw_dir); else -#endif user_prefix = g_strdup (g_get_home_dir ()); } +#else + user_prefix = g_strdup (g_get_home_dir ()); +#endif rest = NULL; if (*user_end != 0) diff --git a/gio/gregistrysettingsbackend.c b/gio/gregistrysettingsbackend.c index 23a96486f..70d391a32 100644 --- a/gio/gregistrysettingsbackend.c +++ b/gio/gregistrysettingsbackend.c @@ -1800,7 +1800,7 @@ watch_thread_function (LPVOID parameter) * likely to block (only when changing notification subscriptions). */ event = g_slice_new (RegistryEvent); - event->self = g_object_ref (self->owner); + event->self = G_REGISTRY_BACKEND (g_object_ref (self->owner)); event->prefix = g_strdup (prefix); event->items = g_ptr_array_new_with_free_func (g_free); diff --git a/gio/gsocket.c b/gio/gsocket.c index b4a941eb1..11be2e738 100644 --- a/gio/gsocket.c +++ b/gio/gsocket.c @@ -572,7 +572,7 @@ g_socket (gint domain, if (fd < 0) { - int errsv = get_socket_errno (); + errsv = get_socket_errno (); g_set_error (error, G_IO_ERROR, socket_io_error_from_errno (errsv), _("Unable to create socket: %s"), socket_strerror (errsv)); @@ -3251,7 +3251,7 @@ g_socket_send_with_timeout (GSocket *socket, { win32_unset_event_mask (socket, FD_WRITE); - if ((ret = send (socket->priv->fd, buffer, size, G_SOCKET_DEFAULT_SEND_FLAGS)) < 0) + if ((ret = send (socket->priv->fd, (const char *)buffer, size, G_SOCKET_DEFAULT_SEND_FLAGS)) < 0) { int errsv = get_socket_errno (); diff --git a/glib/gmessages.c b/glib/gmessages.c index fb1108f9b..eaca78387 100644 --- a/glib/gmessages.c +++ b/glib/gmessages.c @@ -1533,7 +1533,6 @@ static gboolean win32_is_pipe_tty (int fd) { gboolean result = FALSE; - int error; HANDLE h_fd; FILE_NAME_INFO *info = NULL; gint info_size = sizeof (FILE_NAME_INFO) + sizeof (WCHAR) * MAX_PATH; diff --git a/glib/gnulib/meson.build b/glib/gnulib/meson.build index dac3af739..345e11026 100644 --- a/glib/gnulib/meson.build +++ b/glib/gnulib/meson.build @@ -1,6 +1,7 @@ # glib enables -Werror=format-nonliteral by default, but the embedded gnulib # needs to handle user provided format strings. -extra_gnulib_args = cc.get_supported_arguments(['-Wno-format-nonliteral']) +extra_gnulib_args = cc.get_supported_arguments([ + '-Wno-format-nonliteral', '-Wno-duplicated-branches']) gnulib_lib = static_library('gnulib', 'asnprintf.c', 'printf.c', 'printf-args.c', 'printf-parse.c', 'vasnprintf.c', include_directories : [configinc, glibinc], diff --git a/glib/gslice.c b/glib/gslice.c index 454c8a602..6b0f22687 100644 --- a/glib/gslice.c +++ b/glib/gslice.c @@ -1432,11 +1432,15 @@ allocator_memalign (gsize alignment, guint8 *amem = (guint8*) ALIGN ((gsize) mem, sys_page_size); if (amem != mem) i--; /* mem wasn't page aligned */ + G_GNUC_BEGIN_IGNORE_DEPRECATIONS while (--i >= 0) g_trash_stack_push (&compat_valloc_trash, amem + i * sys_page_size); + G_GNUC_END_IGNORE_DEPRECATIONS } } + G_GNUC_BEGIN_IGNORE_DEPRECATIONS aligned_memory = g_trash_stack_pop (&compat_valloc_trash); + G_GNUC_END_IGNORE_DEPRECATIONS #endif if (!aligned_memory) errno = err; @@ -1451,7 +1455,9 @@ allocator_memfree (gsize memsize, free (mem); #else mem_assert (memsize <= sys_page_size); + G_GNUC_BEGIN_IGNORE_DEPRECATIONS g_trash_stack_push (&compat_valloc_trash, mem); + G_GNUC_END_IGNORE_DEPRECATIONS #endif } diff --git a/glib/gspawn-win32.c b/glib/gspawn-win32.c index 8ed10d685..636e9ebe8 100644 --- a/glib/gspawn-win32.c +++ b/glib/gspawn-win32.c @@ -544,7 +544,6 @@ do_spawn_with_pipes (gint *exit_status, GError *conv_error = NULL; gint conv_error_index; gchar *helper_process; - CONSOLE_CURSOR_INFO cursor_info; wchar_t *whelper, **wargv, **wenvp; gchar *glib_dll_directory; diff --git a/glib/tests/mainloop.c b/glib/tests/mainloop.c index f5d672a63..dd219cf6c 100644 --- a/glib/tests/mainloop.c +++ b/glib/tests/mainloop.c @@ -1150,6 +1150,7 @@ read_bytes (gint fd, return TRUE; } +#ifdef G_OS_UNIX static void test_unix_fd (void) { @@ -1206,6 +1207,7 @@ test_unix_fd (void) close (fds[1]); close (fds[0]); } +#endif static void assert_main_context_state (gint n_to_poll, @@ -1513,6 +1515,7 @@ test_unix_file_poll (void) #endif +#ifdef G_OS_UNIX static gboolean timeout_cb (gpointer data) { @@ -1564,6 +1567,7 @@ test_mainloop_wait (void) g_main_context_unref (context); } +#endif static gboolean nfds_in_cb (GIOChannel *io,