From: Pietro Cerutti Date: Tue, 7 Feb 2017 12:21:51 +0000 (+0000) Subject: Turn mutt_new_* macros into inline functions X-Git-Tag: neomutt-20170225~41 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=dca6feacfd242f70842d3728945e02dcd802f7e6;p=neomutt Turn mutt_new_* macros into inline functions Closes #372 --- diff --git a/mutt.h b/mutt.h index 9c994045d..92f3aa422 100644 --- a/mutt.h +++ b/mutt.h @@ -656,10 +656,26 @@ typedef struct spam_list_t struct spam_list_t *next; } SPAM_LIST; -#define mutt_new_list() safe_calloc (1, sizeof (LIST)) -#define mutt_new_heap() safe_calloc(1, sizeof(HEAP)) -#define mutt_new_rx_list() safe_calloc (1, sizeof (RX_LIST)) -#define mutt_new_spam_list() safe_calloc (1, sizeof (SPAM_LIST)) +inline LIST *mutt_new_list() +{ + return safe_calloc (1, sizeof (LIST)); +} + +inline HEAP *mutt_new_heap() +{ + return safe_calloc (1, sizeof (HEAP)); +} + +inline RX_LIST *mutt_new_rx_list() +{ + return safe_calloc (1, sizeof (RX_LIST)); +} + +inline SPAM_LIST *mutt_new_spam_list() +{ + return safe_calloc (1, sizeof (SPAM_LIST)); +} + void mutt_free_list (LIST **); void mutt_free_rx_list (RX_LIST **); void mutt_free_spam_list (SPAM_LIST **); @@ -728,6 +744,11 @@ typedef struct envelope unsigned int refs_changed : 1; /* References changed to break thread */ } ENVELOPE; +inline ENVELOPE *mutt_new_envelope() +{ + return safe_calloc (1, sizeof (ENVELOPE)); +} + typedef struct parameter { char *attribute; @@ -735,6 +756,11 @@ typedef struct parameter struct parameter *next; } PARAMETER; +inline PARAMETER *mutt_new_parameter() +{ + return safe_calloc (1, sizeof (PARAMETER)); +} + /* Information that helps in determing the Content-* of an attachment */ typedef struct content { @@ -914,6 +940,11 @@ typedef struct header char *maildir_flags; /* unknown maildir flags */ } HEADER; +inline HEADER *mutt_new_header() +{ + return safe_calloc (1, sizeof (HEADER)); +} + struct mutt_thread { unsigned int fake_thread : 1; @@ -1093,6 +1124,11 @@ typedef struct int tabs; } ENTER_STATE; +inline ENTER_STATE *mutt_new_enter_state() +{ + return safe_calloc (1, sizeof (ENTER_STATE)); +} + /* flags for the STATE struct */ #define MUTT_DISPLAY (1<<0) /* output is displayed to the user */ #define MUTT_VERIFY (1<<1) /* perform signature verification */ diff --git a/muttlib.c b/muttlib.c index 7260e4546..ce94e7bfe 100644 --- a/muttlib.c +++ b/muttlib.c @@ -53,6 +53,18 @@ #include #include +/* + * External definitions for inline functions in mutt.h + */ +extern LIST *mutt_new_list(); +extern HEAP *mutt_new_heap(); +extern RX_LIST *mutt_new_rx_list(); +extern SPAM_LIST *mutt_new_spam_list(); +extern PARAMETER *mutt_new_parameter(); +extern HEADER *mutt_new_header(); +extern ENVELOPE *mutt_new_envelope(); +extern ENTER_STATE *mutt_new_enter_state(); + static const char *xdg_env_vars[] = { [kXDGConfigHome] = "XDG_CONFIG_HOME", @@ -67,7 +79,7 @@ static const char *xdg_defaults[] = BODY *mutt_new_body (void) { - BODY *p = (BODY *) safe_calloc (1, sizeof (BODY)); + BODY *p = safe_calloc (1, sizeof (BODY)); p->disposition = DISPATTACH; p->use_disp = 1; diff --git a/protos.h b/protos.h index fe85d6c1a..4060ccd92 100644 --- a/protos.h +++ b/protos.h @@ -71,12 +71,6 @@ int _mutt_aside_thread (HEADER *, short, short); #define mutt_thread_next_unread(x,y) _mutt_traverse_thread(x,y,MUTT_THREAD_NEXT_UNREAD) int _mutt_traverse_thread (CONTEXT *ctx, HEADER *hdr, int flag); - -#define mutt_new_parameter() safe_calloc (1, sizeof (PARAMETER)) -#define mutt_new_header() safe_calloc (1, sizeof (HEADER)) -#define mutt_new_envelope() safe_calloc (1, sizeof (ENVELOPE)) -#define mutt_new_enter_state() safe_calloc (1, sizeof (ENTER_STATE)) - typedef const char * format_t (char *, size_t, size_t, int, char, const char *, const char *, const char *, const char *, unsigned long, format_flag); void mutt_FormatString (char *, size_t, size_t, int, const char *, format_t *, unsigned long, format_flag);