[PATCH 09/11] include: add version_compare helper function
Peter Hutterer
peter.hutterer at who-t.net
Tue May 10 21:49:48 PDT 2011
Compare two version numbers in the major.minor form.
Switch the few users of manual version switching over to the new function.
Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
Xi/xiqueryversion.c | 7 ++-----
include/misc.h | 18 ++++++++++++++++++
randr/rrdispatch.c | 8 ++++----
xfixes/xfixes.c | 12 ++++++------
4 files changed, 30 insertions(+), 15 deletions(-)
diff --git a/Xi/xiqueryversion.c b/Xi/xiqueryversion.c
index ae63297..1aaadb6 100644
--- a/Xi/xiqueryversion.c
+++ b/Xi/xiqueryversion.c
@@ -58,7 +58,6 @@ ProcXIQueryVersion(ClientPtr client)
xXIQueryVersionReply rep;
XIClientPtr pXIClient;
int major, minor;
- unsigned int sversion, cversion;
REQUEST(xXIQueryVersionReq);
REQUEST_SIZE_MATCH(xXIQueryVersionReq);
@@ -72,10 +71,8 @@ ProcXIQueryVersion(ClientPtr client)
pXIClient = dixLookupPrivate(&client->devPrivates, XIClientPrivateKey);
- sversion = XIVersion.major_version * 1000 + XIVersion.minor_version;
- cversion = stuff->major_version * 1000 + stuff->minor_version;
-
- if (sversion > cversion)
+ if (version_compare(XIVersion.major_version, XIVersion.minor_version,
+ stuff->major_version, stuff->minor_version) == 1)
{
major = stuff->major_version;
minor = stuff->minor_version;
diff --git a/include/misc.h b/include/misc.h
index 803f5ba..604c893 100644
--- a/include/misc.h
+++ b/include/misc.h
@@ -223,6 +223,24 @@ pad_to_int32(const int bytes) {
extern char**
xstrtokenize(const char *str, const char* separators);
+/**
+ * Compare the two version numbers comprising of major.minor.
+ *
+ * @retval -1 if a is less than b
+ * @retval 0 if a is equal to b
+ * @retval 1 if a is greater than b
+ */
+static inline int
+version_compare(int a_major, int a_minor, int b_major, int b_minor)
+{
+ int a, b;
+
+ a = a_major * 1000 + a_minor;
+ b = b_major * 1000 + b_minor;
+
+ return (a == b) ? 0 : (a < b) ? -1 : 1;
+}
+
/* some macros to help swap requests, replies, and events */
#define LengthRestB(stuff) \
diff --git a/randr/rrdispatch.c b/randr/rrdispatch.c
index 2135504..579999d 100644
--- a/randr/rrdispatch.c
+++ b/randr/rrdispatch.c
@@ -28,8 +28,8 @@ RRClientKnowsRates (ClientPtr pClient)
{
rrClientPriv(pClient);
- return (pRRClient->major_version > 1 ||
- (pRRClient->major_version == 1 && pRRClient->minor_version >= 1));
+ return version_compare(pRRClient->major_version, pRRClient->minor_version,
+ 1, 1) >= 0;
}
static int
@@ -47,8 +47,8 @@ ProcRRQueryVersion (ClientPtr client)
rep.length = 0;
rep.sequenceNumber = client->sequence;
- if ((stuff->majorVersion * 1000 + stuff->minorVersion) <
- (SERVER_RANDR_MAJOR_VERSION * 1000 + SERVER_RANDR_MINOR_VERSION))
+ if (version_compare(stuff->majorVersion, stuff->minorVersion,
+ SERVER_RANDR_MAJOR_VERSION, SERVER_RANDR_MINOR_VERSION) == -1)
{
rep.majorVersion = stuff->majorVersion;
rep.minorVersion = stuff->minorVersion;
diff --git a/xfixes/xfixes.c b/xfixes/xfixes.c
index e8c7bf1..8563b22 100644
--- a/xfixes/xfixes.c
+++ b/xfixes/xfixes.c
@@ -72,17 +72,17 @@ ProcXFixesQueryVersion(ClientPtr client)
rep.type = X_Reply;
rep.length = 0;
rep.sequenceNumber = client->sequence;
- if (stuff->majorVersion < SERVER_XFIXES_MAJOR_VERSION) {
+
+ if (version_compare(stuff->majorVersion, stuff->minorVersion,
+ SERVER_XFIXES_MAJOR_VERSION, SERVER_XFIXES_MAJOR_VERSION) == -1)
+ {
rep.majorVersion = stuff->majorVersion;
rep.minorVersion = stuff->minorVersion;
} else {
rep.majorVersion = SERVER_XFIXES_MAJOR_VERSION;
- if (stuff->majorVersion == SERVER_XFIXES_MAJOR_VERSION &&
- stuff->minorVersion < SERVER_XFIXES_MINOR_VERSION)
- rep.minorVersion = stuff->minorVersion;
- else
- rep.minorVersion = SERVER_XFIXES_MINOR_VERSION;
+ rep.minorVersion = SERVER_XFIXES_MINOR_VERSION;
}
+
pXFixesClient->major_version = rep.majorVersion;
pXFixesClient->minor_version = rep.minorVersion;
if (client->swapped) {
--
1.7.4.4
More information about the xorg-devel
mailing list