From: Timo Sirainen Date: Wed, 10 Feb 2021 18:06:07 +0000 (+0200) Subject: lib: Use array_foreach_elem() where possible X-Git-Tag: 2.3.16~204 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6934e3eff8a5fdfb9410ff96a93dfad8cf05482f;p=thirdparty%2Fdovecot%2Fcore.git lib: Use array_foreach_elem() where possible --- diff --git a/src/lib/env-util.c b/src/lib/env-util.c index 6ac09d35bd..e19cc7cd27 100644 --- a/src/lib/env-util.c +++ b/src/lib/env-util.c @@ -76,7 +76,7 @@ void env_clean(void) static void env_clean_except_real(const char *const preserve_envs[]) { ARRAY_TYPE(const_string) copy; - const char *value, *const *envp; + const char *value, *env; unsigned int i; t_array_init(©, 16); @@ -95,8 +95,8 @@ static void env_clean_except_real(const char *const preserve_envs[]) we t_strconcat() them above. */ env_clean(); - array_foreach(©, envp) - env_put(*envp); + array_foreach_elem(©, env) + env_put(env); } void env_clean_except(const char *const preserve_envs[]) diff --git a/src/lib/event-filter.c b/src/lib/event-filter.c index 49a25daa65..707c6b08f1 100644 --- a/src/lib/event-filter.c +++ b/src/lib/event-filter.c @@ -521,11 +521,11 @@ static bool event_has_category_nonrecursive(struct event *event, struct event_category *wanted_category) { - struct event_category *const *catp; + struct event_category *cat; if (array_is_created(&event->categories)) { - array_foreach(&event->categories, catp) { - if (event_category_match(*catp, wanted_category)) + array_foreach_elem(&event->categories, cat) { + if (event_category_match(cat, wanted_category)) return TRUE; } } diff --git a/src/lib/ioloop.c b/src/lib/ioloop.c index 6f10d11f27..39ef3a3017 100644 --- a/src/lib/ioloop.c +++ b/src/lib/ioloop.c @@ -562,15 +562,14 @@ io_loop_default_time_moved(const struct timeval *old_time, static void io_loop_timeouts_start_new(struct ioloop *ioloop) { - struct timeout *const *to_idx; + struct timeout *timeout; if (array_count(&ioloop->timeouts_new) == 0) return; io_loop_time_refresh(); - array_foreach(&ioloop->timeouts_new, to_idx) { - struct timeout *timeout= *to_idx; + array_foreach_elem(&ioloop->timeouts_new, timeout) { i_assert(timeout->next_run.tv_sec == 0 && timeout->next_run.tv_usec == 0); i_assert(!timeout->one_shot); @@ -833,7 +832,7 @@ struct ioloop *io_loop_create(void) void io_loop_destroy(struct ioloop **_ioloop) { struct ioloop *ioloop = *_ioloop; - struct timeout *const *to_idx; + struct timeout *to; struct priorityq_item *item; bool leaks = FALSE; @@ -842,9 +841,9 @@ void io_loop_destroy(struct ioloop **_ioloop) /* ->prev won't work unless loops are destroyed in create order */ i_assert(ioloop == current_ioloop); if (array_is_created(&io_destroy_callbacks)) { - io_destroy_callback_t *const *callbackp; - array_foreach(&io_destroy_callbacks, callbackp) - (*callbackp)(current_ioloop); + io_destroy_callback_t *callback; + array_foreach_elem(&io_destroy_callbacks, callback) + callback(current_ioloop); } io_loop_set_current(current_ioloop->prev); @@ -870,8 +869,7 @@ void io_loop_destroy(struct ioloop **_ioloop) } i_assert(ioloop->io_pending_count == 0); - array_foreach(&ioloop->timeouts_new, to_idx) { - struct timeout *to = *to_idx; + array_foreach_elem(&ioloop->timeouts_new, to) { const char *error = t_strdup_printf( "Timeout leak: %p (%s:%u)", (void *)to->callback, to->source_filename, @@ -948,7 +946,7 @@ static void io_destroy_callbacks_free(void) void io_loop_set_current(struct ioloop *ioloop) { - io_switch_callback_t *const *callbackp; + io_switch_callback_t *callback; struct ioloop *prev_ioloop = current_ioloop; if (ioloop == current_ioloop) @@ -956,8 +954,8 @@ void io_loop_set_current(struct ioloop *ioloop) current_ioloop = ioloop; if (array_is_created(&io_switch_callbacks)) { - array_foreach(&io_switch_callbacks, callbackp) - (*callbackp)(prev_ioloop); + array_foreach_elem(&io_switch_callbacks, callback) + callback(prev_ioloop); } } diff --git a/src/lib/istream-multiplex.c b/src/lib/istream-multiplex.c index 4cacbbebb2..c70d0cc57b 100644 --- a/src/lib/istream-multiplex.c +++ b/src/lib/istream-multiplex.c @@ -35,34 +35,34 @@ static ssize_t i_stream_multiplex_ichannel_read(struct istream_private *stream); static struct multiplex_ichannel * get_channel(struct multiplex_istream *mstream, uint8_t cid) { - struct multiplex_ichannel **channelp; + struct multiplex_ichannel *channel; i_assert(mstream != NULL); - array_foreach_modifiable(&mstream->channels, channelp) { - if (*channelp != NULL && (*channelp)->cid == cid) - return *channelp; + array_foreach_elem(&mstream->channels, channel) { + if (channel != NULL && channel->cid == cid) + return channel; } return NULL; } static void propagate_error(struct multiplex_istream *mstream, int stream_errno) { - struct multiplex_ichannel **channelp; - array_foreach_modifiable(&mstream->channels, channelp) - if (*channelp != NULL) - (*channelp)->istream.istream.stream_errno = stream_errno; + struct multiplex_ichannel *channel; + array_foreach_elem(&mstream->channels, channel) + if (channel != NULL) + channel->istream.istream.stream_errno = stream_errno; } static void propagate_eof(struct multiplex_istream *mstream) { - struct multiplex_ichannel **channelp; - array_foreach_modifiable(&mstream->channels, channelp) { - if (*channelp == NULL) + struct multiplex_ichannel *channel; + array_foreach_elem(&mstream->channels, channel) { + if (channel == NULL) continue; - (*channelp)->istream.istream.eof = TRUE; + channel->istream.istream.eof = TRUE; if (mstream->remain > 0) { - (*channelp)->istream.istream.stream_errno = EPIPE; - io_stream_set_error(&(*channelp)->istream.iostream, + channel->istream.istream.stream_errno = EPIPE; + io_stream_set_error(&channel->istream.iostream, "Unexpected EOF - %u bytes remaining in packet", mstream->remain); } @@ -202,14 +202,14 @@ i_stream_multiplex_ichannel_switch_ioloop_to(struct istream_private *stream, static void i_stream_multiplex_ichannel_close(struct iostream_private *stream, bool close_parent) { - struct multiplex_ichannel *const *channelp; + struct multiplex_ichannel *arr_channel; struct multiplex_ichannel *channel = container_of(stream, struct multiplex_ichannel, istream.iostream); channel->closed = TRUE; if (close_parent) { - array_foreach(&channel->mstream->channels, channelp) - if (*channelp != NULL && !(*channelp)->closed) + array_foreach_elem(&channel->mstream->channels, arr_channel) + if (arr_channel != NULL && !arr_channel->closed) return; i_stream_close(channel->mstream->parent); } @@ -217,10 +217,10 @@ i_stream_multiplex_ichannel_close(struct iostream_private *stream, bool close_pa static void i_stream_multiplex_try_destroy(struct multiplex_istream *mstream) { - struct multiplex_ichannel **channelp; + struct multiplex_ichannel *channel; /* can't do anything until they are all closed */ - array_foreach_modifiable(&mstream->channels, channelp) - if (*channelp != NULL) + array_foreach_elem(&mstream->channels, channel) + if (channel != NULL) return; i_stream_unref(&mstream->parent); array_free(&mstream->channels); diff --git a/src/lib/lib-event.c b/src/lib/lib-event.c index 4088c066dd..8f71b467a2 100644 --- a/src/lib/lib-event.c +++ b/src/lib/lib-event.c @@ -111,13 +111,13 @@ static bool event_call_callbacks(struct event *event, enum event_callback_type type, struct failure_context *ctx, const char *fmt, va_list args) { - event_callback_t *const *callbackp; + event_callback_t *callback; - array_foreach(&event_handlers, callbackp) { + array_foreach_elem(&event_handlers, callback) { bool ret; T_BEGIN { - ret = (*callbackp)(event, type, ctx, fmt, args); + ret = callback(event, type, ctx, fmt, args); } T_END; if (!ret) { /* event sending was stopped */ @@ -646,11 +646,11 @@ void *event_get_ptr(const struct event *event, const char *key) struct event_category *event_category_find_registered(const char *name) { - struct event_category *const *catp; + struct event_category *cat; - array_foreach(&event_registered_categories_representative, catp) { - if (strcmp((*catp)->name, name) == 0) - return *catp; + array_foreach_elem(&event_registered_categories_representative, cat) { + if (strcmp(cat->name, name) == 0) + return cat; } return NULL; } @@ -658,11 +658,11 @@ struct event_category *event_category_find_registered(const char *name) static struct event_internal_category * event_category_find_internal(const char *name) { - struct event_internal_category *const *internal; + struct event_internal_category *internal; - array_foreach(&event_registered_categories_internal, internal) { - if (strcmp((*internal)->name, name) == 0) - return *internal; + array_foreach_elem(&event_registered_categories_internal, internal) { + if (strcmp(internal->name, name) == 0) + return internal; } return NULL; @@ -688,7 +688,7 @@ static struct event_category * event_category_register(struct event_category *category) { struct event_internal_category *internal = category->internal; - event_category_callback_t *const *callbackp; + event_category_callback_t *callback; bool allocated; if (internal != NULL) @@ -750,8 +750,8 @@ event_category_register(struct event_category *category) return &internal->representative; } - array_foreach(&event_category_callbacks, callbackp) T_BEGIN { - (*callbackp)(&internal->representative); + array_foreach_elem(&event_category_callbacks, callback) T_BEGIN { + callback(&internal->representative); } T_END; return &internal->representative; @@ -762,13 +762,13 @@ event_find_category(const struct event *event, const struct event_category *category) { struct event_internal_category *internal = category->internal; - struct event_category *const *categoryp; + struct event_category *cat; /* make sure we're always looking for a representative */ i_assert(category == &internal->representative); - array_foreach(&event->categories, categoryp) { - if (*categoryp == category) + array_foreach_elem(&event->categories, cat) { + if (cat == category) return TRUE; } return FALSE; @@ -1091,11 +1091,11 @@ void event_export(const struct event *event, string_t *dest) } if (array_is_created(&event->categories)) { - struct event_category *const *catp; - array_foreach(&event->categories, catp) { + struct event_category *cat; + array_foreach_elem(&event->categories, cat) { str_append_c(dest, '\t'); str_append_c(dest, EVENT_CODE_CATEGORY); - str_append_tabescaped(dest, (*catp)->name); + str_append_tabescaped(dest, cat->name); } } @@ -1439,7 +1439,7 @@ void lib_event_init(void) void lib_event_deinit(void) { - struct event_internal_category **internal; + struct event_internal_category *internal; event_unset_global_debug_log_filter(); event_unset_global_debug_send_filter(); @@ -1450,11 +1450,9 @@ void lib_event_deinit(void) event->source_filename, event->source_linenum); } /* categories cannot be unregistered, so just free them here */ - array_foreach_modifiable(&event_registered_categories_internal, internal) { - struct event_internal_category *cur = *internal; - - i_free(cur->name); - i_free(cur); + array_foreach_elem(&event_registered_categories_internal, internal) { + i_free(internal->name); + i_free(internal); } array_free(&event_handlers); array_free(&event_category_callbacks); diff --git a/src/lib/ostream-multiplex.c b/src/lib/ostream-multiplex.c index 822d6150e4..30cdccc166 100644 --- a/src/lib/ostream-multiplex.c +++ b/src/lib/ostream-multiplex.c @@ -39,38 +39,38 @@ struct multiplex_ostream { static struct multiplex_ochannel * get_channel(struct multiplex_ostream *mstream, uint8_t cid) { - struct multiplex_ochannel **channelp; + struct multiplex_ochannel *channel; i_assert(mstream != NULL); - array_foreach_modifiable(&mstream->channels, channelp) { - if (*channelp != NULL && (*channelp)->cid == cid) - return *channelp; + array_foreach_elem(&mstream->channels, channel) { + if (channel != NULL && channel->cid == cid) + return channel; } return NULL; } static void propagate_error(struct multiplex_ostream *mstream, int stream_errno) { - struct multiplex_ochannel **channelp; - array_foreach_modifiable(&mstream->channels, channelp) - if (*channelp != NULL) - (*channelp)->ostream.ostream.stream_errno = stream_errno; + struct multiplex_ochannel *channel; + array_foreach_elem(&mstream->channels, channel) + if (channel != NULL) + channel->ostream.ostream.stream_errno = stream_errno; } static struct multiplex_ochannel *get_next_channel(struct multiplex_ostream *mstream) { - struct multiplex_ochannel *channel = NULL; - struct multiplex_ochannel **channelp; + struct multiplex_ochannel *oldest_channel = NULL; + struct multiplex_ochannel *channel; uint64_t last_counter = mstream->send_counter; - array_foreach_modifiable(&mstream->channels, channelp) { - if (*channelp != NULL && - (*channelp)->last_sent_counter <= last_counter && - (*channelp)->buf->used > 0) { - last_counter = (*channelp)->last_sent_counter; - channel = *channelp; + array_foreach_elem(&mstream->channels, channel) { + if (channel != NULL && + channel->last_sent_counter <= last_counter && + channel->buf->used > 0) { + last_counter = channel->last_sent_counter; + oldest_channel = channel; } } - return channel; + return oldest_channel; } static bool @@ -128,11 +128,11 @@ static int o_stream_multiplex_flush(struct multiplex_ostream *mstream) /* Everything is flushed. See if one of the callbacks' flush callbacks wants to write more data. */ - struct multiplex_ochannel **channelp; + struct multiplex_ochannel *channel; bool unfinished = FALSE; - array_foreach_modifiable(&mstream->channels, channelp) { - if (*channelp != NULL && (*channelp)->ostream.callback != NULL) { - ret = (*channelp)->ostream.callback((*channelp)->ostream.context); + array_foreach_elem(&mstream->channels, channel) { + if (channel != NULL && channel->ostream.callback != NULL) { + ret = channel->ostream.callback(channel->ostream.context); if (ret < 0) return -1; if (ret == 0) @@ -252,14 +252,14 @@ o_stream_multiplex_ochannel_get_buffer_avail_size(const struct ostream_private * static void o_stream_multiplex_ochannel_close(struct iostream_private *stream, bool close_parent) { - struct multiplex_ochannel *const *channelp; + struct multiplex_ochannel *arr_channel; struct multiplex_ochannel *channel = container_of(stream, struct multiplex_ochannel, ostream.iostream); channel->closed = TRUE; if (close_parent) { - array_foreach(&channel->mstream->channels, channelp) - if (*channelp !=NULL && !(*channelp)->closed) + array_foreach_elem(&channel->mstream->channels, arr_channel) + if (arr_channel != NULL && !arr_channel->closed) return; o_stream_close(channel->mstream->parent); } @@ -267,10 +267,10 @@ o_stream_multiplex_ochannel_close(struct iostream_private *stream, bool close_pa static void o_stream_multiplex_try_destroy(struct multiplex_ostream *mstream) { - struct multiplex_ochannel **channelp; + struct multiplex_ochannel *channel; /* can't do anything until they are all closed */ - array_foreach_modifiable(&mstream->channels, channelp) - if (*channelp != NULL) + array_foreach_elem(&mstream->channels, channel) + if (channel != NULL) return; i_assert(mstream->parent->real_stream->callback ==