Previously hash_table_lookup returned a pointer which must always be tested for NULL - but rarely was.
Now hash_table_lookup returns the found data as an out parameter and returns an integer indicating whether the lookup succeeded or not. This lets us flag the return value as warn_unused_result so the compiler can stop us from missing the test. Signed-off-by: Derek Foreman <[email protected]> --- xwayland/hash.c | 15 +++++++++------ xwayland/hash.h | 6 +++++- xwayland/window-manager.c | 29 ++++++++++++++--------------- 3 files changed, 28 insertions(+), 22 deletions(-) diff --git a/xwayland/hash.c b/xwayland/hash.c index 54f3de9..2e5ecfc 100644 --- a/xwayland/hash.c +++ b/xwayland/hash.c @@ -201,16 +201,19 @@ hash_table_for_each(struct hash_table *ht, } } -void * -hash_table_lookup(struct hash_table *ht, uint32_t hash) +int +hash_table_lookup(struct hash_table *ht, uint32_t hash, + struct weston_wm_window **ret) { struct hash_entry *entry; entry = hash_table_search(ht, hash); - if (entry != NULL) - return entry->data; - - return NULL; + if (entry != NULL) { + *ret = entry->data; + return 1; + } + *ret = NULL; + return 0; } static void diff --git a/xwayland/hash.h b/xwayland/hash.h index 6e1674e..b181f19 100644 --- a/xwayland/hash.h +++ b/xwayland/hash.h @@ -36,11 +36,15 @@ #define HASH_H struct hash_table; +struct weston_wm_window; struct hash_table *hash_table_create(void); typedef void (*hash_table_iterator_func_t)(void *element, void *data); void hash_table_destroy(struct hash_table *ht); -void *hash_table_lookup(struct hash_table *ht, uint32_t hash); +int hash_table_lookup(struct hash_table *ht, uint32_t hash, + struct weston_wm_window **ret) + __attribute__ ((warn_unused_result)); + int hash_table_insert(struct hash_table *ht, uint32_t hash, void *data); void hash_table_remove(struct hash_table *ht, uint32_t hash); void hash_table_for_each(struct hash_table *ht, diff --git a/xwayland/window-manager.c b/xwayland/window-manager.c index 83ebfae..3967670 100644 --- a/xwayland/window-manager.c +++ b/xwayland/window-manager.c @@ -448,8 +448,7 @@ weston_wm_window_read_properties(struct weston_wm_window *window) break; case XCB_ATOM_WINDOW: xid = xcb_get_property_value(reply); - *(struct weston_wm_window **) p = - hash_table_lookup(wm->window_hash, *xid); + hash_table_lookup(wm->window_hash, *xid, (struct weston_wm_window **)p); break; case XCB_ATOM_CARDINAL: case XCB_ATOM_ATOM: @@ -594,7 +593,7 @@ weston_wm_handle_configure_request(struct weston_wm *wm, xcb_generic_event_t *ev configure_request->x, configure_request->y, configure_request->width, configure_request->height); - window = hash_table_lookup(wm->window_hash, configure_request->window); + hash_table_lookup(wm->window_hash, configure_request->window, &window); if (window->fullscreen) { weston_wm_window_send_configure_notify(window); @@ -660,7 +659,7 @@ weston_wm_handle_configure_notify(struct weston_wm *wm, xcb_generic_event_t *eve configure_notify->x, configure_notify->y, configure_notify->width, configure_notify->height); - window = hash_table_lookup(wm->window_hash, configure_notify->window); + hash_table_lookup(wm->window_hash, configure_notify->window, &window); window->x = configure_notify->x; window->y = configure_notify->y; if (window->override_redirect) { @@ -932,7 +931,7 @@ weston_wm_handle_map_request(struct weston_wm *wm, xcb_generic_event_t *event) return; } - window = hash_table_lookup(wm->window_hash, map_request->window); + hash_table_lookup(wm->window_hash, map_request->window, &window); weston_wm_window_read_properties(window); @@ -984,7 +983,7 @@ weston_wm_handle_unmap_notify(struct weston_wm *wm, xcb_generic_event_t *event) * as it may come in after we've destroyed the window. */ return; - window = hash_table_lookup(wm->window_hash, unmap_notify->window); + hash_table_lookup(wm->window_hash, unmap_notify->window, &window); if (wm->focus_window == window) wm->focus_window = NULL; if (window->surface) @@ -1113,7 +1112,7 @@ weston_wm_handle_property_notify(struct weston_wm *wm, xcb_generic_event_t *even (xcb_property_notify_event_t *) event; struct weston_wm_window *window; - window = hash_table_lookup(wm->window_hash, property_notify->window); + hash_table_lookup(wm->window_hash, property_notify->window, &window); if (!window) return; @@ -1232,7 +1231,7 @@ weston_wm_handle_destroy_notify(struct weston_wm *wm, xcb_generic_event_t *event if (our_resource(wm, destroy_notify->window)) return; - window = hash_table_lookup(wm->window_hash, destroy_notify->window); + hash_table_lookup(wm->window_hash, destroy_notify->window, &window); weston_wm_window_destroy(window); } @@ -1253,8 +1252,8 @@ weston_wm_handle_reparent_notify(struct weston_wm *wm, xcb_generic_event_t *even reparent_notify->x, reparent_notify->y, reparent_notify->override_redirect); } else if (!our_resource(wm, reparent_notify->parent)) { - window = hash_table_lookup(wm->window_hash, - reparent_notify->window); + hash_table_lookup(wm->window_hash, + reparent_notify->window, &window); weston_wm_window_destroy(window); } } @@ -1492,7 +1491,7 @@ weston_wm_handle_client_message(struct weston_wm *wm, (xcb_client_message_event_t *) event; struct weston_wm_window *window; - window = hash_table_lookup(wm->window_hash, client_message->window); + hash_table_lookup(wm->window_hash, client_message->window, &window); wm_log("XCB_CLIENT_MESSAGE (%s %d %d %d %d %d win %d)\n", get_atom_name(wm->conn, client_message->type), @@ -1722,7 +1721,7 @@ weston_wm_handle_button(struct weston_wm *wm, xcb_generic_event_t *event) button->response_type == XCB_BUTTON_PRESS ? "PRESS" : "RELEASE", button->detail); - window = hash_table_lookup(wm->window_hash, button->event); + hash_table_lookup(wm->window_hash, button->event, &window); if (!window || !window->decorate) return; @@ -1786,7 +1785,7 @@ weston_wm_handle_motion(struct weston_wm *wm, xcb_generic_event_t *event) enum theme_location location; int cursor; - window = hash_table_lookup(wm->window_hash, motion->event); + hash_table_lookup(wm->window_hash, motion->event, &window); if (!window || !window->decorate) return; @@ -1807,7 +1806,7 @@ weston_wm_handle_enter(struct weston_wm *wm, xcb_generic_event_t *event) enum theme_location location; int cursor; - window = hash_table_lookup(wm->window_hash, enter->event); + hash_table_lookup(wm->window_hash, enter->event, &window); if (!window || !window->decorate) return; @@ -1826,7 +1825,7 @@ weston_wm_handle_leave(struct weston_wm *wm, xcb_generic_event_t *event) xcb_leave_notify_event_t *leave = (xcb_leave_notify_event_t *) event; struct weston_wm_window *window; - window = hash_table_lookup(wm->window_hash, leave->event); + hash_table_lookup(wm->window_hash, leave->event, &window); if (!window || !window->decorate) return; -- 2.1.4 _______________________________________________ wayland-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/wayland-devel
