From d6a4ca14340d6618b782ec04e86281f9a1c2653e Mon Sep 17 00:00:00 2001 From: Přemysl Janouch Date: Tue, 14 Jul 2015 22:25:30 +0200 Subject: Bump liberty, fix map iterators --- common.c | 11 ----------- degesch.c | 12 +++++------- kike.c | 25 ++++++++++++------------- liberty | 2 +- 4 files changed, 18 insertions(+), 32 deletions(-) diff --git a/common.c b/common.c index afca7e1..423bb7e 100644 --- a/common.c +++ b/common.c @@ -70,17 +70,6 @@ str_vector_find (const struct str_vector *v, const char *s) return -1; } -static void * -str_map_steal (struct str_map *self, const char *key) -{ - void *value = str_map_find (self, key); - void (*free_backup) (void *) = self->free; - self->free = NULL; - str_map_set (self, key, NULL); - self->free = free_backup; - return value; -} - // --- Logging ----------------------------------------------------------------- static void diff --git a/degesch.c b/degesch.c index c4a7a43..78a5f66 100644 --- a/degesch.c +++ b/degesch.c @@ -6567,14 +6567,12 @@ server_remove (struct app_context *ctx, struct server *s) if (s->buffer) buffer_remove_safe (ctx, s->buffer); - struct str_map_iter iter; - str_map_iter_init (&iter, &s->irc_buffer_map); - struct buffer *buffer, *next = str_map_iter_next (&iter); - for (buffer = next; buffer; buffer = next) - { - next = str_map_iter_next (&iter); + struct str_map_unset_iter iter; + str_map_unset_iter_init (&iter, &s->irc_buffer_map); + struct buffer *buffer; + while ((buffer = str_map_unset_iter_next (&iter))) buffer_remove_safe (ctx, buffer); - } + str_map_unset_iter_free (&iter); hard_assert (!s->buffer); hard_assert (!s->irc_buffer_map.len); diff --git a/kike.c b/kike.c index fafa38d..f24dbf2 100644 --- a/kike.c +++ b/kike.c @@ -870,18 +870,18 @@ client_unregister (struct client *c, const char *reason) irc_send_to_roommates (c, message); free (message); - struct str_map_iter iter; - str_map_iter_init (&iter, &c->ctx->channels); - struct channel *chan, *next = str_map_iter_next (&iter); - for (chan = next; chan; chan = next) + struct str_map_unset_iter iter; + str_map_unset_iter_init (&iter, &c->ctx->channels); + struct channel *chan; + while ((chan = str_map_unset_iter_next (&iter))) { - next = str_map_iter_next (&iter); struct channel_user *user; if (!(user = channel_get_user (chan, c))) continue; channel_remove_user (chan, user); irc_channel_destroy_if_empty (c->ctx, chan); } + str_map_unset_iter_free (&iter); client_add_to_whowas (c); @@ -2590,16 +2590,15 @@ irc_try_part (struct client *c, const char *channel_name, const char *reason) static void irc_part_all_channels (struct client *c) { - struct str_map_iter iter; - str_map_iter_init (&iter, &c->ctx->channels); - struct channel *chan, *next = str_map_iter_next (&iter); - for (chan = next; chan; chan = next) - { - // We have to be careful here, the channel might get destroyed - next = str_map_iter_next (&iter); + // We have to be careful here, the channel might get destroyed + struct str_map_unset_iter iter; + str_map_unset_iter_init (&iter, &c->ctx->channels); + + struct channel *chan; + while ((chan = str_map_unset_iter_next (&iter))) if (channel_get_user (chan, c)) irc_try_part (c, chan->name, NULL); - } + str_map_unset_iter_free (&iter); } static void diff --git a/liberty b/liberty index 7fa873f..0058c1f 160000 --- a/liberty +++ b/liberty @@ -1 +1 @@ -Subproject commit 7fa873fb964156e71a00174f50e3f4bc343bcc04 +Subproject commit 0058c1f457a954fbdfc63f458fa00c3c5a700f69 -- cgit v1.2.3-70-g09d2