[PATCH RESEND 1/5] input: switch InputOption to use XF86OptionRec storage.

Peter Hutterer peter.hutterer at who-t.net
Wed Oct 19 20:05:28 PDT 2011


Use the same struct for both InputOption and XF86OptionRec so we don't need
to convert to and fro the two in the config backends.

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
Reviewed-by: Dan Nicholson <dbn.lists at gmail.com>
---
 dix/inpututils.c                  |   33 +++++++++++++++++----------------
 hw/xfree86/common/xf86Option.c    |    1 +
 hw/xfree86/common/xf86Optionstr.h |   13 ++-----------
 hw/xfree86/common/xf86Xinput.c    |    5 +++--
 hw/xfree86/parser/Flags.c         |    5 +++--
 hw/xfree86/parser/Layout.c        |    2 +-
 include/inputstr.h                |    7 -------
 include/list.h                    |   12 ++++++++++++
 include/optionstr.h               |   14 ++++++++++++++
 9 files changed, 53 insertions(+), 39 deletions(-)
 create mode 100644 include/optionstr.h

diff --git a/dix/inpututils.c b/dix/inpututils.c
index 2915e67..c1ca155 100644
--- a/dix/inpututils.c
+++ b/dix/inpututils.c
@@ -38,6 +38,7 @@
 #include "inpututils.h"
 #include "eventstr.h"
 #include "scrnintstr.h"
+#include "optionstr.h"
 
 /* Check if a button map change is okay with the device.
  * Returns -1 for BadValue, as it collides with MappingBusy. */
@@ -670,8 +671,8 @@ point_on_screen(ScreenPtr pScreen, int x, int y)
 static void
 input_option_free(InputOption *o)
 {
-    free(o->key);
-    free(o->value);
+    free(o->opt_name);
+    free(o->opt_val);
     free(o);
 }
 
@@ -701,7 +702,7 @@ input_option_new(InputOption* list, const char *key, const char *value)
 
     if (list)
     {
-        nt_list_for_each_entry(opt, list, next)
+        nt_list_for_each_entry(opt, list, list.next)
         {
             if (strcmp(input_option_get_key(opt), key) == 0)
             {
@@ -715,13 +716,13 @@ input_option_new(InputOption* list, const char *key, const char *value)
     if (!opt)
         return NULL;
 
-    nt_list_init(opt, next);
+    nt_list_init(opt, list.next);
     input_option_set_key(opt, key);
     input_option_set_value(opt, value);
 
     if (list)
     {
-        nt_list_append(opt, list, InputOption, next);
+        nt_list_append(opt, list, InputOption, list.next);
         return list;
     } else
         return opt;
@@ -732,9 +733,9 @@ input_option_free_element(InputOption *list, const char *key)
 {
     InputOption *element;
 
-    nt_list_for_each_entry(element, list, next) {
+    nt_list_for_each_entry(element, list, list.next) {
         if (strcmp(input_option_get_key(element), key) == 0) {
-            nt_list_del(element, list, InputOption, next);
+            nt_list_del(element, list, InputOption, list.next);
             input_option_free(element);
             break;
         }
@@ -750,8 +751,8 @@ input_option_free_list(InputOption **opt)
 {
     InputOption *element, *tmp;
 
-    nt_list_for_each_entry_safe(element, tmp, *opt, next) {
-        nt_list_del(element, *opt, InputOption, next);
+    nt_list_for_each_entry_safe(element, tmp, *opt, list.next) {
+        nt_list_del(element, *opt, InputOption, list.next);
         input_option_free(element);
     }
     *opt = NULL;
@@ -768,7 +769,7 @@ input_option_find(InputOption *list, const char *key)
 {
     InputOption *element;
 
-    nt_list_for_each_entry(element, list, next) {
+    nt_list_for_each_entry(element, list, list.next) {
         if (strcmp(input_option_get_key(element), key) == 0)
             return element;
     }
@@ -779,29 +780,29 @@ input_option_find(InputOption *list, const char *key)
 const char*
 input_option_get_key(const InputOption *opt)
 {
-    return opt->key;
+    return opt->opt_name;
 }
 
 const char*
 input_option_get_value(const InputOption *opt)
 {
-    return opt->value;
+    return opt->opt_val;
 }
 
 void
 input_option_set_key(InputOption *opt, const char *key)
 {
-    free(opt->key);
+    free(opt->opt_name);
     if (key)
-        opt->key = strdup(key);
+        opt->opt_name = strdup(key);
 }
 
 void
 input_option_set_value(InputOption *opt, const char *value)
 {
-    free(opt->value);
+    free(opt->opt_val);
     if (value)
-        opt->value = strdup(value);
+        opt->opt_val = strdup(value);
 }
 
 
diff --git a/hw/xfree86/common/xf86Option.c b/hw/xfree86/common/xf86Option.c
index 73b6573..1a1f42a 100644
--- a/hw/xfree86/common/xf86Option.c
+++ b/hw/xfree86/common/xf86Option.c
@@ -44,6 +44,7 @@
 #include "xf86Xinput.h"
 #include "xf86Optrec.h"
 #include "xf86Parser.h"
+#include "optionstr.h"
 
 static Bool ParseOptionValue(int scrnIndex, XF86OptionPtr options, OptionInfoPtr p,
 			     Bool markUsed);
diff --git a/hw/xfree86/common/xf86Optionstr.h b/hw/xfree86/common/xf86Optionstr.h
index 8cc82d3..fc93856 100644
--- a/hw/xfree86/common/xf86Optionstr.h
+++ b/hw/xfree86/common/xf86Optionstr.h
@@ -24,16 +24,7 @@
 
 #ifndef XF86OPTIONSTR_H
 #define XF86OPTIONSTR_H
-
-/*
- * all records that need to be linked lists should contain a GenericList as
- * their first field.
- */
-typedef struct generic_list_rec
-{
-	void *next;
-}
-GenericListRec, *GenericListPtr, *glp;
+#include "list.h"
 
 /*
  * All options are stored using this data type.
@@ -48,6 +39,6 @@ typedef struct _XF86OptionRec
 }
 XF86OptionRec;
 
-typedef struct _XF86OptionRec *XF86OptionPtr;
+typedef struct _InputOption *XF86OptionPtr;
 
 #endif
diff --git a/hw/xfree86/common/xf86Xinput.c b/hw/xfree86/common/xf86Xinput.c
index ea1f927..425b359 100644
--- a/hw/xfree86/common/xf86Xinput.c
+++ b/hw/xfree86/common/xf86Xinput.c
@@ -68,6 +68,7 @@
 #include "exglobals.h"
 #include "eventstr.h"
 #include "inpututils.h"
+#include "optionstr.h"
 
 #include <string.h>     /* InputClassMatches */
 #ifdef HAVE_FNMATCH_H
@@ -908,7 +909,7 @@ NewInputDeviceRequest (InputOption *options, InputAttributes *attrs,
     if (!pInfo)
         return BadAlloc;
 
-    nt_list_for_each_entry(option, options, next) {
+    nt_list_for_each_entry(option, options, list.next) {
         if (strcasecmp(input_option_get_key(option), "driver") == 0) {
             if (pInfo->driver) {
                 rval = BadRequest;
@@ -946,7 +947,7 @@ NewInputDeviceRequest (InputOption *options, InputAttributes *attrs,
         }
     }
 
-    nt_list_for_each_entry(option, options, next) {
+    nt_list_for_each_entry(option, options, list.next) {
         /* Copy option key/value strings from the provided list */
         pInfo->options = xf86AddNewOption(pInfo->options,
                                           input_option_get_key(option),
diff --git a/hw/xfree86/parser/Flags.c b/hw/xfree86/parser/Flags.c
index 7a0794b..f0a6170 100644
--- a/hw/xfree86/parser/Flags.c
+++ b/hw/xfree86/parser/Flags.c
@@ -63,6 +63,7 @@
 #include "Configint.h"
 #include <X11/Xfuncproto.h>
 #include "Xprintf.h"
+#include "optionstr.h"
 
 extern LexRec val;
 
@@ -203,7 +204,7 @@ addNewOption2 (XF86OptionPtr head, char *name, char *val, int used)
 		free(new->opt_val);
 	}
 	else
-		new = calloc (1, sizeof (XF86OptionRec));
+		new = calloc (1, sizeof (*new));
 	new->opt_name = name;
 	new->opt_val = val;
 	new->opt_used = used;
@@ -284,7 +285,7 @@ xf86newOption(char *name, char *value)
 {
 	XF86OptionPtr opt;
 
-	opt = calloc(1, sizeof (XF86OptionRec));
+	opt = calloc(1, sizeof (*opt));
 	if (!opt)
 		return NULL;
 
diff --git a/hw/xfree86/parser/Layout.c b/hw/xfree86/parser/Layout.c
index e1f770b..4487b0d 100644
--- a/hw/xfree86/parser/Layout.c
+++ b/hw/xfree86/parser/Layout.c
@@ -63,7 +63,7 @@
 #include "xf86tokens.h"
 #include "Configint.h"
 #include <string.h>
-
+#include "optionstr.h"
 
 /* Needed for auto server layout */
 extern int xf86CheckBoolOption(void* optlist, const char *name, int deflt);
diff --git a/include/inputstr.h b/include/inputstr.h
index 9d4108e..7a15540 100644
--- a/include/inputstr.h
+++ b/include/inputstr.h
@@ -621,11 +621,4 @@ static inline WindowPtr DeepestSpriteWin(SpritePtr sprite)
     return sprite->spriteTrace[sprite->spriteTraceGood - 1];
 }
 
-struct _InputOption {
-    char                *key;
-    char                *value;
-    struct _InputOption *next;
-};
-
-
 #endif /* INPUTSTRUCT_H */
diff --git a/include/list.h b/include/list.h
index 7825dce..4706e17 100644
--- a/include/list.h
+++ b/include/list.h
@@ -438,4 +438,16 @@ list_is_empty(struct list *head)
 		nt_list_init(__e, _member);			\
 	} while(0)
 
+/**
+ * DO NOT USE THIS.
+ * This is a remainder of the xfree86 DDX attempt of having a set of generic
+ * list functions. Unfortunately, the xf86OptionRec uses it and we can't
+ * easily get rid of it. Do not use for new code.
+ */
+typedef struct generic_list_rec
+{
+	void *next;
+}
+GenericListRec, *GenericListPtr, *glp;
+
 #endif
diff --git a/include/optionstr.h b/include/optionstr.h
new file mode 100644
index 0000000..a71d245
--- /dev/null
+++ b/include/optionstr.h
@@ -0,0 +1,14 @@
+#ifndef OPTIONSTR_H_
+#define OPTIONSTR_H_
+#include "list.h"
+
+
+struct _InputOption {
+    GenericListRec list;
+    char *opt_name;
+    char *opt_val;
+    int opt_used;
+    char *opt_comment;
+};
+
+#endif /* INPUTSTRUCT_H */
-- 
1.7.6.4



More information about the xorg-devel mailing list