[PATCH wayland 8/8] fixup! scanner: initialize .{method, event}_count via ARRAY_SIZE

Simon Ser contact at emersion.fr
Tue Jul 3 12:37:40 UTC 2018


On July 3, 2018 12:45 PM, Pekka Paalanen <ppaalanen at gmail.com> wrote:
> On Thu, 14 Jun 2018 16:49:45 +0100
> Emil Velikov <emil.l.velikov at gmail.com> wrote:
>
> > ---
> >  tests/data/example-code.c       | 73 +++++++++++++++++++++--------------------
> >  tests/data/small-code-core.c    |  5 +--
> >  tests/data/small-code.c         |  5 +--
> >  tests/data/small-private-code.c |  5 +--
> >  4 files changed, 46 insertions(+), 42 deletions(-)
> >
> > diff --git a/tests/data/example-code.c b/tests/data/example-code.c
> > index 2e1f73b..65d9651 100644
> > --- a/tests/data/example-code.c
> > +++ b/tests/data/example-code.c
> > @@ -146,6 +146,7 @@ static const struct wl_interface *types[] = {
> >  	[94] = &wl_surface_interface,
> >  };
> >
> > +#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
> >  static const struct wl_message wl_display_requests[] = {
> >  	{ .name = "sync", .signature = "n", .types = &types[8] },
> >  	{ .name = "get_registry", .signature = "n", .types = &types[9] },
> > @@ -158,8 +159,8 @@ static const struct wl_message wl_display_events[] = {
> >
> >  WL_EXPORT const struct wl_interface wl_display_interface = {
> >  	.name = "wl_display", .version = 1,
> > -	.method_count = 2, .methods = wl_display_requests,
> > -	.event_count = 2, .events = wl_display_events,
> > +	.method_count = ARRAY_SIZE(wl_display_requests), .methods = wl_display_requests,
> > +	.event_count = ARRAY_SIZE(wl_display_events), .events = wl_display_events,
> >  };
>
> Hi,
>
> this change is not an obvious improvement to me. "method_count = 2" is
> pretty clear, that combined with "methods = foo" does not seem to
> leave anything to be desired.
>
> If this code was hand-written, then I would be cheering for ARRAY_SIZE
> for sure, but it's not. It all comes from a generator that gets the
> count right.
>
> I suppose we'd need an opinion from someone who is less familiar with
> Wayland C bindings.

Hi,

I'm not sure if I qualify, but I would agree with Pekka here. This generated
code isn't meant to be maintained or edited by humans. This code is read-only,
and is readable enough as is IMHO for the reasons Pekka wrote.

> Thanks,
> pq
> _______________________________________________
> wayland-devel mailing list
> wayland-devel at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/wayland-devel


More information about the wayland-devel mailing list