<div dir="ltr"><div>Ignore these.  Turns out I was trying to fix the wrong issue.  New patches to come<br></div>-- Jason Ekstrand<br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, May 29, 2013 at 10:06 PM, Jason Ekstrand <span dir="ltr"><<a href="mailto:jason@jlekstrand.net" target="_blank">jason@jlekstrand.net</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">This commit cleans up the internals of wl_map by splitting it into two<br>
wl_simple_maps.  This both makes the internals cleaner and also fixes potential<br>
issues with having a single free_list for both sides of the map.<br>
<br>
Signed-off-by: Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>><br>
---<br>
<br>
</div>Ignore the previous patch as it contained an error.  This one is the correct one.<br>
<br>
 src/wayland-private.h |  10 ++-<br>
 src/wayland-util.c    | 177 +++++++++++++++++++++++++++-----------------------<br>
 2 files changed, 102 insertions(+), 85 deletions(-)<br>
<div class="im"><br>
diff --git a/src/wayland-private.h b/src/wayland-private.h<br>
index c4ce6b0..a733a96 100644<br>
--- a/src/wayland-private.h<br>
+++ b/src/wayland-private.h<br>
@@ -41,12 +41,16 @@<br>
 #define WL_SERVER_ID_START 0xff000000<br>
 #define WL_CLOSURE_MAX_ARGS 20<br>
<br>
-struct wl_map {<br>
-       struct wl_array client_entries;<br>
-       struct wl_array server_entries;<br>
+struct wl_simple_map {<br>
+       struct wl_array entries;<br>
        uint32_t free_list;<br>
 };<br>
<br>
+struct wl_map {<br>
+       struct wl_simple_map client_map;<br>
+       struct wl_simple_map server_map;<br>
+};<br>
+<br>
 typedef void (*wl_iterator_func_t)(void *element, void *data);<br>
<br>
 void wl_map_init(struct wl_map *map);<br>
diff --git a/src/wayland-util.c b/src/wayland-util.c<br>
</div>index 598ab42..10607d8 100644<br>
<div><div class="h5">--- a/src/wayland-util.c<br>
+++ b/src/wayland-util.c<br>
@@ -151,102 +151,64 @@ union map_entry {<br>
        void *data;<br>
 };<br>
<br>
-WL_EXPORT void<br>
-wl_map_init(struct wl_map *map)<br>
-{<br>
-       memset(map, 0, sizeof *map);<br>
-}<br>
-<br>
-WL_EXPORT void<br>
-wl_map_release(struct wl_map *map)<br>
-{<br>
-       wl_array_release(&map->client_entries);<br>
-       wl_array_release(&map->server_entries);<br>
-}<br>
-<br>
-WL_EXPORT uint32_t<br>
-wl_map_insert_new(struct wl_map *map, uint32_t side, void *data)<br>
+static uint32_t<br>
+wl_simple_map_insert_new(struct wl_simple_map *map, void *data)<br>
 {<br>
        union map_entry *start, *entry;<br>
-       struct wl_array *entries;<br>
-       uint32_t base;<br>
-<br>
-       if (side == WL_MAP_CLIENT_SIDE) {<br>
-               entries = &map->client_entries;<br>
-               base = 0;<br>
-       } else {<br>
-               entries = &map->server_entries;<br>
-               base = WL_SERVER_ID_START;<br>
-       }<br>
-<br>
        if (map->free_list) {<br>
-               start = entries->data;<br>
+               start = map->entries.data;<br>
                entry = &start[map->free_list >> 1];<br>
                map->free_list = entry->next;<br>
        } else {<br>
-               entry = wl_array_add(entries, sizeof *entry);<br>
+               entry = wl_array_add(&map->entries, sizeof *entry);<br>
                if (!entry)<br>
                        return 0;<br>
-               start = entries->data;<br>
+               start = map->entries.data;<br>
        }<br>
<br>
        entry->data = data;<br>
<br>
-       return (entry - start) + base;<br>
+       return (entry - start);<br>
 }<br>
<br>
-WL_EXPORT int<br>
-wl_map_insert_at(struct wl_map *map, uint32_t i, void *data)<br>
+static int<br>
+wl_simple_map_insert_at(struct wl_simple_map *map, uint32_t i, void *data)<br>
 {<br>
        union map_entry *start;<br>
        uint32_t count;<br>
-       struct wl_array *entries;<br>
-<br>
-       if (i < WL_SERVER_ID_START) {<br>
-               entries = &map->client_entries;<br>
-       } else {<br>
-               entries = &map->server_entries;<br>
-               i -= WL_SERVER_ID_START;<br>
-       }<br>
<br>
-       count = entries->size / sizeof *start;<br>
+       count = map->entries.size / sizeof *start;<br>
        if (count < i)<br>
                return -1;<br>
<br>
        if (count == i)<br>
-               wl_array_add(entries, sizeof *start);<br>
+               if (!wl_array_add(&map->entries, sizeof *start))<br>
+                       return -1;<br>
<br>
-       start = entries->data;<br>
+       start = map->entries.data;<br>
        start[i].data = data;<br>
<br>
        return 0;<br>
 }<br>
<br>
-WL_EXPORT int<br>
-wl_map_reserve_new(struct wl_map *map, uint32_t i)<br>
+static int<br>
+wl_simple_map_reserve_new(struct wl_simple_map *map, uint32_t i)<br>
 {<br>
        union map_entry *start;<br>
        uint32_t count;<br>
-       struct wl_array *entries;<br>
<br>
-       if (i < WL_SERVER_ID_START) {<br>
-               entries = &map->client_entries;<br>
-       } else {<br>
-               entries = &map->server_entries;<br>
-               i -= WL_SERVER_ID_START;<br>
-       }<br>
-<br>
-       count = entries->size / sizeof *start;<br>
+       count = map->entries.size / sizeof *start;<br>
<br>
        if (count < i)<br>
                return -1;<br>
<br>
        if (count == i) {<br>
-               wl_array_add(entries, sizeof *start);<br>
-               start = entries->data;<br>
+               if (!wl_array_add(&map->entries, sizeof *start))<br>
+                       return -1;<br>
+               start = map->entries.data;<br>
                start[i].data = NULL;<br>
        } else {<br>
-               start = entries->data;<br>
+               start = map->entries.data;<br>
                if (start[i].data != NULL) {<br>
                        return -1;<br>
                }<br>
@@ -255,40 +217,24 @@ wl_map_reserve_new(struct wl_map *map, uint32_t i)<br>
        return 0;<br>
 }<br>
<br>
-WL_EXPORT void<br>
-wl_map_remove(struct wl_map *map, uint32_t i)<br>
+static void<br>
+wl_simple_map_remove(struct wl_simple_map *map, uint32_t i)<br>
 {<br>
        union map_entry *start;<br>
-       struct wl_array *entries;<br>
-<br>
</div></div><div class="im">-       if (i < WL_SERVER_ID_START) {<br>
-               entries = &map->client_entries;<br>
-       } else {<br>
-               entries = &map->server_entries;<br>
-               i -= WL_SERVER_ID_START;<br>
-       }<br>
<br>
-       start = entries->data;<br>
+       start = map->entries.data;<br>
        start[i].next = map->free_list;<br>
        map->free_list = (i << 1) | 1;<br>
 }<br>
<br>
-WL_EXPORT void *<br>
-wl_map_lookup(struct wl_map *map, uint32_t i)<br>
+void *<br>
+wl_simple_map_lookup(struct wl_simple_map *map, uint32_t i)<br>
 {<br>
        union map_entry *start;<br>
        uint32_t count;<br>
-       struct wl_array *entries;<br>
<br>
</div><div class="im">-       if (i < WL_SERVER_ID_START) {<br>
-               entries = &map->client_entries;<br>
-       } else {<br>
-               entries = &map->server_entries;<br>
-               i -= WL_SERVER_ID_START;<br>
-       }<br>
-<br>
-       start = entries->data;<br>
</div><div class="im">-       count = entries->size / sizeof *start;<br>
+       start = map->entries.data;<br>
+       count = map->entries.size / sizeof *start;<br>
<br>
        if (i < count && !(start[i].next & 1))<br>
                return start[i].data;<br>
</div>@@ -296,6 +242,73 @@ wl_map_lookup(struct wl_map *map, uint32_t i)<br>
<div class="im">        return NULL;<br>
 }<br>
<br>
+WL_EXPORT void<br>
+wl_map_init(struct wl_map *map)<br>
+{<br>
+       memset(map, 0, sizeof *map);<br>
+}<br>
+<br>
+WL_EXPORT void<br>
+wl_map_release(struct wl_map *map)<br>
+{<br>
+       wl_array_release(&map->client_map.entries);<br>
+       wl_array_release(&map->server_map.entries);<br>
+}<br>
+<br>
+WL_EXPORT uint32_t<br>
+wl_map_insert_new(struct wl_map *map, uint32_t side, void *data)<br>
+{<br>
</div>+       uint32_t id;<br>
<div class="im">+       if (side == WL_MAP_CLIENT_SIDE) {<br>
+               return wl_simple_map_insert_new(&map->client_map, data);<br>
+       } else {<br>
</div>+               id = wl_simple_map_insert_new(&map->server_map, data);<br>
+               if (id == 0)<br>
+                       return 0;<br>
+               else<br>
+                       return id + WL_SERVER_ID_START;<br>
+       }<br>
<div><div class="h5">+}<br>
+<br>
+WL_EXPORT int<br>
+wl_map_insert_at(struct wl_map *map, uint32_t i, void *data)<br>
+{<br>
+       if (i < WL_SERVER_ID_START)<br>
+               return wl_simple_map_insert_at(&map->client_map, i, data);<br>
+       else<br>
+               return wl_simple_map_insert_at(&map->server_map,<br>
+                                              i - WL_SERVER_ID_START, data);<br>
+}<br>
+<br>
+WL_EXPORT int<br>
+wl_map_reserve_new(struct wl_map *map, uint32_t i)<br>
+{<br>
+       if (i < WL_SERVER_ID_START)<br>
+               return wl_simple_map_reserve_new(&map->client_map, i);<br>
+       else<br>
+               return wl_simple_map_reserve_new(&map->server_map,<br>
+                                                i - WL_SERVER_ID_START);<br>
+}<br>
+<br>
+WL_EXPORT void<br>
+wl_map_remove(struct wl_map *map, uint32_t i)<br>
+{<br>
+       if (i < WL_SERVER_ID_START)<br>
+               wl_simple_map_remove(&map->client_map, i);<br>
+       else<br>
+               wl_simple_map_remove(&map->server_map, i - WL_SERVER_ID_START);<br>
+}<br>
+<br>
+WL_EXPORT void *<br>
+wl_map_lookup(struct wl_map *map, uint32_t i)<br>
+{<br>
+       if (i < WL_SERVER_ID_START)<br>
+               return wl_simple_map_lookup(&map->client_map, i);<br>
+       else<br>
+               return wl_simple_map_lookup(&map->server_map,<br>
+                                           i - WL_SERVER_ID_START);<br>
+}<br>
+<br>
 static void<br>
 for_each_helper(struct wl_array *entries, wl_iterator_func_t func, void *data)<br>
 {<br>
</div></div>@@ -312,8 +325,8 @@ for_each_helper(struct wl_array *entries, wl_iterator_func_t func, void *data)<br>
<div class="HOEnZb"><div class="h5"> WL_EXPORT void<br>
 wl_map_for_each(struct wl_map *map, wl_iterator_func_t func, void *data)<br>
 {<br>
-       for_each_helper(&map->client_entries, func, data);<br>
-       for_each_helper(&map->server_entries, func, data);<br>
+       for_each_helper(&map->client_map.entries, func, data);<br>
+       for_each_helper(&map->server_map.entries, func, data);<br>
 }<br>
<br>
 static void<br>
--<br>
1.8.1.4<br>
<br>
</div></div></blockquote></div><br></div>