Skip to content

Commit

Permalink
global: Use array_first instead of array_idx
Browse files Browse the repository at this point in the history
@@
expression A;
@@

-array_idx(A, 0)
+array_first(A)

@@
expression A;
@@

-array_idx_modifiable(A, 0)
+array_first_modifiable(A)
  • Loading branch information
cmouse authored and sirainen committed Jan 10, 2019
1 parent bc8aaf3 commit 27b2b51
Show file tree
Hide file tree
Showing 60 changed files with 85 additions and 85 deletions.
2 changes: 1 addition & 1 deletion src/auth/auth-request-handler.c
Expand Up @@ -859,7 +859,7 @@ void auth_request_handler_flush_failures(bool flush_all)
return;
}

auth_requests = array_idx_modifiable(&auth_failures_arr, 0);
auth_requests = array_first_modifiable(&auth_failures_arr);
/* count the number of requests that we need to flush */
for (i = 0; i < count; i++) {
auth_request = auth_requests[aqueue_idx(auth_failures, i)];
Expand Down
2 changes: 1 addition & 1 deletion src/auth/auth-worker-server.c
Expand Up @@ -500,7 +500,7 @@ void auth_worker_server_deinit(void)
struct auth_worker_connection **connp, *conn;

while (array_count(&connections) > 0) {
connp = array_idx_modifiable(&connections, 0);
connp = array_first_modifiable(&connections);
conn = *connp;
auth_worker_destroy(&conn, "Shutting down", FALSE);
}
Expand Down
4 changes: 2 additions & 2 deletions src/auth/db-ldap.c
Expand Up @@ -544,7 +544,7 @@ db_ldap_find_request(struct ldap_connection *conn, int msgid,
if (count == 0)
return NULL;

requests = array_idx(&conn->request_array, 0);
requests = array_first(&conn->request_array);
for (i = 0; i < count; i++) {
request = requests[aqueue_idx(conn->request_queue, i)];
if (request->msgid == msgid) {
Expand Down Expand Up @@ -1326,7 +1326,7 @@ static void db_ldap_conn_close(struct ldap_connection *conn)
timeout_remove(&conn->to);

if (conn->pending_count != 0) {
requests = array_idx(&conn->request_array, 0);
requests = array_first(&conn->request_array);
for (i = 0; i < conn->pending_count; i++) {
request = requests[aqueue_idx(conn->request_queue, i)];

Expand Down
2 changes: 1 addition & 1 deletion src/config/config-parser.c
Expand Up @@ -738,7 +738,7 @@ static int config_parse_finish(struct config_parser_context *ctx, const char **e

new_filter = config_filter_init(ctx->pool);
array_append_zero(&ctx->all_parsers);
config_filter_add_all(new_filter, array_idx(&ctx->all_parsers, 0));
config_filter_add_all(new_filter, array_first(&ctx->all_parsers));

if (ret < 0)
;
Expand Down
4 changes: 2 additions & 2 deletions src/dict/dict-commands.c
Expand Up @@ -80,7 +80,7 @@ static void dict_connection_cmds_flush(struct dict_connection *conn)

dict_connection_ref(conn);
while (array_count(&conn->cmds) > 0) {
first_cmdp = array_idx(&conn->cmds, 0);
first_cmdp = array_first(&conn->cmds);
cmd = *first_cmdp;

i_assert(cmd->async_reply_id == 0);
Expand Down Expand Up @@ -659,7 +659,7 @@ static void dict_connection_cmd_output_more(struct dict_connection_cmd *cmd)
struct dict_connection_cmd *const *first_cmdp;

if (cmd->conn->minor_version < DICT_CLIENT_PROTOCOL_TIMINGS_MIN_VERSION) {
first_cmdp = array_idx(&cmd->conn->cmds, 0);
first_cmdp = array_first(&cmd->conn->cmds);
if (*first_cmdp != cmd)
return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/director/director.c
Expand Up @@ -1465,7 +1465,7 @@ void director_deinit(struct director **_dir)
*_dir = NULL;

while (array_count(&dir->connections) > 0) {
connp = array_idx(&dir->connections, 0);
connp = array_first(&dir->connections);
conn = *connp;
director_connection_deinit(&conn, "Shutting down");
}
Expand All @@ -1481,7 +1481,7 @@ void director_deinit(struct director **_dir)
timeout_remove(&dir->to_remove_dirs);
timeout_remove(&dir->to_callback);
while (array_count(&dir->dir_hosts) > 0) {
hostp = array_idx(&dir->dir_hosts, 0);
hostp = array_first(&dir->dir_hosts);
host = *hostp;
director_host_free(&host);
}
Expand Down
2 changes: 1 addition & 1 deletion src/doveadm/doveadm-dsync.c
Expand Up @@ -614,7 +614,7 @@ cmd_dsync_run(struct doveadm_mail_cmd_context *_ctx, struct mail_user *user)
t_strsplit_spaces(doveadm_settings->dsync_hashed_headers, " ,");
if (array_count(&ctx->exclude_mailboxes) > 0) {
/* array is NULL-terminated in init() */
set.exclude_mailboxes = array_idx(&ctx->exclude_mailboxes, 0);
set.exclude_mailboxes = array_first(&ctx->exclude_mailboxes);
}
doveadm_user_init_dsync(user);

Expand Down
2 changes: 1 addition & 1 deletion src/doveadm/doveadm-dump-index.c
Expand Up @@ -376,7 +376,7 @@ static void dump_keywords(struct mail_index *index)
if (count == 0)
return;

keywords = array_idx(&index->keywords, 0);
keywords = array_first(&index->keywords);
for (i = 0; i < count; i++)
printf("%3u = %s\n", i, keywords[kw_indexes[i]]);
}
Expand Down
2 changes: 1 addition & 1 deletion src/doveadm/doveadm-kick.c
Expand Up @@ -71,7 +71,7 @@ kick_pid_want_kicked(struct kick_context *ctx, const struct kick_pid *k_pid,
const struct kick_user *user;

if (array_count(&k_pid->users) == 1) {
user = array_idx(&k_pid->users, 0);
user = array_first(&k_pid->users);
if (!user->kick_me)
return FALSE;
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/doveadm/doveadm-mail-server.c
Expand Up @@ -119,7 +119,7 @@ static void doveadm_cmd_callback(int exit_code, const char *error,

if (array_count(&server->queue) > 0) {
struct server_connection *conn;
char *const *usernamep = array_idx(&server->queue, 0);
char *const *usernamep = array_first(&server->queue);
char *username = *usernamep;

conn = doveadm_server_find_unused_conn(server);
Expand Down Expand Up @@ -337,7 +337,7 @@ static void doveadm_servers_destroy_all_connections(void)
while (array_count(&server->connections) > 0) {
struct server_connection *const *connp, *conn;

connp = array_idx(&server->connections, 0);
connp = array_first(&server->connections);
conn = *connp;
server_connection_destroy(&conn);
}
Expand Down
2 changes: 1 addition & 1 deletion src/doveadm/doveadm-mailbox-list-iter.c
Expand Up @@ -108,7 +108,7 @@ doveadm_mailbox_list_iter_init_nsmask(struct doveadm_mail_cmd_context *ctx,
iter->only_selectable = TRUE;
iter->iter_flags = iter_flags;
iter->iter = mailbox_list_iter_init_namespaces(user->namespaces,
array_idx(&iter->patterns, 0),
array_first(&iter->patterns),
ns_mask, iter_flags);
return iter;
}
Expand Down
2 changes: 1 addition & 1 deletion src/doveadm/doveadm-print-formatted.c
Expand Up @@ -64,7 +64,7 @@ static void doveadm_print_formatted_print(const char *value)
entry->value = value;

if (ctx.idx >= array_count(&ctx.headers)) {
if (var_expand(ctx.buf, ctx.format, array_idx(&ctx.headers,0), &error) <= 0) {
if (var_expand(ctx.buf, ctx.format, array_first(&ctx.headers), &error) <= 0) {
i_error("Failed to expand print format '%s': %s",
ctx.format, error);
}
Expand Down
2 changes: 1 addition & 1 deletion src/doveadm/doveadm-who.c
Expand Up @@ -28,7 +28,7 @@ static void who_user_ip(const struct who_user *user, struct ip_addr *ip_r)
if (array_count(&user->ips) == 0)
i_zero(ip_r);
else {
const struct ip_addr *ip = array_idx(&user->ips, 0);
const struct ip_addr *ip = array_first(&user->ips);
*ip_r = *ip;
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/doveadm/dsync/dsync-ibc-pipe.c
Expand Up @@ -111,7 +111,7 @@ dsync_ibc_pipe_pop_item(struct dsync_ibc_pipe *pipe, enum item_type type)
if (array_count(&pipe->item_queue) == 0)
return NULL;

item = array_idx_modifiable(&pipe->item_queue, 0);
item = array_first_modifiable(&pipe->item_queue);
i_assert(item->type == type);
pipe->pop_item = *item;
array_delete(&pipe->item_queue, 0, 1);
Expand All @@ -129,7 +129,7 @@ static bool dsync_ibc_pipe_try_pop_eol(struct dsync_ibc_pipe *pipe)
if (array_count(&pipe->item_queue) == 0)
return FALSE;

item = array_idx(&pipe->item_queue, 0);
item = array_first(&pipe->item_queue);
if (item->type != ITEM_END_OF_LIST)
return FALSE;

Expand Down Expand Up @@ -526,7 +526,7 @@ static void pipe_close_mail_streams(struct dsync_ibc_pipe *pipe)
struct item *item;

if (array_count(&pipe->item_queue) > 0) {
item = array_idx_modifiable(&pipe->item_queue, 0);
item = array_first_modifiable(&pipe->item_queue);
if (item->type == ITEM_MAIL &&
item->u.mail.input != NULL)
i_stream_unref(&item->u.mail.input);
Expand Down
4 changes: 2 additions & 2 deletions src/doveadm/dsync/dsync-mailbox-export.c
Expand Up @@ -745,7 +745,7 @@ dsync_mailbox_export_body_search_init(struct dsync_mailbox_exporter *exporter)
array_count(&instances->seqs) == 0)
continue;

uids = array_idx(&instances->seqs, 0);
uids = array_first(&instances->seqs);
seq = uids[0].seq1;
if (!instances->searched) {
instances->searched = TRUE;
Expand All @@ -762,7 +762,7 @@ dsync_mailbox_export_body_search_init(struct dsync_mailbox_exporter *exporter)
&const_guid, 1);
continue;
}
uids = array_idx(&instances->seqs, 0);
uids = array_first(&instances->seqs);
seq = uids[0].seq1;
seq_range_array_add(&sarg->value.seqset, seq);
}
Expand Down
4 changes: 2 additions & 2 deletions src/imap/cmd-thread.c
Expand Up @@ -116,8 +116,8 @@ static int orderedsubject_thread_cmp(const struct orderedsubject_thread *t1,
if (t1->timestamp > t2->timestamp)
return 1;

m1 = array_idx(&t1->msgs, 0);
m2 = array_idx(&t2->msgs, 0);
m1 = array_first(&t1->msgs);
m2 = array_first(&t2->msgs);
if (*m1 < *m2)
return -1;
if (*m1 > *m2)
Expand Down
2 changes: 1 addition & 1 deletion src/imap/imap-commands-util.c
Expand Up @@ -305,7 +305,7 @@ void client_send_mailbox_flags(struct client *client, bool selecting)
&status);

keywords = count == 0 ? NULL :
array_idx(client->keywords.names, 0);
array_first(client->keywords.names);
str = t_str_new(128);
str_append(str, "* FLAGS (");
imap_write_flags(str, status.flags, keywords);
Expand Down
4 changes: 2 additions & 2 deletions src/imap/imap-fetch.c
Expand Up @@ -41,7 +41,7 @@ void imap_fetch_handler_unregister(const char *name)
{
const struct imap_fetch_handler *handler, *first_handler;

first_handler = array_idx(&fetch_handlers, 0);
first_handler = array_first(&fetch_handlers);
handler = imap_fetch_handler_lookup(name);
i_assert(handler != NULL);
array_delete(&fetch_handlers, handler - first_handler, 1);
Expand Down Expand Up @@ -380,7 +380,7 @@ void imap_fetch_begin(struct imap_fetch_context *ctx, struct mailbox *box,
MAIL_FETCH_STREAM_BODY)) == 0)) {
array_append_zero(&ctx->all_headers);

headers = array_idx(&ctx->all_headers, 0);
headers = array_first(&ctx->all_headers);
wanted_headers = mailbox_header_lookup_init(box, headers);
array_delete(&ctx->all_headers,
array_count(&ctx->all_headers)-1, 1);
Expand Down
2 changes: 1 addition & 1 deletion src/ipc/ipc-connection.c
Expand Up @@ -205,7 +205,7 @@ void ipc_connection_destroy(struct ipc_connection **_conn,
DLLIST_REMOVE(&conn->group->connections, conn);

while (array_count(&conn->cmds) > 0) {
cmdp = array_idx(&conn->cmds, 0);
cmdp = array_first(&conn->cmds);
cmd = *cmdp;

ipc_connection_cmd_free(&cmd, error);
Expand Down
2 changes: 1 addition & 1 deletion src/ipc/ipc-group.c
Expand Up @@ -148,7 +148,7 @@ void ipc_groups_deinit(void)
struct ipc_group *const *groupp, *group;

while (array_count(&ipc_groups) > 0) {
groupp = array_idx(&ipc_groups, 0);
groupp = array_first(&ipc_groups);
group = *groupp;

while ((*groupp)->connections != NULL) {
Expand Down
4 changes: 2 additions & 2 deletions src/lib-dict/dict-redis.c
Expand Up @@ -246,7 +246,7 @@ redis_conn_input_more(struct redis_connection *conn, const char **error_r)
if (line[0] != '*' || str_to_uint(line+1, &num_replies) < 0)
break;

reply = array_idx_modifiable(&dict->replies, 0);
reply = array_first_modifiable(&dict->replies);
i_assert(reply->reply_count > 0);
if (reply->reply_count != num_replies) {
*error_r = t_strdup_printf(
Expand All @@ -259,7 +259,7 @@ redis_conn_input_more(struct redis_connection *conn, const char **error_r)
if (*line != '+' && *line != ':')
break;
/* success, just ignore the actual reply */
reply = array_idx_modifiable(&dict->replies, 0);
reply = array_first_modifiable(&dict->replies);
i_assert(reply->reply_count > 0);
if (--reply->reply_count == 0) {
const struct dict_commit_result result = {
Expand Down
4 changes: 2 additions & 2 deletions src/lib-fts/fts-filter-normalizer-icu.c
Expand Up @@ -90,15 +90,15 @@ fts_filter_normalizer_icu_filter(struct fts_filter *filter, const char **token,
array_append_zero(&np->utf16_token);
array_delete(&np->utf16_token, array_count(&np->utf16_token)-1, 1);
array_clear(&np->trans_token);
if (fts_icu_translate(&np->trans_token, array_idx(&np->utf16_token, 0),
if (fts_icu_translate(&np->trans_token, array_first(&np->utf16_token),
array_count(&np->utf16_token),
np->transliterator, error_r) < 0)
return -1;

if (array_count(&np->trans_token) == 0)
return 0;

fts_icu_utf16_to_utf8(np->utf8_token, array_idx(&np->trans_token, 0),
fts_icu_utf16_to_utf8(np->utf8_token, array_first(&np->trans_token),
array_count(&np->trans_token));
fts_filter_truncate_token(np->utf8_token, np->filter.max_length);
*token = str_c(np->utf8_token);
Expand Down
4 changes: 2 additions & 2 deletions src/lib-fts/fts-language.c
Expand Up @@ -196,7 +196,7 @@ fts_language_list_get_first(struct fts_language_list *list)
{
const struct fts_language *const *langp;

langp = array_idx(&list->languages, 0);
langp = array_first(&list->languages);
return *langp;
}

Expand Down Expand Up @@ -307,7 +307,7 @@ fts_language_detect(struct fts_language_list *list,
/* if there's only a single wanted language, return it always. */
if (array_count(&list->languages) == 1) {
const struct fts_language *const *langp =
array_idx(&list->languages, 0);
array_first(&list->languages);
*lang_r = *langp;
return FTS_LANGUAGE_RESULT_OK;
}
Expand Down
4 changes: 2 additions & 2 deletions src/lib-http/http-client-connection.c
Expand Up @@ -235,7 +235,7 @@ http_client_connection_get_timing_info(struct http_client_connection *conn)
string_t *str = t_str_new(64);

if (array_count(&conn->request_wait_list) > 0) {
requestp = array_idx(&conn->request_wait_list, 0);
requestp = array_first(&conn->request_wait_list);

str_append(str, "Request ");
http_client_request_append_stats_text(*requestp, str);
Expand Down Expand Up @@ -582,7 +582,7 @@ void http_client_connection_start_request_timeout(
i_assert(array_is_created(&conn->request_wait_list));
if (array_count(&conn->request_wait_list) > 0) {
struct http_client_request *const *requestp;
requestp = array_idx(&conn->request_wait_list, 0);
requestp = array_first(&conn->request_wait_list);
timeout_msecs = (*requestp)->attempt_timeout_msecs;
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib-http/http-message-parser.c
Expand Up @@ -451,7 +451,7 @@ int http_message_parse_body(struct http_message_parser *parser, bool request)
&& array_is_created(&coding->parameters)
&& array_count(&coding->parameters) > 0) {
const struct http_transfer_param *param =
array_idx(&coding->parameters, 0);
array_first(&coding->parameters);

parser->error_code = HTTP_MESSAGE_PARSE_ERROR_BAD_MESSAGE;
parser->error = t_strdup_printf(
Expand Down
2 changes: 1 addition & 1 deletion src/lib-imap-client/imapc-client.c
Expand Up @@ -275,7 +275,7 @@ imapc_client_find_connection(struct imapc_client *client)
/* FIXME: stupid algorithm */
if (array_count(&client->conns) == 0)
return imapc_client_add_connection(client)->conn;
connp = array_idx(&client->conns, 0);
connp = array_first(&client->conns);
return (*connp)->conn;
}

Expand Down
4 changes: 2 additions & 2 deletions src/lib-imap-client/imapc-connection.c
Expand Up @@ -2031,7 +2031,7 @@ static void imapc_command_send_finished(struct imapc_connection *conn,
cmd->sent = TRUE;

/* everything sent. move command to wait list. */
cmdp = array_idx(&conn->cmd_send_queue, 0);
cmdp = array_first(&conn->cmd_send_queue);
i_assert(*cmdp == cmd);
array_delete(&conn->cmd_send_queue, 0, 1);
array_append(&conn->cmd_wait_list, &cmd, 1);
Expand All @@ -2048,7 +2048,7 @@ imapc_command_get_sending_stream(struct imapc_command *cmd)
if (!array_is_created(&cmd->streams) || array_count(&cmd->streams) == 0)
return NULL;

stream = array_idx_modifiable(&cmd->streams, 0);
stream = array_first_modifiable(&cmd->streams);
if (stream->pos != cmd->send_pos)
return NULL;
return stream;
Expand Down
2 changes: 1 addition & 1 deletion src/lib-imap-client/imapc-msgmap.c
Expand Up @@ -59,7 +59,7 @@ bool imapc_msgmap_uid_to_rseq(struct imapc_msgmap *msgmap,
return FALSE;
}

first = array_idx(&msgmap->uids, 0);
first = array_first(&msgmap->uids);
*rseq_r = (p - first) + 1;
return TRUE;
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib-imap/imap-parser.c
Expand Up @@ -536,7 +536,7 @@ static bool imap_parser_is_next_resp_text(struct imap_parser *parser)
array_count(parser->cur_list) != 1)
return FALSE;

arg = array_idx(&parser->root_list, 0);
arg = array_first(&parser->root_list);
if (arg->type != IMAP_ARG_ATOM)
return FALSE;

Expand Down
2 changes: 1 addition & 1 deletion src/lib-index/mail-index-sync-ext.c
Expand Up @@ -323,7 +323,7 @@ sync_ext_resize(const struct mail_transaction_ext_intro *u,
ssize_t diff = (ssize_t)new_padded_hdr_size -
(ssize_t)old_padded_hdr_size;

ext = array_idx_modifiable(&map->extensions, 0);
ext = array_first_modifiable(&map->extensions);
for (i = ext_map_idx + 1; i < count; i++) {
ext[i].ext_offset += diff;
ext[i].hdr_offset += diff;
Expand Down
2 changes: 1 addition & 1 deletion src/lib-index/mail-index-transaction-update.c
Expand Up @@ -124,7 +124,7 @@ void mail_index_update_day_headers(struct mail_index_transaction *t,
int i, days;

hdr = *mail_index_get_header(t->view);
rec = array_idx(&t->appends, 0);
rec = array_first(&t->appends);

stamp = time_to_local_day_start(day_stamp);
if ((time_t)hdr.day_stamp >= stamp)
Expand Down

0 comments on commit 27b2b51

Please sign in to comment.