xserver: Branch 'server-1.10-branch' - 6 commits

Jeremy Huddleston jeremyhu at kemper.freedesktop.org
Tue May 3 17:56:26 PDT 2011


 Xi/exevents.c      |   11 ++++-------
 Xi/extinit.c       |    2 +-
 Xi/xipassivegrab.c |   16 ++++++++++++----
 dix/devices.c      |   47 +++++++++++++++++++++++++++++++++++++----------
 dix/ptrveloc.c     |    2 +-
 include/input.h    |    5 +++++
 include/inputstr.h |    2 +-
 test/input.c       |   24 +++++++++++++++++++++++-
 8 files changed, 84 insertions(+), 25 deletions(-)

New commits:
commit be3f41d1ec5413d0ad05ef18e145714201d602aa
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Wed Apr 20 13:14:11 2011 +1000

    dix: fix typo in direction calculation
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>
    Reviewed-by: Jamey Sharp <jamey at minilop.net>
    Reviewed-by: Simon Thum <simon.thum at gmx.de>
    (cherry picked from commit 8c528c667da7c7fba0ba07973a06b2d4613fbf70)

diff --git a/dix/ptrveloc.c b/dix/ptrveloc.c
index 8f03321..4d5dad7 100644
--- a/dix/ptrveloc.c
+++ b/dix/ptrveloc.c
@@ -392,7 +392,7 @@ DoGetDirection(int dx, int dy){
     float r;
     int i1, i2;
     /* on insignificant mickeys, flag 135 degrees */
-    if(abs(dx) < 2 && abs(dy < 2)){
+    if(abs(dx) < 2 && abs(dy) < 2){
 	/* first check diagonal cases */
 	if(dx > 0 && dy > 0)
 	    return 4+8+16;
commit d2c9f331d2d58a396d8d6f067120b0eee041e321
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Wed Mar 9 10:44:48 2011 +1000

    Xi: don't swap the status byte in the XIPassiveGrab replies
    
    Reported-by: Julien Cristau <jcristau at debian.org>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>
    (cherry picked from commit 60b08e013dd1e971f82e5bc8708d3f120c217497)

diff --git a/Xi/xipassivegrab.c b/Xi/xipassivegrab.c
index 3aad28b..776d334 100644
--- a/Xi/xipassivegrab.c
+++ b/Xi/xipassivegrab.c
@@ -43,6 +43,7 @@
 #include "exevents.h"
 #include "xipassivegrab.h"
 #include "dixgrabs.h"
+#include "misc.h"
 
 int
 SProcXIPassiveGrabDevice(ClientPtr client)
@@ -87,6 +88,7 @@ ProcXIPassiveGrabDevice(ClientPtr client)
     GrabParameters param;
     void *tmp;
     int mask_len;
+    int n;
 
     REQUEST(xXIPassiveGrabDeviceReq);
     REQUEST_AT_LEAST_SIZE(xXIPassiveGrabDeviceReq);
@@ -198,6 +200,9 @@ ProcXIPassiveGrabDevice(ClientPtr client)
 
             info->status = status;
             info->modifiers = *modifiers;
+            if (client->swapped)
+                swapl(&info->modifiers, n);
+
             rep.num_modifiers++;
             rep.length += bytes_to_int32(sizeof(xXIGrabModifierInfo));
         }
@@ -205,10 +210,8 @@ ProcXIPassiveGrabDevice(ClientPtr client)
 
     WriteReplyToClient(client, sizeof(rep), &rep);
     if (rep.num_modifiers)
-    {
-	client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write;
-        WriteSwappedDataToClient(client, rep.length * 4, (char*)modifiers_failed);
-    }
+        WriteToClient(client, rep.length * 4, (char*)modifiers_failed);
+
     free(modifiers_failed);
     return ret;
 }
commit 0de1802c998d105a61dbb643e38600d2748eb520
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Wed Mar 9 10:07:19 2011 +1000

    Xi: exit with error value if CheckGrabValues failed.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Jeremy Huddleston <jeremyhu at apple.com>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>
    (cherry picked from commit a3f37f3698880aec508b5ecfb88daf39360610aa)

diff --git a/Xi/xipassivegrab.c b/Xi/xipassivegrab.c
index 463002f..3aad28b 100644
--- a/Xi/xipassivegrab.c
+++ b/Xi/xipassivegrab.c
@@ -159,6 +159,8 @@ ProcXIPassiveGrabDevice(ClientPtr client)
 	return status;
 
     status = CheckGrabValues(client, &param);
+    if (status != Success)
+        return status;
 
     modifiers = (uint32_t*)&stuff[1] + stuff->mask_len;
     modifiers_failed = calloc(stuff->num_modifiers, sizeof(xXIGrabModifierInfo));
commit e3887c8fa36eba2c7fdc5684f4c744156fc9a9e5
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Wed Mar 9 09:54:12 2011 +1000

    Xi: fix reply swapping function check for XIPassiveGrabDevice
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Jeremy Huddleston <jeremyhu at apple.com>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>
    (cherry picked from commit f4d9ff73b161d84d3fcacc5834fa714c113c7a10)

diff --git a/Xi/extinit.c b/Xi/extinit.c
index ec815c9..7f09dfe 100644
--- a/Xi/extinit.c
+++ b/Xi/extinit.c
@@ -511,7 +511,7 @@ SReplyIDispatch(ClientPtr client, int len, xGrabDeviceReply * rep)
         SRepXIQueryDevice(client, len, (xXIQueryDeviceReply*)rep);
     else if (rep->RepType == X_XIGrabDevice)
 	SRepXIGrabDevice(client, len, (xXIGrabDeviceReply *) rep);
-    else if (rep->RepType == X_XIGrabDevice)
+    else if (rep->RepType == X_XIPassiveGrabDevice)
 	SRepXIPassiveGrabDevice(client, len, (xXIPassiveGrabDeviceReply *) rep);
     else if (rep->RepType == X_XIListProperties)
 	SRepXIListProperties(client, len, (xXIListPropertiesReply *) rep);
commit ea55d0d504805674ac06b589d673ed9884575846
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Wed Mar 9 09:53:47 2011 +1000

    Xi: return the bad device ID if a passive grab fails with BadDevice.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Jeremy Huddleston <jeremyhu at apple.com>
    Reviewed-by: Daniel Stone <daniel at fooishbar.org>
    (cherry picked from commit 2a49ffa3c94819e9f28dd939f23ee8a675258172)

diff --git a/Xi/xipassivegrab.c b/Xi/xipassivegrab.c
index 4b71c68..463002f 100644
--- a/Xi/xipassivegrab.c
+++ b/Xi/xipassivegrab.c
@@ -99,7 +99,10 @@ ProcXIPassiveGrabDevice(ClientPtr client)
     {
         ret = dixLookupDevice(&dev, stuff->deviceid, client, DixGrabAccess);
         if (ret != Success)
+        {
+            client->errorValue = stuff->deviceid;
             return ret;
+        }
     }
 
     if (stuff->grab_type != XIGrabtypeButton &&
commit d6328c6bfe49958f68abbb6ddbc1f1514de6831f
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Tue Apr 12 10:17:07 2011 +1000

    Xi: fix valuator alignment in DeepCopyDeviceClasses (#36119)
    
    commit 678f5396c91b3d0c7572ed579b0a4fb62b2b4655 only fixed the
    initialization, not the copy. After a slave device change, the valuator
    were out of alignment again.
    
    X.Org Bug 36119 <http://bugs.freedesktop.org/show_bug.cgi?id=36119>
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
    Reviewed-by: Jeremy Huddleston <jeremyhu at apple.com>
    (cherry picked from commit 419a27b5219a739f2fbd50cc96a1b54c469e4a88)

diff --git a/Xi/exevents.c b/Xi/exevents.c
index 35f96e6..9bd9d60 100644
--- a/Xi/exevents.c
+++ b/Xi/exevents.c
@@ -535,6 +535,7 @@ DeepCopyPointerClasses(DeviceIntPtr from, DeviceIntPtr to)
     if (from->valuator)
     {
         ValuatorClassPtr v;
+
         if (!to->valuator)
         {
             classes = to->unused_classes;
@@ -543,18 +544,14 @@ DeepCopyPointerClasses(DeviceIntPtr from, DeviceIntPtr to)
                 classes->valuator = NULL;
         }
 
-        to->valuator = realloc(to->valuator, sizeof(ValuatorClassRec) +
-                from->valuator->numAxes * sizeof(AxisInfo) +
-                from->valuator->numAxes * sizeof(double));
-        v = to->valuator;
+        v = AllocValuatorClass(to->valuator, from->valuator->numAxes);
+
         if (!v)
             FatalError("[Xi] no memory for class shift.\n");
 
-        v->numAxes = from->valuator->numAxes;
-        v->axes = (AxisInfoPtr)&v[1];
+        to->valuator = v;
         memcpy(v->axes, from->valuator->axes, v->numAxes * sizeof(AxisInfo));
 
-        v->axisVal = (double*)(v->axes + from->valuator->numAxes);
         v->sourceid = from->id;
     } else if (to->valuator && !from->valuator)
     {
diff --git a/dix/devices.c b/dix/devices.c
index 55f22cb..fed05f5 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -1221,13 +1221,46 @@ InitButtonClassDeviceStruct(DeviceIntPtr dev, int numButtons, Atom* labels,
     return TRUE;
 }
 
+/**
+ * Allocate a valuator class and set up the pointers for the axis values
+ * appropriately.
+ *
+ * @param src If non-NULL, the memory is reallocated from src. If NULL, the
+ * memory is calloc'd.
+ * @parma numAxes Number of axes to allocate.
+ * @return The allocated valuator struct.
+ */
+ValuatorClassPtr
+AllocValuatorClass(ValuatorClassPtr src, int numAxes)
+{
+    ValuatorClassPtr v;
+    /* force alignment with double */
+    union align_u { ValuatorClassRec valc; double d; } *align;
+    int size;
+
+    size = sizeof(union align_u) + numAxes * (sizeof(double) + sizeof(AxisInfo));
+    align = (union align_u *) realloc(src, size);
+
+    if (!align)
+        return NULL;
+
+    if (!src)
+        memset(align, 0, size);
+
+    v = &align->valc;
+    v->numAxes = numAxes;
+    v->axisVal = (double*)(align + 1);
+    v->axes = (AxisInfoPtr)(v->axisVal + numAxes);
+
+    return v;
+}
+
 Bool
 InitValuatorClassDeviceStruct(DeviceIntPtr dev, int numAxes, Atom *labels,
                               int numMotionEvents, int mode)
 {
     int i;
     ValuatorClassPtr valc;
-    union align_u { ValuatorClassRec valc; double d; } *align;
 
     if (!dev)
         return FALSE;
@@ -1240,13 +1273,10 @@ InitValuatorClassDeviceStruct(DeviceIntPtr dev, int numAxes, Atom *labels,
         numAxes = MAX_VALUATORS;
     }
 
-    align = (union align_u *) calloc(1, sizeof(union align_u) +
-				     numAxes * sizeof(double) +
-				     numAxes * sizeof(AxisInfo));
-    if (!align)
-	return FALSE;
+    valc = AllocValuatorClass(NULL, numAxes);
+    if (!valc)
+        return FALSE;
 
-    valc = &align->valc;
     valc->sourceid = dev->id;
     valc->motion = NULL;
     valc->first_motion = 0;
@@ -1254,9 +1284,6 @@ InitValuatorClassDeviceStruct(DeviceIntPtr dev, int numAxes, Atom *labels,
 
     valc->numMotionEvents = numMotionEvents;
     valc->motionHintWindow = NullWindow;
-    valc->numAxes = numAxes;
-    valc->axisVal = (double *)(align + 1);
-    valc->axes = (AxisInfoPtr)(valc->axisVal + numAxes);
 
     if (mode & OutOfProximity)
         InitProximityClassDeviceStruct(dev);
diff --git a/include/input.h b/include/input.h
index f96a0a9..908e595 100644
--- a/include/input.h
+++ b/include/input.h
@@ -102,6 +102,7 @@ typedef unsigned long Leds;
 typedef struct _OtherClients *OtherClientsPtr;
 typedef struct _InputClients *InputClientsPtr;
 typedef struct _DeviceIntRec *DeviceIntPtr;
+typedef struct _ValuatorClassRec *ValuatorClassPtr;
 typedef struct _ClassesRec *ClassesPtr;
 typedef struct _SpriteRec *SpritePtr;
 typedef union _GrabMask GrabMask;
@@ -297,6 +298,10 @@ extern _X_EXPORT Bool InitButtonClassDeviceStruct(
     Atom* /* labels */,
     CARD8* /*map*/);
 
+extern _X_INTERNAL ValuatorClassPtr AllocValuatorClass(
+    ValuatorClassPtr src,
+    int numAxes);
+
 extern _X_EXPORT Bool InitValuatorClassDeviceStruct(
     DeviceIntPtr /*device*/,
     int /*numAxes*/,
diff --git a/include/inputstr.h b/include/inputstr.h
index b74ee04..2ee2fd8 100644
--- a/include/inputstr.h
+++ b/include/inputstr.h
@@ -282,7 +282,7 @@ typedef struct _ValuatorClassRec {
     unsigned short	  numAxes;
     double		  *axisVal; /* always absolute, but device-coord system */
     ValuatorAccelerationRec	accelScheme;
-} ValuatorClassRec, *ValuatorClassPtr;
+} ValuatorClassRec;
 
 typedef struct _ButtonClassRec {
     int			sourceid;
diff --git a/test/input.c b/test/input.c
index e0e9e6a..4d840b9 100644
--- a/test/input.c
+++ b/test/input.c
@@ -1199,6 +1199,28 @@ static void include_bit_test_macros(void)
     }
 }
 
+/**
+ * Ensure that val->axisVal and val->axes are aligned on doubles.
+ */
+static void dix_valuator_alloc(void)
+{
+    ValuatorClassPtr v = NULL;
+    int num_axes = 0;
+
+    while (num_axes < 5)
+    {
+        v = AllocValuatorClass(v, num_axes);
+
+        g_assert(v);
+        g_assert(v->numAxes == num_axes);
+        g_assert(((void*)v->axisVal - (void*)v) % sizeof(double) == 0);
+        g_assert(((void*)v->axes - (void*)v) % sizeof(double) == 0);
+        num_axes ++;
+    }
+
+    free(v);
+}
+
 int main(int argc, char** argv)
 {
     g_test_init(&argc, &argv,NULL);
@@ -1216,7 +1238,7 @@ int main(int argc, char** argv)
     g_test_add_func("/include/byte_padding_macros", include_byte_padding_macros);
     g_test_add_func("/include/bit_test_macros", include_bit_test_macros);
     g_test_add_func("/Xi/xiproperty/register-unregister", xi_unregister_handlers);
-
+    g_test_add_func("/dix/input/valuator-alloc", dix_valuator_alloc);
 
     return g_test_run();
 }


More information about the xorg-commit mailing list