Re: [PATCH libinput] evdev: replace null sentinel with ARRAY_SIZE

2017-05-10 Thread Peter Hutterer
On Wed, May 10, 2017 at 11:13:07AM +0100, Eric Engestrom wrote:
> Signed-off-by: Eric Engestrom 
> ---
>  src/evdev.c | 17 +++--
>  1 file changed, 7 insertions(+), 10 deletions(-)
> 
> diff --git a/src/evdev.c b/src/evdev.c
> index a2be6fc..7895644 100644
> --- a/src/evdev.c
> +++ b/src/evdev.c
> @@ -50,6 +50,8 @@
>  #define DEFAULT_WHEEL_CLICK_ANGLE 15
>  #define DEFAULT_BUTTON_SCROLL_TIMEOUT ms2us(200)
>  
> +#define ARRAY_SIZE(a) (sizeof(a)/sizeof(a)[0])

We already have ARRAY_LENGTH, I fixed this up accordingly and squashed my
{ 0, 0 } patch into this one, no point having to patches here. Thanks!

Cheers,
   Peter

> +
>  enum evdev_key_type {
>   EVDEV_KEY_TYPE_NONE,
>   EVDEV_KEY_TYPE_KEY,
> @@ -90,9 +92,6 @@ static const struct evdev_udev_tag_match 
> evdev_udev_tag_matches[] = {
>   {"ID_INPUT_POINTINGSTICK",  EVDEV_UDEV_TAG_POINTINGSTICK},
>   {"ID_INPUT_TRACKBALL",  EVDEV_UDEV_TAG_TRACKBALL},
>   {"ID_INPUT_SWITCH", EVDEV_UDEV_TAG_SWITCH},
> -
> - /* sentinel value */
> - {0, 0},
>  };
>  
>  static inline bool
> @@ -2373,18 +2372,16 @@ evdev_device_get_udev_tags(struct evdev_device 
> *device,
>  struct udev_device *udev_device)
>  {
>   enum evdev_device_udev_tags tags = 0;
> - const struct evdev_udev_tag_match *match;
>   int i;
>  
>   for (i = 0; i < 2 && udev_device; i++) {
> - match = evdev_udev_tag_matches;
> - while (match->name) {
> + unsigned j;
> + for (j = 0; j < ARRAY_SIZE(evdev_udev_tag_matches); j++) {
> + const struct evdev_udev_tag_match match = 
> evdev_udev_tag_matches[j];
>   if (parse_udev_flag(device,
>   udev_device,
> - match->name))
> - tags |= match->tag;
> -
> - match++;
> + match.name))
> + tags |= match.tag;
>   }
>   udev_device = udev_device_get_parent(udev_device);
>   }
> -- 
> Cheers,
>   Eric
> 
___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


Re: [PATCH libinput] evdev: replace null sentinel with ARRAY_SIZE

2017-05-10 Thread Eric Engestrom
On Wednesday, 2017-05-10 17:25:04 +0200, Jan Engelhardt wrote:
> 
> On Wednesday 2017-05-10 17:20, Dima Ryazanov wrote:
> >  +#define ARRAY_SIZE(a) (sizeof(a)/sizeof(a)[0])
> >
> >
> >I'm guessing this works, but "sizeof(a)[0]" looks very unintuitive to me. I 
> >think "sizeof(a[0])" is
> >the convention?
> 
> If going with the sizeof(T) syntax, then the answer would 
> be "sizeof((a)[0])", or alternatively, "sizeof(*(a))".

The syntax [1] is `sizeof(T)` for a type, and `sizeof E` for an
expression, which the array variable passed in is.
Since it's in a macro, you have to put brackets around arguments,
hence the `(a)` in both cases.

I can add unnecessary brackets if you want, but that would be purely
cosmetic, no actual machine purpose ;)

[1] http://en.cppreference.com/w/c/language/sizeof
___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


Re: [PATCH libinput] evdev: replace null sentinel with ARRAY_SIZE

2017-05-10 Thread Jan Engelhardt

On Wednesday 2017-05-10 17:20, Dima Ryazanov wrote:
>  +#define ARRAY_SIZE(a) (sizeof(a)/sizeof(a)[0])
>
>
>I'm guessing this works, but "sizeof(a)[0]" looks very unintuitive to me. I 
>think "sizeof(a[0])" is
>the convention?

If going with the sizeof(T) syntax, then the answer would 
be "sizeof((a)[0])", or alternatively, "sizeof(*(a))".
___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


Re: [PATCH libinput] evdev: replace null sentinel with ARRAY_SIZE

2017-05-10 Thread Dima Ryazanov
On May 10, 2017 7:14 AM, "Eric Engestrom"  wrote:

Signed-off-by: Eric Engestrom 
---
 src/evdev.c | 17 +++--
 1 file changed, 7 insertions(+), 10 deletions(-)

diff --git a/src/evdev.c b/src/evdev.c
index a2be6fc..7895644 100644
--- a/src/evdev.c
+++ b/src/evdev.c
@@ -50,6 +50,8 @@
 #define DEFAULT_WHEEL_CLICK_ANGLE 15
 #define DEFAULT_BUTTON_SCROLL_TIMEOUT ms2us(200)

+#define ARRAY_SIZE(a) (sizeof(a)/sizeof(a)[0])


I'm guessing this works, but "sizeof(a)[0]" looks very unintuitive to me. I
think "sizeof(a[0])" is the convention?

+
 enum evdev_key_type {
EVDEV_KEY_TYPE_NONE,
EVDEV_KEY_TYPE_KEY,
@@ -90,9 +92,6 @@ static const struct evdev_udev_tag_match
evdev_udev_tag_matches[] = {
{"ID_INPUT_POINTINGSTICK",  EVDEV_UDEV_TAG_POINTINGSTICK},
{"ID_INPUT_TRACKBALL",  EVDEV_UDEV_TAG_TRACKBALL},
{"ID_INPUT_SWITCH", EVDEV_UDEV_TAG_SWITCH},
-
-   /* sentinel value */
-   {0, 0},
 };

 static inline bool
@@ -2373,18 +2372,16 @@ evdev_device_get_udev_tags(struct evdev_device
*device,
   struct udev_device *udev_device)
 {
enum evdev_device_udev_tags tags = 0;
-   const struct evdev_udev_tag_match *match;
int i;

for (i = 0; i < 2 && udev_device; i++) {
-   match = evdev_udev_tag_matches;
-   while (match->name) {
+   unsigned j;
+   for (j = 0; j < ARRAY_SIZE(evdev_udev_tag_matches); j++) {
+   const struct evdev_udev_tag_match match =
evdev_udev_tag_matches[j];
if (parse_udev_flag(device,
udev_device,
-   match->name))
-   tags |= match->tag;
-
-   match++;
+   match.name))
+   tags |= match.tag;
}
udev_device = udev_device_get_parent(udev_device);
}
--
Cheers,
  Eric

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel
___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel