swc

Unnamed repository; edit this file 'description' to name the repository.
git clone git://git.nihaljere.xyz/swc
Log | Files | Refs | README | LICENSE

commit a58644c88ff5f43d89b953c36cdf97c8aada9a5e
parent 7bb6813db2057c9101170533e4c771c9a81a3852
Author: Michael Forney <mforney@mforney.org>
Date:   Wed,  3 Jul 2013 21:49:38 -0700

Use our own container_of macro

wl_container_of doesn't work when the sample argument is uninitialized
because the compiler optimizes it away as a garbage value.

Diffstat:
Mcompositor.c | 15++++++++-------
Mdata_device.c | 4++--
Minput_focus.c | 8++------
Mkeyboard.c | 2+-
Mpointer.c | 2+-
Mseat.c | 10+++++-----
Msurface.c | 2+-
Mutil.h | 9+++++++++
8 files changed, 29 insertions(+), 23 deletions(-)

diff --git a/compositor.c b/compositor.c @@ -10,6 +10,7 @@ #include "event.h" #include "region.h" #include "data_device_manager.h" +#include "util.h" static const char default_seat[] = "seat0"; @@ -58,8 +59,8 @@ static bool handle_key(struct swc_keyboard * keyboard, uint32_t time, struct swc_compositor * compositor; char keysym_name[64]; - seat = wl_container_of(keyboard, seat, keyboard); - compositor = wl_container_of(seat, compositor, seat); + seat = swc_container_of(keyboard, typeof(*seat), keyboard); + compositor = swc_container_of(seat, typeof(*compositor), seat); if (state == WL_KEYBOARD_KEY_STATE_PRESSED) { @@ -139,8 +140,8 @@ static bool handle_motion(struct swc_pointer * pointer, uint32_t time) struct swc_seat * seat; struct swc_compositor * compositor; - seat = wl_container_of(pointer, seat, pointer); - compositor = wl_container_of(seat, compositor, seat); + seat = swc_container_of(pointer, typeof(*seat), pointer); + compositor = swc_container_of(seat, typeof(*compositor), seat); return false; } @@ -156,7 +157,7 @@ static void handle_tty_event(struct wl_listener * listener, void * data) struct swc_event * event = data; struct swc_compositor * compositor; - compositor = wl_container_of(listener, compositor, tty_listener); + compositor = swc_container_of(listener, typeof(*compositor), tty_listener); switch (event->type) { @@ -201,7 +202,7 @@ static void handle_drm_event(struct wl_listener * listener, void * data) struct swc_event * event = data; struct swc_compositor * compositor; - compositor = wl_container_of(listener, compositor, drm_listener); + compositor = swc_container_of(listener, typeof(*compositor), drm_listener); switch (event->type) { @@ -275,7 +276,7 @@ static void create_surface(struct wl_client * client, printf("compositor_create_surface: %p\n", surface); - output = wl_container_of(compositor->outputs.next, output, link); + output = swc_container_of(compositor->outputs.next, typeof(*output), link); /* Initialize compositor state */ surface->compositor_state = (struct swc_compositor_surface_state) { diff --git a/data_device.c b/data_device.c @@ -70,8 +70,8 @@ struct wl_data_device_interface data_device_implementation = { static void handle_selection_destroy(struct wl_listener * listener, void * data) { - struct swc_data_device * data_device - = wl_container_of(listener, data_device, selection_destroy_listener); + struct swc_data_device * data_device = swc_container_of + (listener, typeof(*data_device), selection_destroy_listener); struct swc_event event; event.type = SWC_DATA_DEVICE_EVENT_SELECTION_CHANGED; diff --git a/input_focus.c b/input_focus.c @@ -58,12 +58,8 @@ static inline void unfocus(struct swc_input_focus * input_focus) static void handle_focus_surface_destroy(struct wl_listener * listener, void * data) { - struct swc_input_focus * input_focus; - - printf("focus surface destroy\n"); - - input_focus = wl_container_of(listener, input_focus, - surface_destroy_listener); + struct swc_input_focus * input_focus = swc_container_of + (listener, typeof(*input_focus), surface_destroy_listener); input_focus->surface = NULL; input_focus->resource = NULL; diff --git a/keyboard.c b/keyboard.c @@ -11,7 +11,7 @@ static void enter(struct swc_input_focus_handler * handler, struct wl_display * display; uint32_t serial; - keyboard = wl_container_of(handler, keyboard, focus_handler); + keyboard = swc_container_of(handler, typeof(*keyboard), focus_handler); client = wl_resource_get_client(resource); display = wl_client_get_display(client); serial = wl_display_next_serial(display); diff --git a/pointer.c b/pointer.c @@ -13,7 +13,7 @@ static void enter(struct swc_input_focus_handler * handler, uint32_t serial; wl_fixed_t surface_x, surface_y; - pointer = wl_container_of(handler, pointer, focus_handler); + pointer = swc_container_of(handler, typeof(*pointer), focus_handler); client = wl_resource_get_client(resource); display = wl_client_get_display(client); serial = wl_display_next_serial(display); diff --git a/seat.c b/seat.c @@ -134,7 +134,7 @@ static void handle_evdev_event(struct wl_listener * listener, void * data) struct swc_event * event = data; struct swc_evdev_device_event_data * evdev_data = event->data; - entry = wl_container_of(listener, entry, event_listener); + entry = swc_container_of(listener, typeof(*entry), event_listener); switch (event->type) { @@ -159,8 +159,8 @@ static void handle_evdev_event(struct wl_listener * listener, void * data) static void handle_keyboard_focus_event(struct wl_listener * listener, void * data) { - struct swc_seat * seat - = wl_container_of(listener, seat, keyboard_focus_listener); + struct swc_seat * seat = swc_container_of + (listener, typeof(*seat), keyboard_focus_listener); struct swc_event * event = data; struct swc_input_focus_event_data * event_data = event->data; @@ -181,8 +181,8 @@ static void handle_keyboard_focus_event(struct wl_listener * listener, static void handle_data_device_event(struct wl_listener * listener, void * data) { - struct swc_seat * seat - = wl_container_of(listener, seat, data_device_listener); + struct swc_seat * seat = swc_container_of + (listener, typeof(*seat), data_device_listener); struct swc_event * event = data; switch (event->type) diff --git a/surface.c b/surface.c @@ -18,7 +18,7 @@ static void handle_buffer_destroy(struct wl_listener * listener, void * data) { struct swc_surface_state * state; - state = wl_container_of(listener, state, buffer_destroy_listener); + state = swc_container_of(listener, typeof(*state), buffer_destroy_listener); state->buffer = NULL; } diff --git a/util.h b/util.h @@ -4,6 +4,15 @@ #include <stdbool.h> #include <wayland-server.h> +#ifndef offsetof +# define offsetof __builtin_offsetof +#endif + +#define swc_container_of(ptr, type, member) ({ \ + const typeof(((type *) 0)->member) *__mptr = (ptr); \ + ((type *) ((uintptr_t) __mptr - offsetof(type, member))); \ +}) + void swc_remove_resource(struct wl_resource * resource); int swc_launch_open_input_device(int socket, const char * path, int flags);