[glib: 11/13] glib: Fix various compiler warnings when compiling with G_DISABLE_ASSERT



commit faa1d63cab9d7c412460b567915ad148d55986ae
Author: Philip Withnall <withnall endlessm com>
Date:   Tue Mar 5 12:23:41 2019 +0000

    glib: Fix various compiler warnings when compiling with G_DISABLE_ASSERT
    
    Mostly unused variables which are only used in a g_assert() call
    otherwise.
    
    Signed-off-by: Philip Withnall <withnall endlessm com>
    
    Helps: #1708

 glib/gdatetime.c        | 7 ++++++-
 glib/giochannel.c       | 4 ++++
 glib/gvariant-parser.c  | 2 +-
 glib/gvarianttype.c     | 4 ++++
 glib/gvarianttypeinfo.c | 2 ++
 5 files changed, 17 insertions(+), 2 deletions(-)
---
diff --git a/glib/gdatetime.c b/glib/gdatetime.c
index 8abf45a87..d8309f857 100644
--- a/glib/gdatetime.c
+++ b/glib/gdatetime.c
@@ -1304,7 +1304,10 @@ parse_iso8601_date (const gchar *text, gsize length,
 static GTimeZone *
 parse_iso8601_timezone (const gchar *text, gsize length, gssize *tz_offset)
 {
-  gint i, tz_length, offset_sign = 1, offset_hours, offset_minutes;
+  gint i, tz_length, offset_hours, offset_minutes;
+#ifndef G_DISABLE_ASSERT
+  gint offset_sign = 1;
+#endif
   GTimeZone *tz;
 
   /* UTC uses Z suffix  */
@@ -1318,7 +1321,9 @@ parse_iso8601_timezone (const gchar *text, gsize length, gssize *tz_offset)
   for (i = length - 1; i >= 0; i--)
     if (text[i] == '+' || text[i] == '-')
       {
+#ifndef G_DISABLE_ASSERT
         offset_sign = text[i] == '-' ? -1 : 1;
+#endif
         break;
       }
   if (i < 0)
diff --git a/glib/giochannel.c b/glib/giochannel.c
index 88fd8c81d..4fba3a5b0 100644
--- a/glib/giochannel.c
+++ b/glib/giochannel.c
@@ -1311,7 +1311,9 @@ g_io_channel_set_encoding (GIOChannel     *channel,
                           GError      **error)
 {
   GIConv read_cd, write_cd;
+#ifndef G_DISABLE_ASSERT
   gboolean did_encode;
+#endif
 
   g_return_val_if_fail (channel != NULL, G_IO_STATUS_ERROR);
   g_return_val_if_fail ((error == NULL) || (*error == NULL), G_IO_STATUS_ERROR);
@@ -1335,7 +1337,9 @@ g_io_channel_set_encoding (GIOChannel     *channel,
       channel->partial_write_buf[0] = '\0';
     }
 
+#ifndef G_DISABLE_ASSERT
   did_encode = channel->do_encode;
+#endif
 
   if (!encoding || strcmp (encoding, "UTF8") == 0 || strcmp (encoding, "UTF-8") == 0)
     {
diff --git a/glib/gvariant-parser.c b/glib/gvariant-parser.c
index 6061d614c..8876c7e2c 100644
--- a/glib/gvariant-parser.c
+++ b/glib/gvariant-parser.c
@@ -362,7 +362,7 @@ static void
 token_stream_assert (TokenStream *stream,
                      const gchar *token)
 {
-  gboolean correct_token;
+  gboolean correct_token G_GNUC_UNUSED  /* when compiling with G_DISABLE_ASSERT */;
 
   correct_token = token_stream_consume (stream, token);
   g_assert (correct_token);
diff --git a/glib/gvarianttype.c b/glib/gvarianttype.c
index b8c6cc195..1a228f73b 100644
--- a/glib/gvarianttype.c
+++ b/glib/gvarianttype.c
@@ -1084,12 +1084,16 @@ g_variant_type_key (const GVariantType *type)
 const GVariantType *
 g_variant_type_value (const GVariantType *type)
 {
+#ifndef G_DISABLE_ASSERT
   const gchar *type_string;
+#endif
 
   g_return_val_if_fail (g_variant_type_check (type), NULL);
 
+#ifndef G_DISABLE_ASSERT
   type_string = g_variant_type_peek_string (type);
   g_assert (type_string[0] == '{');
+#endif
 
   return g_variant_type_next (g_variant_type_key (type));
 }
diff --git a/glib/gvarianttypeinfo.c b/glib/gvarianttypeinfo.c
index bee0571b5..dc319caee 100644
--- a/glib/gvarianttypeinfo.c
+++ b/glib/gvarianttypeinfo.c
@@ -157,6 +157,7 @@ static void
 g_variant_type_info_check (const GVariantTypeInfo *info,
                            char                    container_class)
 {
+#ifndef G_DISABLE_ASSERT
   g_assert (!container_class || info->container_class == container_class);
 
   /* alignment can only be one of these */
@@ -185,6 +186,7 @@ g_variant_type_info_check (const GVariantTypeInfo *info,
       g_assert (0 <= index && index < 24);
       g_assert (g_variant_type_info_basic_chars[index][0] != ' ');
     }
+#endif  /* !G_DISABLE_ASSERT */
 }
 
 /* < private >


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