On Sat, 26 Feb 2011 00:00:39 +0100, Julien Cristau <jcris...@debian.org> wrote:
> Some architectures (hi, sparc!) are unhappy with unaligned memory > accesses. So make sure the axisVal member of ValuatorClassRec has > sizeof(double) alignment to avoid crashes and test failures. The 'standard' way to do this is to use a union to ensure correct alignment. Seems like simply moving the doubles to after the ValuatorClassRec and using a union between a double and the ValuatorClassRec would fix this without a lot of ugly pointer computations. This is completely untested, but I imagine something the following would work: diff --git a/dix/devices.c b/dix/devices.c index 6c0dc42..89294aa 100644 --- a/dix/devices.c +++ b/dix/devices.c @@ -1225,6 +1225,7 @@ InitValuatorClassDeviceStruct(DeviceIntPtr dev, int numAxes, Atom *labels, { int i; ValuatorClassPtr valc; + union align_u { ValuatorClassRec valc; double d; } *align; if (!dev) return FALSE; @@ -1237,12 +1238,13 @@ InitValuatorClassDeviceStruct(DeviceIntPtr dev, int numAxes, Atom *labels, numAxes = MAX_VALUATORS; } - valc = (ValuatorClassPtr)calloc(1, sizeof(ValuatorClassRec) + - numAxes * sizeof(AxisInfo) + - numAxes * sizeof(double)); - if (!valc) + align = (union align_u *) calloc(1, sizeof(union align_u) + + numAxes * sizeof(double) + + numAxes * sizeof(AxisInfo)); + if (!align) return FALSE; + valc = &align->valc; valc->sourceid = dev->id; valc->motion = NULL; valc->first_motion = 0; @@ -1251,8 +1253,8 @@ InitValuatorClassDeviceStruct(DeviceIntPtr dev, int numAxes, Atom *labels, valc->numMotionEvents = numMotionEvents; valc->motionHintWindow = NullWindow; valc->numAxes = numAxes; - valc->axes = (AxisInfoPtr)(valc + 1); - valc->axisVal = (double *)(valc->axes + numAxes); + valc->axisVal = (double *)(align + 1); + valc->axes = (AxisInfoPtr)(valc->axisVal + numAxes); if (mode & OutOfProximity) InitProximityClassDeviceStruct(dev); -- keith.pack...@intel.com
pgpMA9CvjvTp3.pgp
Description: PGP signature
_______________________________________________ xorg-devel@lists.x.org: X.Org development Archives: http://lists.x.org/archives/xorg-devel Info: http://lists.x.org/mailman/listinfo/xorg-devel