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

Emil Velikov emil.l.velikov at gmail.com
Tue Jul 3 14:37:59 UTC 2018


On 3 July 2018 at 12:45, 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.
>
Sure ARRAY_SIZE is used for getting thins "right" although it also
improves _readability_.

Pre-patch (series) it took me an embarrassing amount of time trying to
understand any of the magic created by the scanner.
Perhaps I'm just silly in trying to spare the next reader some time...

It's trivial change and basic coding practise.

HTH
Emil


More information about the wayland-devel mailing list