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

Emil Velikov emil.l.velikov at gmail.com
Wed Aug 30 15:21:15 UTC 2017


From: Emil Velikov <emil.velikov at collabora.com>

Signed-off-by: Emil Velikov <emil.velikov at collabora.com>
---
Since everything is interface->name based, one could even have a macro
that results in:

DEFINE_INTERFACE(zxdg_surface_v6, 1)
---
 src/scanner.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/src/scanner.c b/src/scanner.c
index b38af52..b53ab21 100644
--- a/src/scanner.c
+++ b/src/scanner.c
@@ -1744,6 +1744,7 @@ emit_code(struct protocol *protocol)
 	}
 	printf("};\n\n");
 
+	printf("#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))\n");
 	wl_list_for_each_safe(i, next, &protocol->interface_list, link) {
 
 		emit_messages(&i->request_list, i, "requests");
@@ -1755,12 +1756,12 @@ emit_code(struct protocol *protocol)
 		       i->name, i->name, i->version);
 
 		if (!wl_list_empty(&i->request_list))
-			printf("\t.method_count = %d, .methods = %s_requests,\n",
-			       wl_list_length(&i->request_list), i->name);
+			printf("\t.method_count = ARRAY_SIZE(%s_requests), .methods = %s_requests,\n",
+			       i->name, i->name);
 
 		if (!wl_list_empty(&i->event_list))
-			printf("\t.event_count = %d, .events = %s_events,\n",
-			       wl_list_length(&i->event_list), i->name);
+			printf("\t.event_count = ARRAY_SIZE(%s_events), .events = %s_events,\n",
+			       i->name, i->name);
 
 		printf("};\n\n");
 
-- 
2.14.1



More information about the wayland-devel mailing list