From 9e62d63e086644da90db03c16907e5c7bb5a42cb Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Thu, 2 Jun 2011 10:05:59 +0200 Subject: [PATCH] mark functions with const and pure attributes Mark functions per suggestions from gcc-4.6 when using these options: -Wsuggest-attribute=pure -Wsuggest-attribute=const. Use gnulib's _GL_ATTRIBUTE_PURE and _GL_ATTRIBUTE_CONST macros. Follow these guidelines: when possible, apply the attribute to an extern declaration, not to its definition. Apply it to the definition only when the definition is static. * lib/argmatch.h (argmatch, argmatch_to_argument): Mark. * lib/argv-iter.h (argv_iter_n_args): Likewise. * lib/base64.h (isbase64): Likewise. * lib/basename-lgpl.c (last_component, base_len): Likewise. * lib/c-ctype.h (c_isascii, c_isalnum, c_isalpha): Likewise. (c_isblank, c_iscntrl, c_isdigit, c_islower, c_isgraph): Likewise. (c_isprint, c_ispunct, c_isspace, c_isupper, c_isxdigit): Likewise. (c_tolower, c_toupper): Likewise. * lib/c-strcase.h (c_strcasecmp, c_strncasecmp): Likewise. * lib/chdir-long.c (find_non_slash): Likewise. * lib/dirname.h (base_len, dir_len, last_component): Likewise. * lib/exclude.h (fnmatch_pattern_has_wildcards): Likewise. * lib/file-type.h (file_type): Likewise. * lib/filenamecat-lgpl.c (longest_relative_suffix): Likewise. * lib/filevercmp.c (verrevcmp): Likewise. * lib/freadahead.h (freadahead): Likewise. * lib/fts.c (fts_maxarglen): Likewise. * lib/hash-pjw.h (hash_pjw): Likewise. * lib/hash-triple.h (triple_hash_no_name, triple_compare_ino_str): * lib/hash.c (is_prime, next_prime): Likewise. * lib/hash.c (hash_get_n_buckets, hash_get_n_buckets_used): Likewise. (hash_get_n_entries, hash_get_max_bucket_length): Likewise. (hash_table_ok, hash_get_first, hash_string): Likewise. (compute_bucket_size): Likewise. * lib/i-ring.h (i_ring_empty): Likewise. * lib/isnan.c (isnanl): Likewise. * lib/math.h (isnanl, rpl_isnanl): Likewise. * lib/memcasecmp.h (memcasecmp): Likewise. * lib/memchr2.h (memchr2): Likewise. * lib/memcmp2.h (memcmp2): Likewise. * lib/parse-datetime.y (lookup_zone): Likewise. * lib/sockets.h (gl_sockets_startup, gl_sockets_cleanup) [!WINDOWS_SOCKETS]: Likewise. * lib/strnlen1.h (strnlen1): Likewise. * lib/uniwidth.in.h (uc_width): Likewise, but since this is installed as a public header by libunistring, it cannot depend on the macro definitions of gnulib-common.m4, so open-code the __attribute__... * lib/quotearg.c: Add pragma to avoid unwarranted suggestion from gcc's -Wsuggest-attribute=pure for quoting_options_from_style. (quoting_options_from_style): Add a comment. * lib/propername.h (proper_name): Add a comment. --- ChangeLog | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ lib/argmatch.h | 5 +++-- lib/argv-iter.h | 2 +- lib/base64.h | 2 +- lib/c-ctype.h | 34 +++++++++++++++++----------------- lib/c-strcase.h | 5 +++-- lib/chdir-long.c | 2 +- lib/dirname.h | 6 +++--- lib/exclude.h | 2 +- lib/file-type.h | 2 +- lib/filenamecat-lgpl.c | 2 +- lib/filevercmp.c | 2 +- lib/freadahead.h | 2 +- lib/fts.c | 2 +- lib/hash-pjw.h | 2 +- lib/hash-triple.h | 8 +++++--- lib/hash.c | 4 ++-- lib/hash.h | 14 +++++++------- lib/i-ring.h | 2 +- lib/isnan.c | 2 +- lib/math.in.h | 4 ++-- lib/memcasecmp.h | 2 +- lib/memchr2.h | 3 ++- lib/memcmp2.h | 3 ++- lib/parse-datetime.y | 2 +- lib/propername.h | 2 +- lib/quotearg.c | 9 ++++++++- lib/sockets.h | 13 +++++++++++-- lib/strnlen1.h | 3 ++- lib/uniwidth.in.h | 6 +++++- 30 files changed, 137 insertions(+), 60 deletions(-) diff --git a/ChangeLog b/ChangeLog index cdc32a770..ba43f79f7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,53 @@ +2011-11-27 Jim Meyering + + mark functions with const and pure attributes + + Mark functions per suggestions from gcc-4.6 when using these options: + -Wsuggest-attribute=pure -Wsuggest-attribute=const. + Use gnulib's _GL_ATTRIBUTE_PURE and _GL_ATTRIBUTE_CONST macros. + Follow these guidelines: when possible, apply the attribute to + an extern declaration, not to its definition. Apply it to the + definition only when the definition is static. + * lib/argmatch.h (argmatch, argmatch_to_argument): Mark. + * lib/argv-iter.h (argv_iter_n_args): Likewise. + * lib/base64.h (isbase64): Likewise. + * lib/basename-lgpl.c (last_component, base_len): Likewise. + * lib/c-ctype.h (c_isascii, c_isalnum, c_isalpha): Likewise. + (c_isblank, c_iscntrl, c_isdigit, c_islower, c_isgraph): Likewise. + (c_isprint, c_ispunct, c_isspace, c_isupper, c_isxdigit): Likewise. + (c_tolower, c_toupper): Likewise. + * lib/c-strcase.h (c_strcasecmp, c_strncasecmp): Likewise. + * lib/chdir-long.c (find_non_slash): Likewise. + * lib/dirname.h (base_len, dir_len, last_component): Likewise. + * lib/exclude.h (fnmatch_pattern_has_wildcards): Likewise. + * lib/file-type.h (file_type): Likewise. + * lib/filenamecat-lgpl.c (longest_relative_suffix): Likewise. + * lib/filevercmp.c (verrevcmp): Likewise. + * lib/freadahead.h (freadahead): Likewise. + * lib/fts.c (fts_maxarglen): Likewise. + * lib/hash-pjw.h (hash_pjw): Likewise. + * lib/hash-triple.h (triple_hash_no_name, triple_compare_ino_str): + * lib/hash.c (is_prime, next_prime): Likewise. + * lib/hash.c (hash_get_n_buckets, hash_get_n_buckets_used): Likewise. + (hash_get_n_entries, hash_get_max_bucket_length): Likewise. + (hash_table_ok, hash_get_first, hash_string): Likewise. + (compute_bucket_size): Likewise. + * lib/i-ring.h (i_ring_empty): Likewise. + * lib/isnan.c (isnanl): Likewise. + * lib/math.h (isnanl, rpl_isnanl): Likewise. + * lib/memcasecmp.h (memcasecmp): Likewise. + * lib/memchr2.h (memchr2): Likewise. + * lib/memcmp2.h (memcmp2): Likewise. + * lib/parse-datetime.y (lookup_zone): Likewise. + * lib/sockets.h (gl_sockets_startup, gl_sockets_cleanup) + [!WINDOWS_SOCKETS]: Likewise. + * lib/strnlen1.h (strnlen1): Likewise. + * lib/uniwidth.in.h (uc_width): Likewise. + * lib/quotearg.c: Add pragma to avoid unwarranted suggestion from + gcc's -Wsuggest-attribute=pure for quoting_options_from_style. + (quoting_options_from_style): Add a comment. + * lib/propername.h (proper_name): Add a comment. + 2011-11-27 Bruno Haible Remove unused macros from !_LIBC code in glibc-borrowed files. diff --git a/lib/argmatch.h b/lib/argmatch.h index f87729dd6..b1a119368 100644 --- a/lib/argmatch.h +++ b/lib/argmatch.h @@ -40,7 +40,7 @@ to the same values in VALLIST). */ ptrdiff_t argmatch (char const *arg, char const *const *arglist, - char const *vallist, size_t valsize); + char const *vallist, size_t valsize) _GL_ATTRIBUTE_PURE; # define ARGMATCH(Arg, Arglist, Vallist) \ argmatch (Arg, Arglist, (char const *) (Vallist), sizeof *(Vallist)) @@ -93,7 +93,8 @@ ptrdiff_t __xargmatch_internal (char const *context, char const *argmatch_to_argument (char const *value, char const *const *arglist, - char const *vallist, size_t valsize); + char const *vallist, size_t valsize) + _GL_ATTRIBUTE_PURE; # define ARGMATCH_TO_ARGUMENT(Value, Arglist, Vallist) \ argmatch_to_argument (Value, Arglist, \ diff --git a/lib/argv-iter.h b/lib/argv-iter.h index 9f76f2896..73db77d1e 100644 --- a/lib/argv-iter.h +++ b/lib/argv-iter.h @@ -37,6 +37,6 @@ struct argv_iterator *argv_iter_init_stream (FILE *fp) char *argv_iter (struct argv_iterator *, enum argv_iter_err *) _GL_ARG_NONNULL ((1, 2)); size_t argv_iter_n_args (struct argv_iterator const *) - _GL_ARG_NONNULL ((1)); + _GL_ATTRIBUTE_PURE _GL_ARG_NONNULL ((1)); void argv_iter_free (struct argv_iterator *) _GL_ARG_NONNULL ((1)); diff --git a/lib/base64.h b/lib/base64.h index 98f962f4a..1d65edc6e 100644 --- a/lib/base64.h +++ b/lib/base64.h @@ -35,7 +35,7 @@ struct base64_decode_context char buf[4]; }; -extern bool isbase64 (char ch); +extern bool isbase64 (char ch) _GL_ATTRIBUTE_CONST; extern void base64_encode (const char *restrict in, size_t inlen, char *restrict out, size_t outlen); diff --git a/lib/c-ctype.h b/lib/c-ctype.h index ed8859ed3..078bd9a01 100644 --- a/lib/c-ctype.h +++ b/lib/c-ctype.h @@ -118,23 +118,23 @@ extern "C" { if (c_isalpha (*s)) ... */ -extern bool c_isascii (int c); /* not locale dependent */ - -extern bool c_isalnum (int c); -extern bool c_isalpha (int c); -extern bool c_isblank (int c); -extern bool c_iscntrl (int c); -extern bool c_isdigit (int c); -extern bool c_islower (int c); -extern bool c_isgraph (int c); -extern bool c_isprint (int c); -extern bool c_ispunct (int c); -extern bool c_isspace (int c); -extern bool c_isupper (int c); -extern bool c_isxdigit (int c); - -extern int c_tolower (int c); -extern int c_toupper (int c); +extern bool c_isascii (int c) _GL_ATTRIBUTE_CONST; /* not locale dependent */ + +extern bool c_isalnum (int c) _GL_ATTRIBUTE_CONST; +extern bool c_isalpha (int c) _GL_ATTRIBUTE_CONST; +extern bool c_isblank (int c) _GL_ATTRIBUTE_CONST; +extern bool c_iscntrl (int c) _GL_ATTRIBUTE_CONST; +extern bool c_isdigit (int c) _GL_ATTRIBUTE_CONST; +extern bool c_islower (int c) _GL_ATTRIBUTE_CONST; +extern bool c_isgraph (int c) _GL_ATTRIBUTE_CONST; +extern bool c_isprint (int c) _GL_ATTRIBUTE_CONST; +extern bool c_ispunct (int c) _GL_ATTRIBUTE_CONST; +extern bool c_isspace (int c) _GL_ATTRIBUTE_CONST; +extern bool c_isupper (int c) _GL_ATTRIBUTE_CONST; +extern bool c_isxdigit (int c) _GL_ATTRIBUTE_CONST; + +extern int c_tolower (int c) _GL_ATTRIBUTE_CONST; +extern int c_toupper (int c) _GL_ATTRIBUTE_CONST; #if defined __GNUC__ && defined __OPTIMIZE__ && !defined __OPTIMIZE_SIZE__ && !defined NO_C_CTYPE_MACROS diff --git a/lib/c-strcase.h b/lib/c-strcase.h index 66a549209..df2f0705f 100644 --- a/lib/c-strcase.h +++ b/lib/c-strcase.h @@ -40,12 +40,13 @@ extern "C" { /* Compare strings S1 and S2, ignoring case, returning less than, equal to or greater than zero if S1 is lexicographically less than, equal to or greater than S2. */ -extern int c_strcasecmp (const char *s1, const char *s2); +extern int c_strcasecmp (const char *s1, const char *s2) _GL_ATTRIBUTE_PURE; /* Compare no more than N characters of strings S1 and S2, ignoring case, returning less than, equal to or greater than zero if S1 is lexicographically less than, equal to or greater than S2. */ -extern int c_strncasecmp (const char *s1, const char *s2, size_t n); +extern int c_strncasecmp (const char *s1, const char *s2, size_t n) + _GL_ATTRIBUTE_PURE; #ifdef __cplusplus diff --git a/lib/chdir-long.c b/lib/chdir-long.c index 96b750cb4..af41b121d 100644 --- a/lib/chdir-long.c +++ b/lib/chdir-long.c @@ -83,7 +83,7 @@ cdb_advance_fd (struct cd_buf *cdb, char const *dir) } /* Return a pointer to the first non-slash in S. */ -static inline char * +static inline char * _GL_ATTRIBUTE_PURE find_non_slash (char const *s) { size_t n_slash = strspn (s, "/"); diff --git a/lib/dirname.h b/lib/dirname.h index 2ef988244..ba9c56e41 100644 --- a/lib/dirname.h +++ b/lib/dirname.h @@ -37,9 +37,9 @@ char *dir_name (char const *file); # endif char *mdir_name (char const *file); -size_t base_len (char const *file); -size_t dir_len (char const *file); -char *last_component (char const *file); +size_t base_len (char const *file) _GL_ATTRIBUTE_PURE; +size_t dir_len (char const *file) _GL_ATTRIBUTE_PURE; +char *last_component (char const *file) _GL_ATTRIBUTE_PURE; bool strip_trailing_slashes (char *file); diff --git a/lib/exclude.h b/lib/exclude.h index 0a314a99f..63e94d323 100644 --- a/lib/exclude.h +++ b/lib/exclude.h @@ -39,7 +39,7 @@ struct exclude; -bool fnmatch_pattern_has_wildcards (const char *, int); +bool fnmatch_pattern_has_wildcards (const char *, int) _GL_ATTRIBUTE_PURE; struct exclude *new_exclude (void); void free_exclude (struct exclude *); diff --git a/lib/file-type.h b/lib/file-type.h index 0d1b9a483..d7c66e968 100644 --- a/lib/file-type.h +++ b/lib/file-type.h @@ -24,6 +24,6 @@ # include # include -char const *file_type (struct stat const *); +char const *file_type (struct stat const *) _GL_ATTRIBUTE_PURE; #endif /* FILE_TYPE_H */ diff --git a/lib/filenamecat-lgpl.c b/lib/filenamecat-lgpl.c index 8cb2da43d..26d1c735f 100644 --- a/lib/filenamecat-lgpl.c +++ b/lib/filenamecat-lgpl.c @@ -34,7 +34,7 @@ /* Return the longest suffix of F that is a relative file name. If it has no such suffix, return the empty string. */ -static char const * +static char const * _GL_ATTRIBUTE_PURE longest_relative_suffix (char const *f) { for (f += FILE_SYSTEM_PREFIX_LEN (f); ISSLASH (*f); f++) diff --git a/lib/filevercmp.c b/lib/filevercmp.c index f6ed2481f..fd9e9f429 100644 --- a/lib/filevercmp.c +++ b/lib/filevercmp.c @@ -80,7 +80,7 @@ order (unsigned char c) section on the `Version' control field. This version of the code implements that from s5.6.12 of Debian Policy v3.8.0.1 http://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Version */ -static int +static int _GL_ATTRIBUTE_PURE verrevcmp (const char *s1, size_t s1_len, const char *s2, size_t s2_len) { size_t s1_pos = 0; diff --git a/lib/freadahead.h b/lib/freadahead.h index af03b8995..0ddb826a4 100644 --- a/lib/freadahead.h +++ b/lib/freadahead.h @@ -31,7 +31,7 @@ extern "C" { STREAM must not be wide-character oriented. */ -extern size_t freadahead (FILE *stream); +extern size_t freadahead (FILE *stream) _GL_ATTRIBUTE_PURE; #ifdef __cplusplus } diff --git a/lib/fts.c b/lib/fts.c index f61a91e6f..ccd1980ed 100644 --- a/lib/fts.c +++ b/lib/fts.c @@ -1988,7 +1988,7 @@ fts_padjust (FTS *sp, FTSENT *head) } static size_t -internal_function +internal_function _GL_ATTRIBUTE_PURE fts_maxarglen (char * const *argv) { size_t len, max; diff --git a/lib/hash-pjw.h b/lib/hash-pjw.h index 80c183864..36b776ae2 100644 --- a/lib/hash-pjw.h +++ b/lib/hash-pjw.h @@ -20,4 +20,4 @@ and return the hash code modulo TABLESIZE. The result is platform dependent: it depends on the size of the 'size_t' type and on the signedness of the 'char' type. */ -extern size_t hash_pjw (void const *x, size_t tablesize); +extern size_t hash_pjw (void const *x, size_t tablesize) _GL_ATTRIBUTE_PURE; diff --git a/lib/hash-triple.h b/lib/hash-triple.h index 51863c9df..0658d8170 100644 --- a/lib/hash-triple.h +++ b/lib/hash-triple.h @@ -13,10 +13,12 @@ struct F_triple dev_t st_dev; }; -extern size_t triple_hash (void const *x, size_t table_size); -extern size_t triple_hash_no_name (void const *x, size_t table_size); +extern size_t triple_hash (void const *x, size_t table_size) _GL_ATTRIBUTE_PURE; +extern size_t triple_hash_no_name (void const *x, size_t table_size) + _GL_ATTRIBUTE_PURE; extern bool triple_compare (void const *x, void const *y); -extern bool triple_compare_ino_str (void const *x, void const *y); +extern bool triple_compare_ino_str (void const *x, void const *y) + _GL_ATTRIBUTE_PURE; extern void triple_free (void *x); #endif diff --git a/lib/hash.c b/lib/hash.c index 9f2d07569..a0e641670 100644 --- a/lib/hash.c +++ b/lib/hash.c @@ -440,7 +440,7 @@ hash_string (const char *string, size_t n_buckets) /* Return true if CANDIDATE is a prime number. CANDIDATE should be an odd number at least equal to 11. */ -static bool +static bool _GL_ATTRIBUTE_CONST is_prime (size_t candidate) { size_t divisor = 3; @@ -459,7 +459,7 @@ is_prime (size_t candidate) /* Round a given CANDIDATE number up to the nearest prime, and return that prime. Primes lower than 10 are merely skipped. */ -static size_t +static size_t _GL_ATTRIBUTE_CONST next_prime (size_t candidate) { /* Skip small primes. */ diff --git a/lib/hash.h b/lib/hash.h index 572032d02..541abc4fa 100644 --- a/lib/hash.h +++ b/lib/hash.h @@ -69,22 +69,22 @@ struct hash_table; typedef struct hash_table Hash_table; /* Information and lookup. */ -size_t hash_get_n_buckets (const Hash_table *); -size_t hash_get_n_buckets_used (const Hash_table *); -size_t hash_get_n_entries (const Hash_table *); -size_t hash_get_max_bucket_length (const Hash_table *); -bool hash_table_ok (const Hash_table *); +size_t hash_get_n_buckets (const Hash_table *) _GL_ATTRIBUTE_PURE; +size_t hash_get_n_buckets_used (const Hash_table *) _GL_ATTRIBUTE_PURE; +size_t hash_get_n_entries (const Hash_table *) _GL_ATTRIBUTE_PURE; +size_t hash_get_max_bucket_length (const Hash_table *) _GL_ATTRIBUTE_PURE; +bool hash_table_ok (const Hash_table *) _GL_ATTRIBUTE_PURE; void hash_print_statistics (const Hash_table *, FILE *); void *hash_lookup (const Hash_table *, const void *); /* Walking. */ -void *hash_get_first (const Hash_table *); +void *hash_get_first (const Hash_table *) _GL_ATTRIBUTE_PURE; void *hash_get_next (const Hash_table *, const void *); size_t hash_get_entries (const Hash_table *, void **, size_t); size_t hash_do_for_each (const Hash_table *, Hash_processor, void *); /* Allocation and clean-up. */ -size_t hash_string (const char *, size_t); +size_t hash_string (const char *, size_t) _GL_ATTRIBUTE_PURE; void hash_reset_tuning (Hash_tuning *); Hash_table *hash_initialize (size_t, const Hash_tuning *, Hash_hasher, Hash_comparator, diff --git a/lib/i-ring.h b/lib/i-ring.h index f0700b693..ae81f683e 100644 --- a/lib/i-ring.h +++ b/lib/i-ring.h @@ -41,4 +41,4 @@ typedef struct I_ring I_ring; void i_ring_init (I_ring *ir, int ir_default_val); int i_ring_push (I_ring *ir, int val); int i_ring_pop (I_ring *ir); -bool i_ring_empty (I_ring const *ir); +bool i_ring_empty (I_ring const *ir) _GL_ATTRIBUTE_PURE; diff --git a/lib/isnan.c b/lib/isnan.c index 1d0754c93..db0c685b1 100644 --- a/lib/isnan.c +++ b/lib/isnan.c @@ -21,7 +21,7 @@ /* Specification. */ #ifdef USE_LONG_DOUBLE /* Specification found in math.h or isnanl-nolibm.h. */ -extern int rpl_isnanl (long double x); +extern int rpl_isnanl (long double x) _GL_ATTRIBUTE_CONST; #elif ! defined USE_FLOAT /* Specification found in math.h or isnand-nolibm.h. */ extern int rpl_isnand (double x); diff --git a/lib/math.in.h b/lib/math.in.h index eadb489cd..6b5966aec 100644 --- a/lib/math.in.h +++ b/lib/math.in.h @@ -1246,7 +1246,7 @@ _GL_EXTERN_C int isnand (double x); /* Test whether X is a NaN. */ # undef isnanl # define isnanl rpl_isnanl -_GL_EXTERN_C int isnanl (long double x); +_GL_EXTERN_C int isnanl (long double x) _GL_ATTRIBUTE_CONST; # endif #endif @@ -1272,7 +1272,7 @@ _GL_EXTERN_C int rpl_isnand (double x); # if @HAVE_ISNANL@ && __GNUC__ >= 4 # define gl_isnan_l(x) __builtin_isnanl ((long double)(x)) # else -_GL_EXTERN_C int rpl_isnanl (long double x); +_GL_EXTERN_C int rpl_isnanl (long double x) _GL_ATTRIBUTE_CONST; # define gl_isnan_l(x) rpl_isnanl (x) # endif # undef isnan diff --git a/lib/memcasecmp.h b/lib/memcasecmp.h index d2e14ac15..502b856eb 100644 --- a/lib/memcasecmp.h +++ b/lib/memcasecmp.h @@ -19,4 +19,4 @@ #include -int memcasecmp (const void *vs1, const void *vs2, size_t n); +int memcasecmp (const void *vs1, const void *vs2, size_t n) _GL_ATTRIBUTE_PURE; diff --git a/lib/memchr2.h b/lib/memchr2.h index e5752237b..c34acbddc 100644 --- a/lib/memchr2.h +++ b/lib/memchr2.h @@ -24,7 +24,8 @@ extern "C" { char) that occurs within N bytes of the memory region S. If neither byte appears, return NULL. */ -extern void *memchr2 (void const *s, int c1, int c2, size_t n); +extern void *memchr2 (void const *s, int c1, int c2, size_t n) + _GL_ATTRIBUTE_PURE; #ifdef __cplusplus } diff --git a/lib/memcmp2.h b/lib/memcmp2.h index cbe6e8ce6..21552b297 100644 --- a/lib/memcmp2.h +++ b/lib/memcmp2.h @@ -29,7 +29,8 @@ extern "C" { This function's result is locale independent, unlike memcoll()'s. Return a negative number if S1 < S2, a positive number if S1 > S2, or 0 if S1 and S2 have the same contents. */ -extern int memcmp2 (const char *s1, size_t n1, const char *s2, size_t n2); +extern int memcmp2 (const char *s1, size_t n1, const char *s2, size_t n2) + _GL_ATTRIBUTE_PURE; #ifdef __cplusplus diff --git a/lib/parse-datetime.y b/lib/parse-datetime.y index d99c9558e..5621adc7c 100644 --- a/lib/parse-datetime.y +++ b/lib/parse-datetime.y @@ -905,7 +905,7 @@ to_year (textint textyear) return year; } -static table const * +static table const * _GL_ATTRIBUTE_PURE lookup_zone (parser_control const *pc, char const *name) { table const *tp; diff --git a/lib/propername.h b/lib/propername.h index d2a1e3bf0..a4eac0100 100644 --- a/lib/propername.h +++ b/lib/propername.h @@ -89,7 +89,7 @@ extern "C" { #endif /* Return the localization of NAME. NAME is written in ASCII. */ -extern const char * proper_name (const char *name); +extern const char * proper_name (const char *name) /* NOT PURE */; /* Return the localization of a name whose original writing is not ASCII. NAME_UTF8 is the real name, written in UTF-8 with octal or hexadecimal diff --git a/lib/quotearg.c b/lib/quotearg.c index da8ba1eac..3c154117d 100644 --- a/lib/quotearg.c +++ b/lib/quotearg.c @@ -17,6 +17,13 @@ /* Written by Paul Eggert */ +/* Without this pragma, gcc 4.7.0 20111124 mistakenly suggests that + the quoting_options_from_style function might be candidate for + attribute 'pure' */ +#if (__GNUC__ == 4 && 3 <= __GNUC_MINOR__) || 4 < __GNUC__ +# pragma GCC diagnostic ignored "-Wsuggest-attribute=pure" +#endif + #include #include "quotearg.h" @@ -165,7 +172,7 @@ set_custom_quoting (struct quoting_options *o, } /* Return quoting options for STYLE, with no extra quoting. */ -static struct quoting_options +static struct quoting_options /* NOT PURE!! */ quoting_options_from_style (enum quoting_style style) { struct quoting_options o = { 0 }; diff --git a/lib/sockets.h b/lib/sockets.h index 323f68cd1..68bf73126 100644 --- a/lib/sockets.h +++ b/lib/sockets.h @@ -26,8 +26,17 @@ #define SOCKETS_2_1 0x201 #define SOCKETS_2_2 0x202 -int gl_sockets_startup (int version); -int gl_sockets_cleanup (void); +int gl_sockets_startup (int version) +#if !WINDOWS_SOCKETS + _GL_ATTRIBUTE_CONST +#endif + ; + +int gl_sockets_cleanup (void) +#if !WINDOWS_SOCKETS + _GL_ATTRIBUTE_CONST +#endif + ; /* This function is useful it you create a socket using gnulib's Winsock wrappers but needs to pass on the socket handle to some diff --git a/lib/strnlen1.h b/lib/strnlen1.h index 1bb13de60..a0634fecc 100644 --- a/lib/strnlen1.h +++ b/lib/strnlen1.h @@ -28,7 +28,8 @@ extern "C" { /* Find the length of STRING + 1, but scan at most MAXLEN bytes. If no '\0' terminator is found in that many characters, return MAXLEN. */ /* This is the same as strnlen (string, maxlen - 1) + 1. */ -extern size_t strnlen1 (const char *string, size_t maxlen); +extern size_t strnlen1 (const char *string, size_t maxlen) + _GL_ATTRIBUTE_PURE; #ifdef __cplusplus diff --git a/lib/uniwidth.in.h b/lib/uniwidth.in.h index be99b9726..e80674433 100644 --- a/lib/uniwidth.in.h +++ b/lib/uniwidth.in.h @@ -38,7 +38,11 @@ extern "C" { /* Determine number of column positions required for UC. */ extern int - uc_width (ucs4_t uc, const char *encoding); + uc_width (ucs4_t uc, const char *encoding) +#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96) + __attribute__ ((__pure__)) +#endif + ; /* Determine number of column positions required for first N units (or fewer if S ends before this) in S. */ -- 2.11.0