[glib/wip/gcleanup: 7/21] gcleanup: Fix noisy warnings about taking address of static variables



commit bae9fc5e92b4eedabd75c6c520f4300ef2b01fbe
Author: Stef Walter <stefw gnome org>
Date:   Thu Oct 31 10:18:22 2013 +0100

    gcleanup: Fix noisy warnings about taking address of static variables
    
    These are -Waddress warnings, which are valid warnings for most use
    cases of G_CLEANUP_ADD.
    
    It's not a big deal to have a NULL @data argument to G_CLEANUP_ADD.
    But what is a big deal is having a NULL @func. Add precondition
    checks for that.
    
    ie:
    
    gthread.c: In function 'g_thread_self':
    gthread.c:1006:147: warning: the comparison will always evaluate as 'true' for the address of 
'g_thread_specific_private' will never be NULL [-Waddress]
           G_CLEANUP_ADD (&g_thread_specific_private, g_private_reset);
                                                                                                              
                                         ^
    gthread.c:1006:303: warning: the address of 'g_thread_specific_private' will always evaluate as 'true' 
[-Waddress]
           G_CLEANUP_ADD (&g_thread_specific_private, g_private_reset);
                                                                                                              
                                                                                                              
                                                                                       ^
    
    https://bugzilla.gnome.org/show_bug.cgi?id=627423

 glib/gcleanup.c |    4 +++-
 glib/gcleanup.h |    5 +----
 2 files changed, 4 insertions(+), 5 deletions(-)
---
diff --git a/glib/gcleanup.c b/glib/gcleanup.c
index 065c7bd..89960c3 100644
--- a/glib/gcleanup.c
+++ b/glib/gcleanup.c
@@ -87,6 +87,8 @@ g_cleanup_list_add (GCleanupList *list,
 {
   GCleanupNode *node;
 
+  g_return_if_fail (cleanup_func != NULL);
+
   if (!g_cleanup_enabled)
     return;
 
@@ -157,7 +159,7 @@ g_cleanup_list_clear (GCleanupList *list)
 
 /**
  * G_CLEANUP_ADD:
- * @data: the data to free, non-%NULL
+ * @data: the data to free
  * @notify: the function used to free data
  *
  * Marks an item to be freed when performing memory cleanup.
diff --git a/glib/gcleanup.h b/glib/gcleanup.h
index 5262afe..27ae2bb 100644
--- a/glib/gcleanup.h
+++ b/glib/gcleanup.h
@@ -60,9 +60,7 @@ void                    g_cleanup_list_clear                            (GCleanu
   G_STMT_START {                                                                \
     extern GCleanupList _glib_cleanup_list;                                     \
     if (0) (func) ((data));                                                     \
-    g_warn_if_fail ((data) != NULL);                                            \
-    if (data)                                                                   \
-      g_cleanup_list_add (&_glib_cleanup_list, (void*) (func), (data));         \
+    g_cleanup_list_add (&_glib_cleanup_list, (void*) (func), (data));           \
   } G_STMT_END
 #define G_CLEANUP_ADD_FUNC(func) \
   G_STMT_START {                                                                \
@@ -76,7 +74,6 @@ void                    g_cleanup_list_clear                            (GCleanu
 #define G_CLEANUP_DEFINE
 #define G_CLEANUP_ADD(data, func) \
   G_STMT_START {                                                        \
-    g_warn_if_fail ((data) != NULL);                                    \
     if (0) (func) (data);                                               \
   } G_STMT_END
 #define G_CLEANUP_ADD_FUNC(func) \


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