[PATCH 02/11] Make InputAttributes strings const

Dan Nicholson dbn.lists at gmail.com
Thu May 20 07:09:04 PDT 2010


From: Julien Cristau <jcristau at debian.org>

Signed-off-by: Julien Cristau <jcristau at debian.org>
Reviewed-by: Dan Nicholson <dbn.lists at gmail.com>
---
 config/hal.c                   |   21 +++++++++++----------
 config/udev.c                  |   10 ++++++----
 hw/xfree86/common/xf86Xinput.c |    2 +-
 include/input.h                |    8 ++++----
 4 files changed, 22 insertions(+), 19 deletions(-)

diff --git a/config/hal.c b/config/hal.c
index 6a22323..33864c5 100644
--- a/config/hal.c
+++ b/config/hal.c
@@ -129,6 +129,8 @@ static void
 device_added(LibHalContext *hal_ctx, const char *udi)
 {
     char *path = NULL, *driver = NULL, *name = NULL, *config_info = NULL;
+    char **tags = NULL;
+    char *vendor = NULL;
     InputOption *options = NULL, *tmpo = NULL;
     InputAttributes attrs = {0};
     DeviceIntPtr dev = NULL;
@@ -155,16 +157,17 @@ device_added(LibHalContext *hal_ctx, const char *udi)
         LogMessage(X_WARNING,"config/hal: no driver or path specified for %s\n", udi);
         goto unwind;
     }
-    attrs.device = xstrdup(path);
+    attrs.device = path;
 
     name = get_prop_string(hal_ctx, udi, "info.product");
     if (!name)
         name = xstrdup("(unnamed)");
     else
-        attrs.product = xstrdup(name);
+        attrs.product = name;
 
-    attrs.vendor = get_prop_string(hal_ctx, udi, "info.vendor");
-    attrs.tags = xstrtokenize(get_prop_string(hal_ctx, udi, "input.tags"), ",");
+    attrs.vendor = vendor = get_prop_string(hal_ctx, udi, "info.vendor");
+    tags = xstrtokenize(get_prop_string(hal_ctx, udi, "input.tags"), ",");
+    attrs.tags = (const char * const *)tags;
 
     if (libhal_device_query_capability(hal_ctx, udi, "input.keys", NULL))
         attrs.flags |= ATTR_KEYBOARD;
@@ -389,16 +392,14 @@ unwind:
         free(tmpo);
     }
 
-    free(attrs.product);
-    free(attrs.vendor);
-    free(attrs.device);
-    if (attrs.tags) {
-        char **tag = attrs.tags;
+    free(vendor);
+    if (tags) {
+        char **tag = tags;
         while (*tag) {
             free(*tag);
             tag++;
         }
-        free(attrs.tags);
+        free(tags);
     }
 
     if (xkb_opts.layout)
diff --git a/config/udev.c b/config/udev.c
index 5e8d8da..201506a 100644
--- a/config/udev.c
+++ b/config/udev.c
@@ -46,6 +46,7 @@ device_added(struct udev_device *udev_device)
     char *config_info = NULL;
     const char *syspath;
     const char *key, *value, *tmp;
+    char **tags = NULL;
     InputOption *options = NULL, *tmpo;
     InputAttributes attrs = {};
     DeviceIntPtr dev = NULL;
@@ -87,7 +88,8 @@ device_added(struct udev_device *udev_device)
     add_option(&options, "path", path);
     add_option(&options, "device", path);
     attrs.device = path;
-    attrs.tags = xstrtokenize(udev_device_get_property_value(udev_device, "ID_INPUT.tags"), ",");
+    tags = xstrtokenize(udev_device_get_property_value(udev_device, "ID_INPUT.tags"), ",");
+    attrs.tags = (const char * const *)tags;
 
     config_info = Xprintf("udev:%s", syspath);
     if (!config_info)
@@ -154,13 +156,13 @@ device_added(struct udev_device *udev_device)
         free(tmpo);
     }
 
-    if (attrs.tags) {
-        char **tag = attrs.tags;
+    if (tags) {
+        char **tag = tags;
         while (*tag) {
             free(*tag);
             tag++;
         }
-        free(attrs.tags);
+        free(tags);
     }
 
     return;
diff --git a/hw/xfree86/common/xf86Xinput.c b/hw/xfree86/common/xf86Xinput.c
index ba83f24..3f1de8f 100644
--- a/hw/xfree86/common/xf86Xinput.c
+++ b/hw/xfree86/common/xf86Xinput.c
@@ -551,7 +551,7 @@ InputClassMatches(XF86ConfInputClassPtr iclass, InputAttributes *attrs)
             return FALSE;
 
         for (cur = iclass->match_tag, match = FALSE; *cur && !match; cur++) {
-            char **tag;
+            const char * const *tag;
             for(tag = attrs->tags; *tag; tag++) {
                 if (!strcmp(*tag, *cur)) {
                     match = TRUE;
diff --git a/include/input.h b/include/input.h
index 63f981e..e36577d 100644
--- a/include/input.h
+++ b/include/input.h
@@ -212,10 +212,10 @@ typedef struct _InputOption {
 } InputOption;
 
 typedef struct _InputAttributes {
-    char                *product;
-    char                *vendor;
-    char                *device;
-    char                **tags; /* null-terminated */
+    const char          *product;
+    const char          *vendor;
+    const char          *device;
+    const char  * const *tags; /* null-terminated */
     uint32_t            flags;
 } InputAttributes;
 
-- 
1.6.6.1



More information about the xorg-devel mailing list