When designing the original Waffle 1.0 API, I made a mistake when I chose to declare attribute lists as arrays of int32_t. Instead, they should have been arrays of intptr_t.
A new public function, waffle_window_create2, will have a `const intptr_t attrib_list[]` parameter. Therefore waffle needs intptr_t variants of the wcore_attrib_list functions. Signed-off-by: Chad Versace <[email protected]> --- src/waffle/core/wcore_attrib_list.c | 73 +++++++++++++++++++++++++++++++++++++ src/waffle/core/wcore_attrib_list.h | 23 ++++++++++++ 2 files changed, 96 insertions(+) diff --git a/src/waffle/core/wcore_attrib_list.c b/src/waffle/core/wcore_attrib_list.c index 09a4dec..a7f087d 100644 --- a/src/waffle/core/wcore_attrib_list.c +++ b/src/waffle/core/wcore_attrib_list.c @@ -29,6 +29,79 @@ #include <stdint.h> #include <stddef.h> +size_t +wcore_attrib_list_length(const intptr_t attrib_list[]) +{ + const intptr_t *i = attrib_list; + + if (attrib_list == NULL) + return 0; + + while (*i != 0) + i += 2; + + return (i - attrib_list) / 2; +} + +bool +wcore_attrib_list_get( + const intptr_t *attrib_list, + intptr_t key, + intptr_t *value) +{ + if (attrib_list == NULL) + return false; + + for (size_t i = 0; attrib_list[i] != 0; i += 2) { + if (attrib_list[i] != key) + continue; + + *value = attrib_list[i + 1]; + return true; + } + + return false; +} + +bool +wcore_attrib_list_get_with_default( + const intptr_t attrib_list[], + intptr_t key, + intptr_t *value, + intptr_t default_value) +{ + if (wcore_attrib_list_get(attrib_list, key, value)) { + return true; + } + else { + *value = default_value; + return false; + } +} + +bool +wcore_attrib_list_update( + intptr_t *attrib_list, + intptr_t key, + intptr_t value) +{ + intptr_t *i = attrib_list; + + if (attrib_list == NULL) + return false; + + while (*i != 0 && *i != key) + i += 2; + + if (*i == key) { + i[1] = value; + return true; + } + else { + return false; + } +} + int32_t wcore_attrib_list32_length(const int32_t attrib_list[]) { diff --git a/src/waffle/core/wcore_attrib_list.h b/src/waffle/core/wcore_attrib_list.h index 8339578..5e6473b 100644 --- a/src/waffle/core/wcore_attrib_list.h +++ b/src/waffle/core/wcore_attrib_list.h @@ -27,6 +27,29 @@ #include <stdbool.h> #include <stdint.h> +#include <stdlib.h> + +size_t +wcore_attrib_list_length(const intptr_t attrib_list[]); + +bool +wcore_attrib_list_get( + const intptr_t *attrib_list, + intptr_t key, + intptr_t *value); + +bool +wcore_attrib_list_get_with_default( + const intptr_t attrib_list[], + intptr_t key, + intptr_t *value, + intptr_t default_value); + +bool +wcore_attrib_list_update( + intptr_t *attrib_list, + intptr_t key, + intptr_t value); int32_t wcore_attrib_list32_length(const int32_t attrib_list[]); -- 2.2.0 _______________________________________________ waffle mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/waffle

