[PATCH] dix: do not use bit-wise operators on the boolean result of BitIsOn

Mark Kettenis mark.kettenis at xs4all.nl
Wed Dec 1 03:17:48 PST 2010


> From: Ferry Huberts <mailings at hupie.com>
> Date: Tue, 30 Nov 2010 19:06:55 +0100
> 
> From: Ferry Huberts <ferry.huberts at pelagic.nl>
> 
> Performing bit-wise operations on a boolean amounts to mixing types,
> is confusing and basically incorrect; one should only perform
> logical operations on booleans.

The idea that C has a boolean type is a mere illusion.  Even the _Bool
type introduced in C99 is classified as an unsigned integer type.

If you ask me, the recent !! change to BitIsOn() already made little
sense.  People really shouldn't wish to use to == operator to compare
the results of two pretend-to-be boolean expressions.  But I guess
that's a trap that's too easy to fall into for people who didn't grow
up with traditional C.

> Performing such operations relies on the implementation detail
> that a boolean is in fact an integer and that its value FALSE
> is implemented as zero.

In the C language that is defenitely not an implementation detail!

That said, since the !! change to BitIsOn was deemed desirable by some
people, this diff is a logical consequence.

> Signed-off-by: Ferry Huberts <ferry.huberts at pelagic.nl>
> ---
>  dix/getevents.c |   12 ++++++------
>  1 files changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/dix/getevents.c b/dix/getevents.c
> index f09d31c..25889de 100644
> --- a/dix/getevents.c
> +++ b/dix/getevents.c
> @@ -112,12 +112,12 @@ set_button_up(DeviceIntPtr pDev, int button, int type)
>  Bool
>  button_is_down(DeviceIntPtr pDev, int button, int type)
>  {
> -    int ret = 0;
> +    Bool ret = FALSE;
>  
>      if (type & BUTTON_PROCESSED)
> -        ret |= BitIsOn(pDev->button->down, button);
> +        ret = ret || BitIsOn(pDev->button->down, button);
>      if (type & BUTTON_POSTED)
> -        ret |= BitIsOn(pDev->button->postdown, button);
> +        ret = ret || BitIsOn(pDev->button->postdown, button);
>  
>      return ret;
>  }
> @@ -143,12 +143,12 @@ set_key_up(DeviceIntPtr pDev, int key_code, int type)
>  Bool
>  key_is_down(DeviceIntPtr pDev, int key_code, int type)
>  {
> -    int ret = 0;
> +    Bool ret = FALSE;
>  
>      if (type & KEY_PROCESSED)
> -        ret |= BitIsOn(pDev->key->down, key_code);
> +        ret = ret || BitIsOn(pDev->key->down, key_code);
>      if (type & KEY_POSTED)
> -        ret |= BitIsOn(pDev->key->postdown, key_code);
> +        ret = ret || BitIsOn(pDev->key->postdown, key_code);
>  
>      return ret;
>  }
> -- 
> 1.7.3.2
> 
> _______________________________________________
> xorg-devel at lists.x.org: X.Org development
> Archives: http://lists.x.org/archives/xorg-devel
> Info: http://lists.x.org/mailman/listinfo/xorg-devel
> 


More information about the xorg-devel mailing list