From 3e6125829d555f93d9b38bce749905833b9eae48 Mon Sep 17 00:00:00 2001 From: Richard Russon Date: Sat, 2 Jun 2018 23:37:17 +0100 Subject: [PATCH] move new functions to reduce header deps Having the `new` functions in the header creates a requirement on the mutt library. --- enter.c | 9 +++++++++ enter_state.h | 7 +------ ncrypt/pgplib.c | 10 ++++++++++ ncrypt/pgplib.h | 7 +------ pattern.c | 19 ++++++++++++++----- pattern.h | 8 ++------ 6 files changed, 37 insertions(+), 23 deletions(-) diff --git a/enter.c b/enter.c index b19dd16e5..eda4a51a0 100644 --- a/enter.c +++ b/enter.c @@ -112,6 +112,15 @@ static void replace_part(struct EnterState *state, size_t from, char *buf) state->lastchar = state->curpos + savelen; } +/** + * mutt_enter_state_new - Create a new EnterState + * @retval ptr New EnterState + */ +struct EnterState *mutt_enter_state_new(void) +{ + return mutt_mem_calloc(1, sizeof(struct EnterState)); +} + /** * mutt_enter_string - Ask the user for a string * @param buf Buffer to store the string diff --git a/enter_state.h b/enter_state.h index 8e4e551b6..30dc710ea 100644 --- a/enter_state.h +++ b/enter_state.h @@ -24,7 +24,6 @@ #define _MUTT_ENTER_STATE_H #include -#include "mutt/mutt.h" /** * struct EnterState - Keep our place when entering a string @@ -40,10 +39,6 @@ struct EnterState }; void mutt_enter_state_free(struct EnterState **esp); - -static inline struct EnterState *mutt_enter_state_new(void) -{ - return mutt_mem_calloc(1, sizeof(struct EnterState)); -} +struct EnterState *mutt_enter_state_new(void); #endif /* _MUTT_ENTER_STATE_H */ diff --git a/ncrypt/pgplib.c b/ncrypt/pgplib.c index 66e118e40..aabdd6fe5 100644 --- a/ncrypt/pgplib.c +++ b/ncrypt/pgplib.c @@ -203,3 +203,13 @@ void pgp_free_key(struct PgpKeyInfo **kpp) *kpp = NULL; } + +/** + * pgp_new_keyinfo - Create a new PgpKeyInfo + * @retval ptr New PgpKeyInfo + */ +struct PgpKeyInfo *pgp_new_keyinfo(void) +{ + return mutt_mem_calloc(1, sizeof(struct PgpKeyInfo)); +} + diff --git a/ncrypt/pgplib.h b/ncrypt/pgplib.h index 90e5c1a32..40c41e2bc 100644 --- a/ncrypt/pgplib.h +++ b/ncrypt/pgplib.h @@ -28,8 +28,6 @@ #include #include -#include "mutt/mutt.h" - /** * struct PgpUid - PGP User ID @@ -72,10 +70,7 @@ void pgp_free_key(struct PgpKeyInfo **kpp); struct PgpKeyInfo * pgp_remove_key(struct PgpKeyInfo * *klist, struct PgpKeyInfo * key); -static inline struct PgpKeyInfo *pgp_new_keyinfo(void) -{ - return mutt_mem_calloc(1, sizeof(struct PgpKeyInfo)); -} +struct PgpKeyInfo *pgp_new_keyinfo(void); #endif /* CRYPT_BACKEND_CLASSIC_PGP */ diff --git a/pattern.c b/pattern.c index 98b647adc..470078463 100644 --- a/pattern.c +++ b/pattern.c @@ -1091,6 +1091,15 @@ void mutt_pattern_free(struct Pattern **pat) } } +/** + * mutt_pattern_new - Create a new Pattern + * @retval ptr New Pattern + */ +struct Pattern *mutt_pattern_new(void) +{ + return mutt_mem_calloc(1, sizeof(struct Pattern)); +} + struct Pattern *mutt_pattern_comp(/* const */ char *s, int flags, struct Buffer *err) { struct Pattern *curlist = NULL; @@ -1139,7 +1148,7 @@ struct Pattern *mutt_pattern_comp(/* const */ char *s, int flags, struct Buffer if (curlist->next) { /* A & B | C == (A & B) | C */ - tmp = new_pattern(); + tmp = mutt_pattern_new(); tmp->op = MUTT_AND; tmp->child = curlist; @@ -1183,7 +1192,7 @@ struct Pattern *mutt_pattern_comp(/* const */ char *s, int flags, struct Buffer mutt_pattern_free(&curlist); return NULL; } - tmp = new_pattern(); + tmp = mutt_pattern_new(); tmp->op = thread_op; if (last) last->next = tmp; @@ -1213,7 +1222,7 @@ struct Pattern *mutt_pattern_comp(/* const */ char *s, int flags, struct Buffer if (implicit && or) { /* A | B & C == (A | B) & C */ - tmp = new_pattern(); + tmp = mutt_pattern_new(); tmp->op = MUTT_OR; tmp->child = curlist; curlist = tmp; @@ -1221,7 +1230,7 @@ struct Pattern *mutt_pattern_comp(/* const */ char *s, int flags, struct Buffer or = false; } - tmp = new_pattern(); + tmp = mutt_pattern_new(); tmp->not = not; tmp->alladdr = alladdr; tmp->isalias = isalias; @@ -1316,7 +1325,7 @@ struct Pattern *mutt_pattern_comp(/* const */ char *s, int flags, struct Buffer } if (curlist->next) { - tmp = new_pattern(); + tmp = mutt_pattern_new(); tmp->op = or ? MUTT_OR : MUTT_AND; tmp->child = curlist; curlist = tmp; diff --git a/pattern.h b/pattern.h index 38cbdb0b3..97d09b6a4 100644 --- a/pattern.h +++ b/pattern.h @@ -26,9 +26,9 @@ #include #include #include -#include "mutt/mutt.h" struct Address; +struct Buffer; struct Header; struct Context; @@ -83,11 +83,7 @@ struct PatternCache int pers_from_one; /**< ~P */ }; -static inline struct Pattern *new_pattern(void) -{ - return mutt_mem_calloc(1, sizeof(struct Pattern)); -} - +struct Pattern *mutt_pattern_new(void); int mutt_pattern_exec(struct Pattern *pat, enum PatternExecFlag flags, struct Context *ctx, struct Header *h, struct PatternCache *cache); struct Pattern *mutt_pattern_comp(/* const */ char *s, int flags, struct Buffer *err); -- 2.40.0