+2011-11-27 Jim Meyering <meyering@redhat.com>
+
+ 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 <bruno@clisp.org>
Remove unused macros from !_LIBC code in glibc-borrowed files.
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))
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, \
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));
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);
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
/* 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
}
/* 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, "/");
# 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);
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 *);
# include <sys/types.h>
# include <sys/stat.h>
-char const *file_type (struct stat const *);
+char const *file_type (struct stat const *) _GL_ATTRIBUTE_PURE;
#endif /* FILE_TYPE_H */
/* 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++)
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;
STREAM must not be wide-character oriented. */
-extern size_t freadahead (FILE *stream);
+extern size_t freadahead (FILE *stream) _GL_ATTRIBUTE_PURE;
#ifdef __cplusplus
}
}
static size_t
-internal_function
+internal_function _GL_ATTRIBUTE_PURE
fts_maxarglen (char * const *argv)
{
size_t len, max;
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;
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
/* 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;
/* 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. */
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,
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;
/* 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);
/* 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
# 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
#include <stddef.h>
-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;
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
}
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
return year;
}
-static table const *
+static table const * _GL_ATTRIBUTE_PURE
lookup_zone (parser_control const *pc, char const *name)
{
table const *tp;
#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
/* Written by Paul Eggert <eggert@twinsun.com> */
+/* 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 <config.h>
#include "quotearg.h"
}
/* 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 };
#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
/* 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
/* 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. */