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

Jason Ekstrand jason at jlekstrand.net
Fri Mar 8 20:26:12 PST 2013


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

diff --git a/src/connection.c b/src/connection.c
index 9d409e0..816392d 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -862,12 +862,13 @@ convert_arguments_to_ffi(const char *signature, uint32_t flags,
 
 void
 wl_closure_invoke(struct wl_closure *closure, uint32_t flags,
-		  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);
 
@@ -882,7 +883,8 @@ wl_closure_invoke(struct wl_closure *closure, uint32_t flags,
 	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 85a7fe0..5b3f5dc 100644
--- a/src/wayland-client.c
+++ b/src/wayland-client.c
@@ -837,8 +837,8 @@ 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, WL_CLOSURE_INVOKE_CLIENT, &proxy->object,
-				  proxy->object.implementation[opcode],
+		wl_closure_invoke(closure, WL_CLOSURE_INVOKE_CLIENT,
+				  &proxy->object, opcode,
 				  proxy->user_data);
 	}
 
diff --git a/src/wayland-private.h b/src/wayland-private.h
index 2df668d..3669ba9 100644
--- a/src/wayland-private.h
+++ b/src/wayland-private.h
@@ -137,7 +137,7 @@ enum wl_closure_invoke_flag {
 
 void
 wl_closure_invoke(struct wl_closure *closure, uint32_t flags,
-		  struct wl_object *target, void (*func)(void), void *data);
+		  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 aaecf29..130511d 100644
--- a/src/wayland-server.c
+++ b/src/wayland-server.c
@@ -278,7 +278,7 @@ wl_client_connection_data(int fd, uint32_t mask, void *data)
 			wl_closure_print(closure, object, false);
 
 		wl_closure_invoke(closure, WL_CLOSURE_INVOKE_SERVER, object,
-				  object->implementation[opcode], client);
+				  opcode, client);
 
 		wl_closure_destroy(closure);
 
diff --git a/tests/connection-test.c b/tests/connection-test.c
index d5b3a99..9a07d71 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, WL_CLOSURE_INVOKE_SERVER, &object, func, data);
+	wl_closure_invoke(closure, WL_CLOSURE_INVOKE_SERVER, &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, WL_CLOSURE_INVOKE_SERVER, &object, func, data);
+	wl_closure_invoke(closure, WL_CLOSURE_INVOKE_SERVER, &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, WL_CLOSURE_INVOKE_SERVER, &object, handler, &done);
+	wl_closure_invoke(closure, WL_CLOSURE_INVOKE_SERVER, &object, 0, &done);
 	wl_closure_destroy(closure);
 	assert(done);
 }
diff --git a/tests/os-wrappers-test.c b/tests/os-wrappers-test.c
index ce6fda6..77af873 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, WL_CLOSURE_INVOKE_SERVER, &object, func, data);
+	wl_closure_invoke(closure, WL_CLOSURE_INVOKE_SERVER, &object, 0, data);
 	wl_closure_destroy(closure);
 }
 
-- 
1.8.1.4



More information about the wayland-devel mailing list