Silence -Wcast-qual warnings
authorRan Benita <ran234@gmail.com>
Fri, 23 Mar 2012 22:29:33 +0000 (00:29 +0200)
committerDaniel Stone <daniel@fooishbar.org>
Tue, 27 Mar 2012 13:15:11 +0000 (14:15 +0100)
There are some cases where we must free a string with a const qualifier.
Add a macro UNCONSTIFY to trick the compiler into silencing the warning
in the cases where we know what we're doing.

Signed-off-by: Ran Benita <ran234@gmail.com>
src/alloc.c
src/malloc.c
src/utils.h
src/xkbcomp/indicators.c
src/xkbcomp/keycodes.c
src/xkbcomp/symbols.c

index 1a46fbb..3b4e33a 100644 (file)
@@ -181,18 +181,18 @@ XkbcFreeNames(struct xkb_desc * xkb)
         for (i = 0; i < map->num_types; i++, type++) {
             int j;
             for (j = 0; j < type->num_levels; j++)
-                free((char *) type->level_names[i]);
+                free(UNCONSTIFY(type->level_names[i]));
             free(type->level_names);
             type->level_names = NULL;
         }
     }
 
     for (i = 0; i < XkbNumVirtualMods; i++)
-        free((char *) names->vmods[i]);
+        free(UNCONSTIFY(names->vmods[i]));
     for (i = 0; i < XkbNumIndicators; i++)
-        free((char *) names->indicators[i]);
+        free(UNCONSTIFY(names->indicators[i]));
     for (i = 0; i < XkbNumKbdGroups; i++)
-        free((char *) names->groups[i]);
+        free(UNCONSTIFY(names->groups[i]));
 
     free(names->keys);
     free(names->key_aliases);
index cff30d7..3818cdd 100644 (file)
@@ -225,7 +225,7 @@ XkbcCopyKeyType(struct xkb_key_type * from, struct xkb_key_type * into)
     free(into->preserve);
     into->preserve= NULL;
     for (i = 0; i < into->num_levels; i++)
-        free((char *) into->level_names[i]);
+        free(UNCONSTIFY(into->level_names[i]));
     free(into->level_names);
     into->level_names = NULL;
 
@@ -401,9 +401,9 @@ XkbcFreeClientMap(struct xkb_desc * xkb)
         free(type->map);
         free(type->preserve);
         for (j = 0; j < type->num_levels; j++)
-            free((char *) type->level_names[j]);
+            free(UNCONSTIFY(type->level_names[j]));
         free(type->level_names);
-        free((char *) type->name);
+        free(UNCONSTIFY(type->name));
     }
     free(map->types);
     free(map->key_sym_map);
index cbf3552..630fa48 100644 (file)
 extern void *
 recalloc(void *ptr, size_t old_size, size_t new_size);
 
+/*
+ * We sometimes malloc strings and then expose them as const char*'s. This
+ * macro is used when we free these strings in order to avoid -Wcast-qual
+ * errors.
+ */
+#define UNCONSTIFY(const_ptr) ((void *)(uintptr_t)(const_ptr))
+
 #define uTypedAlloc(t)              malloc(sizeof(t))
 #define uTypedCalloc(n, t)          calloc((n), sizeof(t))
 #define uTypedRealloc(pO, n, t)     realloc((pO), (n) * sizeof(t))
index ed40be1..5f00916 100644 (file)
@@ -423,7 +423,7 @@ CopyIndicatorMapDefs(struct xkb_desc * xkb, LEDInfo *leds, LEDInfo **unboundRtrn
             im->ctrls = led->ctrls;
             if (xkb->names != NULL)
             {
-                free((char *) xkb->names->indicators[led->indicator - 1]);
+                free(UNCONSTIFY(xkb->names->indicators[led->indicator - 1]));
                 xkb->names->indicators[led->indicator-1] = XkbcAtomGetString(led->name);
             }
             free(led);
index 50d8484..6a05dc2 100644 (file)
@@ -914,7 +914,7 @@ CompileKeycodes(XkbFile *file, struct xkb_desc * xkb, unsigned merge)
             for (ii = info.leds; ii != NULL;
                  ii = (IndicatorNameInfo *) ii->defs.next)
             {
-                free((char *) xkb->names->indicators[ii->ndx - 1]);
+                free(UNCONSTIFY(xkb->names->indicators[ii->ndx - 1]));
                 xkb->names->indicators[ii->ndx - 1] = XkbcAtomGetString(ii->name);
                 if (xkb->indicators != NULL)
                 {
index 8e00038..188d649 100644 (file)
@@ -2017,7 +2017,7 @@ CompileSymbols(XkbFile *file, struct xkb_desc * xkb, unsigned merge)
         {
             if (info.groupNames[i] != None)
             {
-                free((char *) xkb->names->groups[i]);
+                free(UNCONSTIFY(xkb->names->groups[i]));
                 xkb->names->groups[i] = XkbcAtomGetString(info.groupNames[i]);
             }
         }