[PATCH weston 2/3] xwm: Make hash_table_lookup use an output parameter
Pekka Paalanen
ppaalanen at gmail.com
Wed Apr 8 05:26:19 PDT 2015
On Tue, 7 Apr 2015 12:12:14 -0500
Derek Foreman <derekf at osg.samsung.com> wrote:
> 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 <derekf at osg.samsung.com>
> ---
> 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)
int for a boolean? ;-)
Apart from that,
Reviewed-by: Pekka Paalanen <pekka.paalanen at collabora.co.uk>
> {
> 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));
I suppose this really isn't used for anything else than
weston_wm_window, so ok for now.
Thanks,
pq
More information about the wayland-devel
mailing list