From: Kristian Høgsberg Date: Sun, 22 Apr 2012 17:49:35 +0000 (-0400) Subject: connection: Move closure object out of wl_connection X-Git-Tag: 0.94.90~87 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1901d66ffca2a10a3f24b918e5a4de56646f4f11;p=profile%2Fivi%2Fwayland.git connection: Move closure object out of wl_connection --- diff --git a/src/connection.c b/src/connection.c index 6967262..ffae35d 100644 --- a/src/connection.c +++ b/src/connection.c @@ -28,7 +28,6 @@ #include #include #include -#include #include #include #include @@ -48,16 +47,6 @@ struct wl_buffer { #define MASK(i) ((i) & 4095) -struct wl_closure { - int count; - const struct wl_message *message; - ffi_type *types[20]; - ffi_cif cif; - void *args[20]; - uint32_t buffer[256]; - uint32_t *start; -}; - #define MAX_FDS_OUT 28 #define CLEN (CMSG_LEN(MAX_FDS_OUT * sizeof(int32_t))) @@ -412,13 +401,12 @@ wl_connection_put_fd(struct wl_connection *connection, int32_t fd) return 0; } -struct wl_closure * -wl_connection_vmarshal(struct wl_connection *connection, - struct wl_object *sender, - uint32_t opcode, va_list ap, - const struct wl_message *message) +int +wl_closure_vmarshal(struct wl_closure *closure, + struct wl_object *sender, + uint32_t opcode, va_list ap, + const struct wl_message *message) { - struct wl_closure *closure = &connection->send_closure; struct wl_object **objectp, *object; uint32_t length, *p, *start, size, *end; int dup_fd; @@ -550,17 +538,18 @@ wl_connection_vmarshal(struct wl_connection *connection, closure->message = message; closure->count = count; - return closure; + return 0; err: printf("request too big to marshal, maximum size is %zu\n", sizeof closure->buffer); errno = ENOMEM; - return NULL; + return -1; } -struct wl_closure * +int wl_connection_demarshal(struct wl_connection *connection, + struct wl_closure *closure, uint32_t size, struct wl_map *objects, const struct wl_message *message) @@ -571,14 +560,13 @@ wl_connection_demarshal(struct wl_connection *connection, unsigned int i, count, extra_space; struct wl_object **object; struct wl_array **array; - struct wl_closure *closure = &connection->receive_closure; count = strlen(message->signature) + 2; if (count > ARRAY_LENGTH(closure->types)) { printf("too many args (%d)\n", count); errno = EINVAL; wl_connection_consume(connection, size); - return NULL; + return -1; } extra_space = wl_message_size_extra(message); @@ -587,7 +575,7 @@ wl_connection_demarshal(struct wl_connection *connection, sizeof closure->buffer, size + extra_space); errno = ENOMEM; wl_connection_consume(connection, size); - return NULL; + return -1; } closure->message = message; @@ -740,14 +728,14 @@ wl_connection_demarshal(struct wl_connection *connection, wl_connection_consume(connection, size); - return closure; + return 0; err: closure->count = i; wl_closure_destroy(closure); wl_connection_consume(connection, size); - return NULL; + return -1; } void diff --git a/src/wayland-client.c b/src/wayland-client.c index 794f716..fb69ed8 100644 --- a/src/wayland-client.c +++ b/src/wayland-client.c @@ -190,29 +190,29 @@ wl_proxy_add_listener(struct wl_proxy *proxy, WL_EXPORT void wl_proxy_marshal(struct wl_proxy *proxy, uint32_t opcode, ...) { - struct wl_closure *closure; + struct wl_closure closure; va_list ap; + int ret; va_start(ap, opcode); - closure = wl_connection_vmarshal(proxy->display->connection, - &proxy->object, opcode, ap, - &proxy->object.interface->methods[opcode]); + ret = wl_closure_vmarshal(&closure, &proxy->object, opcode, ap, + &proxy->object.interface->methods[opcode]); va_end(ap); - if (closure == NULL) { + if (ret) { fprintf(stderr, "Error marshalling request\n"); abort(); } - if (wl_closure_send(closure, proxy->display->connection)) { + if (wl_closure_send(&closure, proxy->display->connection)) { fprintf(stderr, "Error sending request: %m\n"); abort(); } if (wl_debug) - wl_closure_print(closure, &proxy->object, true); + wl_closure_print(&closure, &proxy->object, true); - wl_closure_destroy(closure); + wl_closure_destroy(&closure); } /* Can't do this, there may be more than one instance of an @@ -465,8 +465,9 @@ handle_event(struct wl_display *display, uint32_t id, uint32_t opcode, uint32_t size) { struct wl_proxy *proxy; - struct wl_closure *closure; + struct wl_closure closure; const struct wl_message *message; + int ret; proxy = wl_map_lookup(&display->objects, id); @@ -479,22 +480,22 @@ handle_event(struct wl_display *display, } message = &proxy->object.interface->events[opcode]; - closure = wl_connection_demarshal(display->connection, - size, &display->objects, message); + ret = wl_connection_demarshal(display->connection, &closure, + size, &display->objects, message); - if (closure == NULL) { + if (ret) { fprintf(stderr, "Error demarshalling event\n"); abort(); } if (wl_debug) - wl_closure_print(closure, &proxy->object, false); + wl_closure_print(&closure, &proxy->object, false); - wl_closure_invoke(closure, &proxy->object, + wl_closure_invoke(&closure, &proxy->object, proxy->object.implementation[opcode], proxy->user_data); - wl_closure_destroy(closure); + wl_closure_destroy(&closure); } WL_EXPORT void diff --git a/src/wayland-private.h b/src/wayland-private.h index b843e89..61b07a2 100644 --- a/src/wayland-private.h +++ b/src/wayland-private.h @@ -25,6 +25,7 @@ #define WAYLAND_PRIVATE_H #include +#include #include "wayland-util.h" #define WL_ZOMBIE_OBJECT ((void *) 2) @@ -69,17 +70,29 @@ int wl_connection_write(struct wl_connection *connection, const void *data, size int wl_connection_queue(struct wl_connection *connection, const void *data, size_t count); -struct wl_closure * -wl_connection_vmarshal(struct wl_connection *connection, - struct wl_object *sender, - uint32_t opcode, va_list ap, - const struct wl_message *message); +struct wl_closure { + int count; + const struct wl_message *message; + ffi_type *types[20]; + ffi_cif cif; + void *args[20]; + uint32_t buffer[256]; + uint32_t *start; +}; + +int +wl_closure_vmarshal(struct wl_closure *closure, + struct wl_object *sender, + uint32_t opcode, va_list ap, + const struct wl_message *message); -struct wl_closure * +int wl_connection_demarshal(struct wl_connection *connection, + struct wl_closure *closure, uint32_t size, struct wl_map *objects, const struct wl_message *message); + void wl_closure_invoke(struct wl_closure *closure, struct wl_object *target, void (*func)(void), void *data); diff --git a/src/wayland-server.c b/src/wayland-server.c index 1fe00a9..94eb308 100644 --- a/src/wayland-server.c +++ b/src/wayland-server.c @@ -102,54 +102,54 @@ destroy_client(void *data) WL_EXPORT void wl_resource_post_event(struct wl_resource *resource, uint32_t opcode, ...) { - struct wl_closure *closure; + struct wl_closure closure; struct wl_object *object = &resource->object; va_list ap; + int ret; va_start(ap, opcode); - closure = wl_connection_vmarshal(resource->client->connection, - object, opcode, ap, - &object->interface->events[opcode]); + ret = wl_closure_vmarshal(&closure, object, opcode, ap, + &object->interface->events[opcode]); va_end(ap); - if (closure == NULL) + if (ret) return; - if (wl_closure_send(closure, resource->client->connection)) + if (wl_closure_send(&closure, resource->client->connection)) wl_event_loop_add_idle(resource->client->display->loop, destroy_client, resource->client); if (wl_debug) - wl_closure_print(closure, object, true); + wl_closure_print(&closure, object, true); - wl_closure_destroy(closure); + wl_closure_destroy(&closure); } WL_EXPORT void wl_resource_queue_event(struct wl_resource *resource, uint32_t opcode, ...) { - struct wl_closure *closure; + struct wl_closure closure; struct wl_object *object = &resource->object; va_list ap; + int ret; va_start(ap, opcode); - closure = wl_connection_vmarshal(resource->client->connection, - object, opcode, ap, - &object->interface->events[opcode]); + ret = wl_closure_vmarshal(&closure, object, opcode, ap, + &object->interface->events[opcode]); va_end(ap); - if (closure == NULL) + if (ret) return; - if (wl_closure_queue(closure, resource->client->connection)) + if (wl_closure_queue(&closure, resource->client->connection)) wl_event_loop_add_idle(resource->client->display->loop, destroy_client, resource->client); if (wl_debug) - wl_closure_print(closure, object, true); + wl_closure_print(&closure, object, true); - wl_closure_destroy(closure); + wl_closure_destroy(&closure); } WL_EXPORT void @@ -187,12 +187,12 @@ wl_client_connection_data(int fd, uint32_t mask, void *data) struct wl_connection *connection = client->connection; struct wl_resource *resource; struct wl_object *object; - struct wl_closure *closure; + struct wl_closure closure; const struct wl_message *message; uint32_t p[2]; int opcode, size; uint32_t cmask = 0; - int len; + int len, ret; if (mask & WL_EVENT_READABLE) cmask |= WL_CONNECTION_READABLE; @@ -232,11 +232,11 @@ wl_client_connection_data(int fd, uint32_t mask, void *data) } message = &object->interface->methods[opcode]; - closure = wl_connection_demarshal(client->connection, size, - &client->objects, message); + ret = wl_connection_demarshal(client->connection, &closure, + size, &client->objects, message); len -= size; - if (closure == NULL && errno == EINVAL) { + if (ret && errno == EINVAL) { wl_resource_post_error(client->display_resource, WL_DISPLAY_ERROR_INVALID_METHOD, "invalid arguments for %s@%d.%s", @@ -244,18 +244,18 @@ wl_client_connection_data(int fd, uint32_t mask, void *data) object->id, message->name); break; - } else if (closure == NULL && errno == ENOMEM) { + } else if (ret && errno == ENOMEM) { wl_resource_post_no_memory(resource); break; } if (wl_debug) - wl_closure_print(closure, object, false); + wl_closure_print(&closure, object, false); - wl_closure_invoke(closure, object, + wl_closure_invoke(&closure, object, object->implementation[opcode], client); - wl_closure_destroy(closure); + wl_closure_destroy(&closure); if (client->error) break; diff --git a/tests/Makefile.am b/tests/Makefile.am index 5bb4784..eaf4dd8 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -29,7 +29,7 @@ os_wrappers_test_SOURCES = \ ../src/wayland-os.c \ $(test_runner_src) -AM_CFLAGS = $(GCC_CFLAGS) +AM_CFLAGS = $(GCC_CFLAGS) $(FFI_CFLAGS) LDADD = $(top_builddir)/src/libwayland-util.la \ $(top_builddir)/src/libwayland-server.la \ -lrt -ldl $(FFI_LIBS) diff --git a/tests/connection-test.c b/tests/connection-test.c index a4d76b7..72c32e6 100644 --- a/tests/connection-test.c +++ b/tests/connection-test.c @@ -185,20 +185,20 @@ release_marshal_data(struct marshal_data *data) static void marshal(struct marshal_data *data, const char *format, int size, ...) { - struct wl_closure *closure; + struct wl_closure closure; static const uint32_t opcode = 4444; static struct wl_object sender = { NULL, NULL, 1234 }; struct wl_message message = { "test", format, NULL }; va_list ap; + int ret; va_start(ap, size); - closure = wl_connection_vmarshal(data->write_connection, - &sender, opcode, ap, &message); + ret = wl_closure_vmarshal(&closure, &sender, opcode, ap, &message); va_end(ap); - assert(closure); - assert(wl_closure_send(closure, data->write_connection) == 0); - wl_closure_destroy(closure); + assert(ret == 0); + assert(wl_closure_send(&closure, data->write_connection) == 0); + wl_closure_destroy(&closure); assert(data->write_mask == (WL_CONNECTION_WRITABLE | WL_CONNECTION_READABLE)); assert(wl_connection_data(data->write_connection, @@ -292,10 +292,10 @@ demarshal(struct marshal_data *data, const char *format, uint32_t *msg, void (*func)(void)) { struct wl_message message = { "test", format, NULL }; - struct wl_closure *closure; + struct wl_closure closure; struct wl_map objects; struct wl_object object; - int size = msg[1]; + int size = msg[1], ret; assert(write(data->s[1], msg, size) == size); assert(wl_connection_data(data->read_connection, @@ -303,9 +303,10 @@ demarshal(struct marshal_data *data, const char *format, wl_map_init(&objects); object.id = msg[0]; - closure = wl_connection_demarshal(data->read_connection, - size, &objects, &message); - wl_closure_invoke(closure, &object, func, data); + ret = wl_connection_demarshal(data->read_connection, + &closure, size, &objects, &message); + assert(ret == 0); + wl_closure_invoke(&closure, &object, func, data); } TEST(connection_demarshal) @@ -341,7 +342,7 @@ static void marshal_demarshal(struct marshal_data *data, void (*func)(void), int size, const char *format, ...) { - struct wl_closure *closure; + struct wl_closure closure; static const int opcode = 4444; static struct wl_object sender = { NULL, NULL, 1234 }; struct wl_message message = { "test", format, NULL }; @@ -349,15 +350,15 @@ marshal_demarshal(struct marshal_data *data, struct wl_object object; va_list ap; uint32_t msg[1] = { 1234 }; + int ret; va_start(ap, format); - closure = wl_connection_vmarshal(data->write_connection, - &sender, opcode, ap, &message); + ret = wl_closure_vmarshal(&closure, &sender, opcode, ap, &message); va_end(ap); - assert(closure); - assert(wl_closure_send(closure, data->write_connection) == 0); - wl_closure_destroy(closure); + assert(ret == 0); + assert(wl_closure_send(&closure, data->write_connection) == 0); + wl_closure_destroy(&closure); assert(data->write_mask == (WL_CONNECTION_WRITABLE | WL_CONNECTION_READABLE)); assert(wl_connection_data(data->write_connection, @@ -369,11 +370,10 @@ marshal_demarshal(struct marshal_data *data, wl_map_init(&objects); object.id = msg[0]; - closure = wl_connection_demarshal(data->read_connection, - size, &objects, &message); - wl_closure_invoke(closure, &object, func, data); - - wl_closure_destroy(closure); + ret = wl_connection_demarshal(data->read_connection, + &closure, size, &objects, &message); + wl_closure_invoke(&closure, &object, func, data); + wl_closure_destroy(&closure); } TEST(connection_marshal_demarshal)