From 93a18dd7a6b92922361383a4e6152380da5f3583 Mon Sep 17 00:00:00 2001 From: Ralph Corderoy Date: Sun, 27 Aug 2017 14:08:22 +0100 Subject: [PATCH] Add gcc's pure function attribute. Mark quite a few function prototypes with it. --- h/aliasbr.h | 2 +- h/fmt_scan.h | 4 ++-- h/icalendar.h | 2 +- h/mh.h | 16 +++++++++------- h/mhparse.h | 12 ++++++------ h/netsec.h | 4 ++-- h/oauth.h | 6 +++--- h/prototypes.h | 22 +++++++++++----------- h/utils.h | 14 +++++++------- mts/smtp/smtp.c | 2 +- sbr/fmt_scan.c | 2 +- sbr/lock_file.c | 2 +- uip/aliasbr.c | 4 ++-- uip/inc.c | 2 +- uip/mhfixmsg.c | 2 +- uip/mhical.c | 2 +- uip/mhlsbr.c | 2 +- uip/mhmisc.c | 4 ++-- uip/mhparam.c | 2 +- uip/mhstoresbr.c | 2 +- uip/msgchk.c | 2 +- uip/post.c | 4 ++-- uip/slocal.c | 2 +- 23 files changed, 59 insertions(+), 57 deletions(-) diff --git a/h/aliasbr.h b/h/aliasbr.h index da027f59..6e7a5a32 100644 --- a/h/aliasbr.h +++ b/h/aliasbr.h @@ -21,7 +21,7 @@ struct adr { * prototypes */ int alias (char *); -int akvisible (void); +int akvisible (void) PURE; char *akresult (struct aka *); char *akvalue (char *); char *akerror (int); diff --git a/h/fmt_scan.h b/h/fmt_scan.h index 4f14b65c..2574c579 100644 --- a/h/fmt_scan.h +++ b/h/fmt_scan.h @@ -205,7 +205,7 @@ void fmt_freecomptext(void); * or NULL if the component is not found in the hash table. */ -struct comp *fmt_findcomp(char *component); +struct comp *fmt_findcomp(char *component) PURE; /* * Search for a component structure in the component hash table. @@ -213,7 +213,7 @@ struct comp *fmt_findcomp(char *component); * Identical to fmd_findcomp(), but is case-INSENSITIVE. */ -struct comp *fmt_findcasecomp(char *component); +struct comp *fmt_findcasecomp(char *component) PURE; /* * Add a component entry to the component hash table diff --git a/h/icalendar.h b/h/icalendar.h index be7244e2..0bedfded 100644 --- a/h/icalendar.h +++ b/h/icalendar.h @@ -71,7 +71,7 @@ void add_param_name (contentline *, char *); void add_param_value (contentline *, char *); void remove_value (value_list *); struct contentline *find_contentline (contentline *, const char *, - const char *); + const char *) PURE; void free_contentlines (contentline *); typedef struct tzdesc *tzdesc_t; diff --git a/h/mh.h b/h/mh.h index 75812a3c..bb06366b 100644 --- a/h/mh.h +++ b/h/mh.h @@ -46,6 +46,7 @@ typedef unsigned char boolean; /* not int so we can pack in a structure */ #define CONST __attribute__((const)) #define MALLOC __attribute__((malloc)) #define NONNULL(...) __attribute__((nonnull(__VA_ARGS__))) +#define PURE __attribute__((pure)) #define NMH_UNUSED(i) (void) i #else #define NORETURN @@ -54,6 +55,7 @@ typedef unsigned char boolean; /* not int so we can pack in a structure */ #define CONST #define MALLOC #define NONNULL(...) +#define PURE #define NMH_UNUSED(i) i #endif @@ -91,8 +93,8 @@ void charstring_clear (charstring_t) NONNULL(1); const char *charstring_buffer (const charstring_t) NONNULL(1); /* User is responsible for free'ing result of buffer copy. */ char *charstring_buffer_copy (const charstring_t) NONNULL(1); -size_t charstring_bytes (const charstring_t) NONNULL(1); -size_t charstring_chars (const charstring_t) NONNULL(1); +size_t charstring_bytes (const charstring_t) NONNULL(1) PURE; +size_t charstring_chars (const charstring_t) NONNULL(1) PURE; /* Length of the last character in the charstring. */ int charstring_last_char_len (const charstring_t) NONNULL(1); @@ -225,8 +227,8 @@ void bvector_fini(struct bvector *bv) NONNULL(1); void bvector_clear (bvector_t, size_t) NONNULL(1); void bvector_clear_all (bvector_t) NONNULL(1); void bvector_set (bvector_t, size_t) NONNULL(1); -unsigned int bvector_at (bvector_t, size_t) NONNULL(1); -unsigned long bvector_first_bits (bvector_t) NONNULL(1); +unsigned int bvector_at (bvector_t, size_t) NONNULL(1) PURE; +unsigned long bvector_first_bits (bvector_t) NONNULL(1) PURE; typedef struct svector *svector_t; @@ -234,9 +236,9 @@ svector_t svector_create (size_t); void svector_free (svector_t) NONNULL(1); char *svector_push_back (svector_t, char *) NONNULL(1); char *svector_at (svector_t, size_t) NONNULL(1); -char **svector_find(svector_t, const char *) NONNULL(1); -char **svector_strs (svector_t) NONNULL(1); -size_t svector_size (svector_t) NONNULL(1); +char **svector_find(svector_t, const char *) NONNULL(1) PURE; +char **svector_strs (svector_t) NONNULL(1) PURE; +size_t svector_size (svector_t) NONNULL(1) PURE; typedef struct ivector *ivector_t; diff --git a/h/mhparse.h b/h/mhparse.h index b96ce654..6b7ebebd 100644 --- a/h/mhparse.h +++ b/h/mhparse.h @@ -359,11 +359,11 @@ int open7Bit (CT, char **); void close_encoding (CT); char *ct_type_str (int) CONST; char *ct_subtype_str (int, int) CONST; -int ct_str_type (const char *); -int ct_str_subtype (int, const char *); -const struct str2init *get_ct_init (int); +int ct_str_type (const char *) PURE; +int ct_str_subtype (int, const char *) PURE; +const struct str2init *get_ct_init (int) PURE; const char *ce_str (int) CONST; -const struct str2init *get_ce_method (const char *); +const struct str2init *get_ce_method (const char *) PURE; char *content_charset (CT); void reverse_alternative_parts (CT); @@ -375,7 +375,7 @@ void reverse_alternative_parts (CT); * * ct - Content structure to examine */ -int is_inline(CT ct); +int is_inline(CT ct) PURE; /* * Given a list of messages, display information about them on standard @@ -529,6 +529,6 @@ extern int checksw; /* Add Content-MD5 field */ */ typedef struct mhstoreinfo *mhstoreinfo_t; mhstoreinfo_t mhstoreinfo_create(CT *, char *, const char *, int, int); -int mhstoreinfo_files_not_clobbered(const mhstoreinfo_t); +int mhstoreinfo_files_not_clobbered(const mhstoreinfo_t) PURE; void mhstoreinfo_free(mhstoreinfo_t); void store_all_messages (mhstoreinfo_t); diff --git a/h/netsec.h b/h/netsec.h index b3018a24..0a14a1d0 100644 --- a/h/netsec.h +++ b/h/netsec.h @@ -72,7 +72,7 @@ void netsec_set_hostname(netsec_context *ns_context, const char *hostname); * Returns "1" if snoop is enabled, 0 if it is not. */ -int netsec_get_snoop(netsec_context *ns_context); +int netsec_get_snoop(netsec_context *ns_context) PURE; /* * Sets "snoop" status; if snoop is set to a nonzero value, network traffic @@ -352,7 +352,7 @@ int netsec_negotiate_sasl(netsec_context *ns_context, const char *mechlist, * supported or in use. */ -char *netsec_get_sasl_mechanism(netsec_context *ns_context); +char *netsec_get_sasl_mechanism(netsec_context *ns_context) PURE; /* * Set the OAuth service name used to retrieve the OAuth parameters from diff --git a/h/oauth.h b/h/oauth.h index 66da2f31..1ba53149 100644 --- a/h/oauth.h +++ b/h/oauth.h @@ -145,7 +145,7 @@ mh_oauth_free(mh_oauth_ctx *ctx); * Never returns NULL. */ const char * -mh_oauth_svc_display_name(const mh_oauth_ctx *ctx); +mh_oauth_svc_display_name(const mh_oauth_ctx *ctx) PURE; /* * Enable logging for subsequent operations on ctx. @@ -164,7 +164,7 @@ mh_oauth_log_to(FILE *log, mh_oauth_ctx *ctx); * Must not be called if an error was not indicated. */ mh_oauth_err_code -mh_oauth_get_err_code(const mh_oauth_ctx *ctx); +mh_oauth_get_err_code(const mh_oauth_ctx *ctx) PURE; /* * Return null-terminated error message after some function indicated an error. @@ -205,7 +205,7 @@ mh_oauth_refresh(mh_oauth_cred *cred); * Return whether access token is present and not expired at time T. */ boolean -mh_oauth_access_token_valid(time_t t, const mh_oauth_cred *cred); +mh_oauth_access_token_valid(time_t t, const mh_oauth_cred *cred) PURE; /* * Free all resources associated with cred. diff --git a/h/prototypes.h b/h/prototypes.h index 0b40c0d5..a0c78060 100644 --- a/h/prototypes.h +++ b/h/prototypes.h @@ -27,7 +27,7 @@ void argsplit_msgarg (struct msgs_array *, char *, char **) NONNULL(1, 2, 3); void argsplit_insert (struct msgs_array *, char *, char **) NONNULL(1, 2, 3); void arglist_free (char *, char **); void ambigsw (const char *, const struct swit *) NONNULL(1, 2); -int atooi(char *) NONNULL(1); +int atooi(char *) NONNULL(1) PURE; char **brkstring (char *, char *, char *) NONNULL(1); /* @@ -46,9 +46,9 @@ int client(char *, char *, char *, int, int); void closefds(int); char *concat (const char *, ...); int context_del (char *); -char *context_find (const char *); +char *context_find (const char *) PURE; char *context_find_by_type (const char *, const char *, const char *); -int context_find_prefix(const char *); +int context_find_prefix(const char *) PURE; int context_foil (char *); void context_read (void); void context_replace (char *, char *); @@ -169,7 +169,7 @@ char *get_charset(void); char *getcpy(const char *str); char *get_default_editor(void); -char *getfolder(int); +char *getfolder(int) PURE; /* * Get a string from the terminfo database for the current terminal. @@ -222,7 +222,7 @@ char *get_term_stringparm(char *capability, long arg1, long arg2); */ int get_term_numcap(char *capability); -int m_atoi (char *); +int m_atoi (char *) PURE; char *m_backup (const char *); int m_convert (struct msgs *, char *); char *m_draft (char *, char *, int, int *); @@ -234,7 +234,7 @@ void m_getfld_track_filepos (m_getfld_state_t *, FILE *); void m_getfld_track_filepos2(m_getfld_state_t *); int m_getfld (m_getfld_state_t *, char[NAMESZ], char *, int *, FILE *); int m_getfld2(m_getfld_state_t *, char[NAMESZ], char *, int *); -int m_gmprot (void); +int m_gmprot (void) PURE; char *m_name (int); void m_unknown(m_getfld_state_t *, FILE *); @@ -255,7 +255,7 @@ void print_intro (FILE *, int); void print_sw (const char *, const struct swit *, char *, FILE *); void print_version (char *); void push (void); -char *r1bindex(char *, int); +char *r1bindex(char *, int) PURE; void readconfig (struct node **, FILE *, const char *, int); int refile (char **, char *); @@ -312,7 +312,7 @@ void seq_setcur (struct msgs *, int); void seq_setprev (struct msgs *); void seq_setunseen (struct msgs *, int); int showfile (char **, char *); -int smatch(const char *, const struct swit *); +int smatch(const char *, const struct swit *) PURE; /* * Convert a set of bit flags to printable format. @@ -347,11 +347,11 @@ int smatch(const char *, const struct swit *); * from least significant bit to most significant. */ char *snprintb (char *buffer, size_t size, unsigned flags, char *bitfield); -int ssequal (const char *, const char *); -int stringdex (char *, char *); +int ssequal (const char *, const char *) PURE; +int stringdex (char *, char *) PURE; char *trimcpy (char *); -int uprf (const char *, const char *); +int uprf (const char *, const char *) PURE; int vfgets (FILE *, char **); /* diff --git a/h/utils.h b/h/utils.h index 597569b5..13ac94e9 100644 --- a/h/utils.h +++ b/h/utils.h @@ -39,7 +39,7 @@ char *add(const char *, char *) MALLOC; char *addlist(char *, const char *) MALLOC; int folder_exists(const char *); void create_folder(char *, int, void (*)(int)); -int num_digits(int); +int num_digits(int) PURE; /* * A vector of char array, used to hold a list of string message numbers @@ -68,17 +68,17 @@ struct msgnum_array { void app_msgarg(struct msgs_array *, char *); void app_msgnum(struct msgnum_array *, int); -char *find_str (const char [], size_t, const char *); -char *rfind_str (const char [], size_t, const char *); -char *nmh_strcasestr (const char *, const char *); +char *find_str (const char [], size_t, const char *) PURE; +char *rfind_str (const char [], size_t, const char *) PURE; +char *nmh_strcasestr (const char *, const char *) PURE; void trunccpy(char *dst, const char *src, size_t size); /* A convenience for the common case of dst being an array. */ #define TRUNCCPY(dst, src) trunccpy(dst, src, sizeof (dst)) -bool has_prefix(const char *s, const char *prefix); -bool has_suffix(const char *s, const char *suffix); -bool has_suffix_c(const char *s, int c); +bool has_prefix(const char *s, const char *prefix) PURE; +bool has_suffix(const char *s, const char *suffix) PURE; +bool has_suffix_c(const char *s, int c) PURE; void trim_suffix_c(char *s, int c); void to_lower(char *s); void to_upper(char *s); diff --git a/mts/smtp/smtp.c b/mts/smtp/smtp.c index fed756b7..e3ac50d0 100644 --- a/mts/smtp/smtp.c +++ b/mts/smtp/smtp.c @@ -64,7 +64,7 @@ static int sm_nerror (char *); static int smtalk (int time, char *fmt, ...) CHECK_PRINTF(2, 3); static int sm_wstream (char *, int); static int smhear (void); -static char *EHLOset (char *); +static char *EHLOset (char *) PURE; static int sm_sasl_callback(enum sasl_message_type, unsigned const char *, unsigned int, unsigned char **, unsigned int *, char **); diff --git a/sbr/fmt_scan.c b/sbr/fmt_scan.c index 49fc717f..0de7a432 100644 --- a/sbr/fmt_scan.c +++ b/sbr/fmt_scan.c @@ -31,7 +31,7 @@ struct mailname fmt_mnull = { NULL, NULL, NULL, NULL, NULL, NULL, 0, 0, 0, 0, /* * static prototypes */ -static int match (char *, char *); +static int match (char *, char *) PURE; static char *get_x400_friendly (char *, char *, int); static int get_x400_comp (char *, char *, char *, int); diff --git a/sbr/lock_file.c b/sbr/lock_file.c index 8b0a1215..19cad331 100644 --- a/sbr/lock_file.c +++ b/sbr/lock_file.c @@ -90,7 +90,7 @@ static int lkopen_lockf (const char *, int, mode_t, int *); static int lkopen_flock (const char *, int, mode_t, int *); #endif /* HAVE_FLOCK */ -static enum locktype init_locktype(const char *); +static enum locktype init_locktype(const char *) PURE; static int lkopen_dot (const char *, int, mode_t, int *); static void lkclose_dot (int, const char *); diff --git a/uip/aliasbr.c b/uip/aliasbr.c index b3978ef4..ed347b67 100644 --- a/uip/aliasbr.c +++ b/uip/aliasbr.c @@ -27,8 +27,8 @@ char *akvalue (char *); char *akerror (int); static char *akval (struct aka *, char *); -static bool aleq (char *, char *); -static char *scanp (char *); +static bool aleq (char *, char *) PURE; +static char *scanp (char *) PURE; static char *getp (char *); static char *seekp (char *, char *, char **); static int addfile (struct aka *, char *); diff --git a/uip/inc.c b/uip/inc.c index 85a6396a..ad454e10 100644 --- a/uip/inc.c +++ b/uip/inc.c @@ -156,7 +156,7 @@ static FILE *in; /* * prototypes */ -static int maildir_srt(const void *va, const void *vb); +static int maildir_srt(const void *va, const void *vb) PURE; static void inc_done(int) NORETURN; static int pop_action(void *closure, char *); diff --git a/uip/mhfixmsg.c b/uip/mhfixmsg.c index 0bf0437c..34e366ce 100644 --- a/uip/mhfixmsg.c +++ b/uip/mhfixmsg.c @@ -116,7 +116,7 @@ static int should_decode(const char *, const char *, const char *); static int content_encoding (CT, const char **); static int strip_crs (CT, int *); static void update_cte (CT); -static int least_restrictive_encoding (CT); +static int least_restrictive_encoding (CT) PURE; static int less_restrictive (int, int); static int convert_charsets (CT, char *, int *); static int fix_always (CT, int *); diff --git a/uip/mhical.c b/uip/mhical.c index 1567d3af..3249d085 100644 --- a/uip/mhical.c +++ b/uip/mhical.c @@ -29,7 +29,7 @@ static void convert_common (contentline *, act); static void dump_unfolded (FILE *, contentline *); static void output (FILE *, contentline *, int); static void display (FILE *, contentline *, char *); -static const char *identity (const contentline *); +static const char *identity (const contentline *) PURE; static char *format_params (char *, param_list *); static char *fold (char *, int); diff --git a/uip/mhlsbr.c b/uip/mhlsbr.c index 5140b88e..edcf0e76 100644 --- a/uip/mhlsbr.c +++ b/uip/mhlsbr.c @@ -315,7 +315,7 @@ static int ptos (char *, char **); static char *parse (void); static void process (char *, char *, int, int); static void mhlfile (FILE *, char *, int, int); -static int mcomp_flags (char *); +static int mcomp_flags (char *) PURE; static char *mcomp_add (unsigned long, char *, char *); static void mcomp_format (struct mcomp *, struct mcomp *); static struct mcomp *add_queue (struct mcomp **, struct mcomp **, char *, char *, int); diff --git a/uip/mhmisc.c b/uip/mhmisc.c index d987f693..a20c186e 100644 --- a/uip/mhmisc.c +++ b/uip/mhmisc.c @@ -29,8 +29,8 @@ static char *errs = NULL; /* * prototypes */ -int part_ok (CT); -int part_exact(CT ct); +int part_ok (CT) PURE; +int part_exact(CT ct) PURE; int type_ok (CT, int); void content_error (char *, CT, char *, ...) CHECK_PRINTF(3, 4); void flush_errors (void); diff --git a/uip/mhparam.c b/uip/mhparam.c index d726d53e..1a392bb3 100644 --- a/uip/mhparam.c +++ b/uip/mhparam.c @@ -131,7 +131,7 @@ static struct proc procs [] = { /* * static prototypes */ -static char *p_find(char *); +static char *p_find(char *) PURE; int diff --git a/uip/mhstoresbr.c b/uip/mhstoresbr.c index 46fd8ed0..c0398518 100644 --- a/uip/mhstoresbr.c +++ b/uip/mhstoresbr.c @@ -26,7 +26,7 @@ enum clobber_policy_t { NMH_CLOBBER_NEVER }; -static enum clobber_policy_t clobber_policy (const char *); +static enum clobber_policy_t clobber_policy (const char *) PURE; struct mhstoreinfo { CT *cts; /* Top-level list of contents to store. */ diff --git a/uip/msgchk.c b/uip/msgchk.c index f582920e..73ed7284 100644 --- a/uip/msgchk.c +++ b/uip/msgchk.c @@ -79,7 +79,7 @@ DEFINE_SWITCH_ARRAY(MSGCHK, switches); /* * static prototypes */ -static int donote (char *, int); +static int donote (char *, int) PURE; static int checkmail (char *, char *, int, int, int); static int remotemail (char *, char *, char *, char *, int, int, int, int, char *, int, const char *); diff --git a/uip/post.c b/uip/post.c index a02b0711..6dc18d10 100644 --- a/uip/post.c +++ b/uip/post.c @@ -290,7 +290,7 @@ static char *partno = NULL; static void putfmt (char *, char *, int *, FILE *); static void start_headers (void); static void finish_headers (FILE *); -static int get_header (char *, struct headers *); +static int get_header (char *, struct headers *) PURE; static int putadr (char *, char *, struct mailname *, FILE *, unsigned int, char *, unsigned int); static void putgrp (char *, char *, FILE *, unsigned int); @@ -301,7 +301,7 @@ static int annoaux (struct mailname *); static void insert_fcc (struct headers *, char *); static void make_bcc_file (int); static void verify_all_addresses (int, int, char *, int, char *); -static void chkadr (void); +static void chkadr (void) PURE; static void sigon (void); static void sigoff (void); static void p_refile (char *); diff --git a/uip/slocal.c b/uip/slocal.c index e136f101..2bf71fab 100644 --- a/uip/slocal.c +++ b/uip/slocal.c @@ -163,7 +163,7 @@ static int split (char *, char **); static int parse (int); static void expand (char *, char *, int); static void glob (int); -static struct pair *lookup (struct pair *, char *); +static struct pair *lookup (struct pair *, char *) PURE; static int logged_in (void); static int timely (char *, char *); static int usr_file (int, char *, int); -- 2.56.0