[glib: 2/3] macros: Double-cast func for g_autolist to avoid warning



commit c7d11d3418a7eafb2946a28946b902147d8230ed
Author: Jan Alexander Steffens (heftig) <jan steffens gmail com>
Date:   Fri May 25 14:11:30 2018 +0200

    macros: Double-cast func for g_autolist to avoid warning
    
    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 <glib.h>
 #include <string.h>
 
+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)
 {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]