[RFC wayland 1/4] Change wl_closure_invoke to take an opcode instead of an actual function pointer

Jason Ekstrand jason at jlekstrand.net
Wed Feb 27 19:29:55 PST 2013


Signed-off-by: Jason Ekstrand <jason at jlekstrand.net>
---
 src/connection.c         |  6 ++++--
 src/wayland-client.c     |  3 +--
 src/wayland-private.h    |  4 ++--
 src/wayland-server.c     |  3 +--
 tests/connection-test.c  | 13 +++++++------
 tests/os-wrappers-test.c |  4 ++--
 6 files changed, 17 insertions(+), 16 deletions(-)

diff --git a/src/connection.c b/src/connection.c
index 93f0105..d68f959 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -856,12 +856,13 @@ convert_arguments_to_ffi(const char *signature, union wl_argument *args,
 
 void
 wl_closure_invoke(struct wl_closure *closure,
-		  struct wl_object *target, void (*func)(void), void *data)
+		  struct wl_object *target, uint32_t opcode, void *data)
 {
 	int count;
 	ffi_cif cif;
 	ffi_type *ffi_types[WL_CLOSURE_MAX_ARGS + 2];
 	void * ffi_args[WL_CLOSURE_MAX_ARGS + 2];
+	void (* const *implementation)(void);
 
 	count = arg_count_for_signature(closure->message->signature);
 
@@ -876,7 +877,8 @@ wl_closure_invoke(struct wl_closure *closure,
 	ffi_prep_cif(&cif, FFI_DEFAULT_ABI,
 		     count + 2, &ffi_type_void, ffi_types);
 
-	ffi_call(&cif, func, NULL, ffi_args);
+	implementation = target->implementation;
+	ffi_call(&cif, implementation[opcode], NULL, ffi_args);
 }
 
 static int
diff --git a/src/wayland-client.c b/src/wayland-client.c
index 2f551f9..e8cf7a2 100644
--- a/src/wayland-client.c
+++ b/src/wayland-client.c
@@ -836,8 +836,7 @@ dispatch_event(struct wl_display *display, struct wl_event_queue *queue)
 		if (wl_debug)
 			wl_closure_print(closure, &proxy->object, false);
 
-		wl_closure_invoke(closure, &proxy->object,
-				  proxy->object.implementation[opcode],
+		wl_closure_invoke(closure, &proxy->object, opcode,
 				  proxy->user_data);
 	}
 
diff --git a/src/wayland-private.h b/src/wayland-private.h
index f0c9010..cb92e51 100644
--- a/src/wayland-private.h
+++ b/src/wayland-private.h
@@ -130,8 +130,8 @@ int
 wl_closure_lookup_objects(struct wl_closure *closure, struct wl_map *objects);
 
 void
-wl_closure_invoke(struct wl_closure *closure,
-		  struct wl_object *target, void (*func)(void), void *data);
+wl_closure_invoke(struct wl_closure *closure, struct wl_object *target,
+		  uint32_t opcode, void *data);
 int
 wl_closure_send(struct wl_closure *closure, struct wl_connection *connection);
 int
diff --git a/src/wayland-server.c b/src/wayland-server.c
index 2f3ddc9..e45b880 100644
--- a/src/wayland-server.c
+++ b/src/wayland-server.c
@@ -277,8 +277,7 @@ wl_client_connection_data(int fd, uint32_t mask, void *data)
 		if (wl_debug)
 			wl_closure_print(closure, object, false);
 
-		wl_closure_invoke(closure, object,
-				  object->implementation[opcode], client);
+		wl_closure_invoke(closure, object, opcode, client);
 
 		wl_closure_destroy(closure);
 
diff --git a/tests/connection-test.c b/tests/connection-test.c
index 1ac88d2..0f6667b 100644
--- a/tests/connection-test.c
+++ b/tests/connection-test.c
@@ -327,7 +327,7 @@ demarshal(struct marshal_data *data, const char *format,
 	struct wl_message message = { "test", format, NULL };
 	struct wl_closure *closure;
 	struct wl_map objects;
-	struct wl_object object;
+	struct wl_object object = { NULL, &func, 0 };
 	int size = msg[1];
 
 	assert(write(data->s[1], msg, size) == size);
@@ -338,7 +338,7 @@ demarshal(struct marshal_data *data, const char *format,
 	closure = wl_connection_demarshal(data->read_connection,
 					  size, &objects, &message);
 	assert(closure);
-	wl_closure_invoke(closure, &object, func, data);
+	wl_closure_invoke(closure, &object, 0, data);
 	wl_closure_destroy(closure);
 }
 
@@ -399,7 +399,7 @@ marshal_demarshal(struct marshal_data *data,
 	static struct wl_object sender = { NULL, NULL, 1234 };
 	struct wl_message message = { "test", format, NULL };
 	struct wl_map objects;
-	struct wl_object object;
+	struct wl_object object = { NULL, &func, 0 };
 	va_list ap;
 	uint32_t msg[1] = { 1234 };
 
@@ -418,7 +418,7 @@ marshal_demarshal(struct marshal_data *data,
 	object.id = msg[0];
 	closure = wl_connection_demarshal(data->read_connection,
 					  size, &objects, &message);
-	wl_closure_invoke(closure, &object, func, data);
+	wl_closure_invoke(closure, &object, 0, data);
 	wl_closure_destroy(closure);
 }
 
@@ -493,7 +493,8 @@ static void
 marshal_helper(const char *format, void *handler, ...)
 {
 	struct wl_closure *closure;
-	static struct wl_object sender = { NULL, NULL, 1234 }, object;
+	static struct wl_object sender = { NULL, NULL, 1234 };
+	struct wl_object object = { NULL, &handler, 0 };
 	static const int opcode = 4444;
 	struct wl_message message = { "test", format, NULL };
 	va_list ap;
@@ -505,7 +506,7 @@ marshal_helper(const char *format, void *handler, ...)
 
 	assert(closure);
 	done = 0;
-	wl_closure_invoke(closure, &object, handler, &done);
+	wl_closure_invoke(closure, &object, 0, &done);
 	wl_closure_destroy(closure);
 	assert(done);
 }
diff --git a/tests/os-wrappers-test.c b/tests/os-wrappers-test.c
index 515fd81..cdbe199 100644
--- a/tests/os-wrappers-test.c
+++ b/tests/os-wrappers-test.c
@@ -233,7 +233,7 @@ marshal_demarshal(struct marshal_data *data,
 	static struct wl_object sender = { NULL, NULL, 1234 };
 	struct wl_message message = { "test", format, NULL };
 	struct wl_map objects;
-	struct wl_object object;
+	struct wl_object object = { NULL, &func, 1234 };
 	va_list ap;
 	uint32_t msg[1] = { 1234 };
 
@@ -252,7 +252,7 @@ marshal_demarshal(struct marshal_data *data,
 	object.id = msg[0];
 	closure = wl_connection_demarshal(data->read_connection,
 					  size, &objects, &message);
-	wl_closure_invoke(closure, &object, func, data);
+	wl_closure_invoke(closure, &object, 0, data);
 	wl_closure_destroy(closure);
 }
 
-- 
1.8.1.2



More information about the wayland-devel mailing list