From b41bff1fe928a530ac63601deca8f87cb2e062f8 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Tue, 22 May 2018 21:00:04 +0000 Subject: gmacros: Add G_GNUC_UNUSED for autoptr funcs (notably GLists) In commit f49a93b20761a0be51b22c481503b4cda0f7264f from bug https://bugzilla.gnome.org/show_bug.cgi?id=791342 we added two new static inline cleanup helpers in case a type was used inside a list. These functions will commonly be unused. In rpm-ostree, we run a build using `CC=clang -Werror=unused` because it catches `g_autofree char *foo = NULL;` as unused, but GCC doesn't. When trying to update to F28 with a newer glib, our CI fell over on this. Mark all of the autocleanups as "maybe unused". --- glib/gmacros.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/glib/gmacros.h b/glib/gmacros.h index 55fb81e5b..03876d8ce 100644 --- a/glib/gmacros.h +++ b/glib/gmacros.h @@ -482,9 +482,9 @@ typedef GList *_GLIB_AUTOPTR_LIST_TYPENAME(TypeName); \ typedef GSList *_GLIB_AUTOPTR_SLIST_TYPENAME(TypeName); \ G_GNUC_BEGIN_IGNORE_DEPRECATIONS \ - static inline void _GLIB_AUTOPTR_FUNC_NAME(TypeName) (TypeName **_ptr) { if (*_ptr) (func) (*_ptr); } \ - static inline void _GLIB_AUTOPTR_LIST_FUNC_NAME(TypeName) (GList **_l) { g_list_free_full (*_l, (GDestroyNotify) func); } \ - static inline void _GLIB_AUTOPTR_SLIST_FUNC_NAME(TypeName) (GSList **_l) { g_slist_free_full (*_l, (GDestroyNotify) func); } \ + static G_GNUC_UNUSED inline void _GLIB_AUTOPTR_FUNC_NAME(TypeName) (TypeName **_ptr) { if (*_ptr) (func) (*_ptr); } \ + static G_GNUC_UNUSED inline void _GLIB_AUTOPTR_LIST_FUNC_NAME(TypeName) (GList **_l) { g_list_free_full (*_l, (GDestroyNotify) func); } \ + static G_GNUC_UNUSED inline void _GLIB_AUTOPTR_SLIST_FUNC_NAME(TypeName) (GSList **_l) { g_slist_free_full (*_l, (GDestroyNotify) func); } \ G_GNUC_END_IGNORE_DEPRECATIONS #define G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(TypeName, func) \ G_GNUC_BEGIN_IGNORE_DEPRECATIONS \ -- cgit v1.2.1 From c7d11d3418a7eafb2946a28946b902147d8230ed Mon Sep 17 00:00:00 2001 From: "Jan Alexander Steffens (heftig)" Date: Fri, 25 May 2018 14:11:30 +0200 Subject: macros: Double-cast func for g_autolist to avoid warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For g_autolist and g_autoslist, the cleanup func was cast to GDestroyNotify before being passed to g_(s)list_free_full. This cast provokes GCC 8 to emit a warning if the return type is not void: …/gmacros.h:462:99: warning: cast between incompatible function types from … to 'void (*)(void *)' [-Wcast-function-type] Cast to 'void (*)(void)' first, which suppresses the warning as recommended by the GCC documentation. g_autoptr remains untouched. Fixes https://gitlab.gnome.org/GNOME/glib/issues/1382 --- glib/gmacros.h | 4 ++-- glib/tests/autoptr.c | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/glib/gmacros.h b/glib/gmacros.h index 03876d8ce..0e180bb09 100644 --- a/glib/gmacros.h +++ b/glib/gmacros.h @@ -483,8 +483,8 @@ typedef GSList *_GLIB_AUTOPTR_SLIST_TYPENAME(TypeName); \ G_GNUC_BEGIN_IGNORE_DEPRECATIONS \ static G_GNUC_UNUSED inline void _GLIB_AUTOPTR_FUNC_NAME(TypeName) (TypeName **_ptr) { if (*_ptr) (func) (*_ptr); } \ - static G_GNUC_UNUSED inline void _GLIB_AUTOPTR_LIST_FUNC_NAME(TypeName) (GList **_l) { g_list_free_full (*_l, (GDestroyNotify) func); } \ - static G_GNUC_UNUSED inline void _GLIB_AUTOPTR_SLIST_FUNC_NAME(TypeName) (GSList **_l) { g_slist_free_full (*_l, (GDestroyNotify) func); } \ + static G_GNUC_UNUSED inline void _GLIB_AUTOPTR_LIST_FUNC_NAME(TypeName) (GList **_l) { g_list_free_full (*_l, (GDestroyNotify) (void(*)(void)) func); } \ + static G_GNUC_UNUSED inline void _GLIB_AUTOPTR_SLIST_FUNC_NAME(TypeName) (GSList **_l) { g_slist_free_full (*_l, (GDestroyNotify) (void(*)(void)) func); } \ G_GNUC_END_IGNORE_DEPRECATIONS #define G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(TypeName, func) \ G_GNUC_BEGIN_IGNORE_DEPRECATIONS \ diff --git a/glib/tests/autoptr.c b/glib/tests/autoptr.c index 408f14b6c..c8c130d5c 100644 --- a/glib/tests/autoptr.c +++ b/glib/tests/autoptr.c @@ -1,6 +1,12 @@ #include #include +typedef struct _HNVC HasNonVoidCleanup; +HasNonVoidCleanup * non_void_cleanup (HasNonVoidCleanup *); + +/* Should not cause any warnings with -Wextra */ +G_DEFINE_AUTOPTR_CLEANUP_FUNC(HasNonVoidCleanup, non_void_cleanup) + static void test_autofree (void) { -- cgit v1.2.1