[PATCH wayland 1/4] scanner: use c99 initializers for the wl_interface * array

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


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

Allows us to remove the explicit NULL init, keeping the list shorter and
easier to read.

Signed-off-by: Emil Velikov <emil.velikov at collabora.com>
---
 src/scanner.c | 26 +++++++++-----------------
 1 file changed, 9 insertions(+), 17 deletions(-)

diff --git a/src/scanner.c b/src/scanner.c
index c345ed6..c93ee60 100644
--- a/src/scanner.c
+++ b/src/scanner.c
@@ -1609,20 +1609,12 @@ emit_header(struct protocol *protocol, enum side side)
 	       "#endif\n");
 }
 
-static void
-emit_null_run(struct protocol *protocol)
-{
-	int i;
-
-	for (i = 0; i < protocol->null_run_length; i++)
-		printf("\tNULL,\n");
-}
-
 static void
 emit_types(struct protocol *protocol, struct wl_list *message_list)
 {
 	struct message *m;
 	struct arg *a;
+	int index;
 
 	wl_list_for_each(m, message_list, link) {
 		if (m->all_null) {
@@ -1633,21 +1625,22 @@ emit_types(struct protocol *protocol, struct wl_list *message_list)
 		m->type_index =
 			protocol->null_run_length + protocol->type_index;
 		protocol->type_index += m->arg_count;
+		index = m->type_index;
 
 		wl_list_for_each(a, &m->arg_list, link) {
 			switch (a->type) {
 			case NEW_ID:
 			case OBJECT:
-				if (a->interface_name)
-					printf("\t&%s_interface,\n",
-					       a->interface_name);
-				else
-					printf("\tNULL,\n");
-				break;
+				if (a->interface_name) {
+					printf("\t[%u] = &%s_interface,\n",
+					       index, a->interface_name);
+					break;
+				}
+			/* fallthrough */
 			default:
-				printf("\tNULL,\n");
 				break;
 			}
+			index++;
 		}
 	}
 }
@@ -1745,7 +1738,6 @@ emit_code(struct protocol *protocol)
 	printf("\n");
 
 	printf("static const struct wl_interface *types[] = {\n");
-	emit_null_run(protocol);
 	wl_list_for_each(i, &protocol->interface_list, link) {
 		emit_types(protocol, &i->request_list);
 		emit_types(protocol, &i->event_list);
-- 
2.14.1



More information about the wayland-devel mailing list