[PATCH] config: Declare InputAttributes pointers as const

Dan Nicholson dbn.lists at gmail.com
Tue May 11 10:20:04 PDT 2010


These values are really immutable once they're filled in by the config
backend. Kills a couple warnings in udev where libudev returns const
char * properties that were being assigned to InputAttributes.

Signed-off-by: Dan Nicholson <dbn.lists at gmail.com>
---
 I had a change of heart, so here's a patch to make the InputAttributes
 members const.

 config/hal.c    |   12 ++++++------
 config/udev.c   |    8 ++++++--
 include/input.h |    8 ++++----
 3 files changed, 16 insertions(+), 12 deletions(-)

diff --git a/config/hal.c b/config/hal.c
index d3daa84..9b360ec 100644
--- a/config/hal.c
+++ b/config/hal.c
@@ -155,16 +155,18 @@ 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.tags = (const char **)xstrtokenize(get_prop_string(hal_ctx, udi,
+                                                             "input.tags"),
+                                             ",");
 
     if (libhal_device_query_capability(hal_ctx, udi, "input.keys", NULL))
         attrs.flags |= ATTR_KEYBOARD;
@@ -389,11 +391,9 @@ unwind:
         xfree(tmpo);
     }
 
-    xfree(attrs.product);
     xfree(attrs.vendor);
-    xfree(attrs.device);
     if (attrs.tags) {
-        char **tag = attrs.tags;
+        const char **tag = attrs.tags;
         while (*tag) {
             xfree(*tag);
             tag++;
diff --git a/config/udev.c b/config/udev.c
index 452fb5a..ea981fa 100644
--- a/config/udev.c
+++ b/config/udev.c
@@ -87,7 +87,11 @@ 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"), ",");
+
+    attrs.tags = (const char **)
+        xstrtokenize(udev_device_get_property_value(udev_device,
+                                                    "ID_INPUT.tags"),
+                     ",");
 
     config_info = Xprintf("udev:%s", syspath);
     if (!config_info)
@@ -155,7 +159,7 @@ device_added(struct udev_device *udev_device)
     }
 
     if (attrs.tags) {
-        char **tag = attrs.tags;
+        const char **tag = attrs.tags;
         while (*tag) {
             xfree(*tag);
             tag++;
diff --git a/include/input.h b/include/input.h
index 8561308..0dc2423 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          **tags; /* null-terminated */
     uint32_t            flags;
 } InputAttributes;
 
-- 
1.6.6.1


More information about the xorg-devel mailing list