[PATCH libXi 1/2] Move version comparison into a helper function.

Peter Hutterer peter.hutterer at who-t.net
Sun Mar 25 16:10:47 PDT 2012


No functional changes, this simply introduces a version helper function that
returns -1, 0 or 1 depending on the version comparison result. To be used
internally only.

Needed for fix to #34240

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 src/XExtInt.c |   51 +++++++++++++++++++++++++++++++++++++++++----------
 src/XIint.h   |    1 +
 2 files changed, 42 insertions(+), 10 deletions(-)

diff --git a/src/XExtInt.c b/src/XExtInt.c
index 0c64f9a..4f85667 100644
--- a/src/XExtInt.c
+++ b/src/XExtInt.c
@@ -344,6 +344,43 @@ static int XInputCheckExtension(Display *dpy, XExtDisplayInfo *info)
     return 1;
 }
 
+/*****************************************************************
+ * Compare version numbers between info and the built-in version table.
+ * Returns
+ *   -1 if info's version is less than version_index's version,
+ *   0 if equal (or DontCheck),
+ *   1 if info's version is greater than version_index's version.
+ * Returns -2 on initialization errors which shouldn't happen if you call it
+ * correctly.
+ */
+_X_HIDDEN int
+_XiCheckVersion(XExtDisplayInfo *info,
+                int version_index)
+{
+    XExtensionVersion *ext;
+
+    if (versions[version_index].major_version == Dont_Check)
+        return 0;
+
+    if (!info->data)
+        return -2;
+
+    ext = ((XInputData *) info->data)->vers;
+    if (!ext)
+        return -2;
+
+    if (ext->major_version == versions[version_index].major_version &&
+        ext->minor_version == versions[version_index].minor_version)
+        return 0;
+
+    if (ext->major_version < versions[version_index].major_version ||
+        (ext->major_version == versions[version_index].major_version &&
+         ext->minor_version < versions[version_index].minor_version))
+        return -1;
+    else
+        return 1;
+}
+
 /***********************************************************************
  *
  * Check to see if the input extension is installed in the server.
@@ -357,8 +394,6 @@ _XiCheckExtInit(
     register int	 version_index,
     XExtDisplayInfo	*info)
 {
-    XExtensionVersion *ext;
-
     if (!XInputCheckExtension(dpy, info)) {
 	UnlockDisplay(dpy);
 	return (-1);
@@ -374,15 +409,11 @@ _XiCheckExtInit(
 	    _XiGetExtensionVersion(dpy, "XInputExtension", info);
     }
 
-    if (versions[version_index].major_version > Dont_Check) {
-	ext = ((XInputData *) info->data)->vers;
-	if ((ext->major_version < versions[version_index].major_version) ||
-	    ((ext->major_version == versions[version_index].major_version) &&
-	     (ext->minor_version < versions[version_index].minor_version))) {
-	    UnlockDisplay(dpy);
-	    return (-1);
-	}
+    if (_XiCheckVersion(info, version_index) < 0) {
+	UnlockDisplay(dpy);
+	return -1;
     }
+
     return (0);
 }
 
diff --git a/src/XIint.h b/src/XIint.h
index cc46754..be4eafb 100644
--- a/src/XIint.h
+++ b/src/XIint.h
@@ -26,6 +26,7 @@
 extern XExtDisplayInfo *XInput_find_display(Display *);
 
 extern int _XiCheckExtInit(Display *, int, XExtDisplayInfo *);
+extern int _XiCheckVersion(XExtDisplayInfo *info, int version_index);
 
 extern XExtensionVersion *_XiGetExtensionVersion(Display *, _Xconst char *, XExtDisplayInfo *);
 extern XExtensionVersion* _XiGetExtensionVersionRequest(Display *dpy, _Xconst char *name, int xi_opcode);
-- 
1.7.7.6



More information about the xorg-devel mailing list