1
0
mirror of git://git.sv.gnu.org/coreutils.git synced 2026-06-01 15:26:29 +02:00

maint: use "const" and "pure" function attributes where possible

* configure.ac (WARN_CFLAGS): Add -Wsuggest-attribute=const,
-Wsuggest-attribute=pure and -Wsuggest-attribute=noreturn.
(GNULIB_WARN_CFLAGS): But do not add them here... yet.
* src/chown-core.h (chopt_free, uid_to_name): Add function attribute(s).
* src/copy.c (is_ancestor, valid_options): Likewise.
* src/copy.h (chown_failure_ok): Likewise.
* src/dd.c (operand_matches, operand_is): Likewise.
* src/df.c (selected_fstype, excluded_fstype): Likewise.
* src/expr.c (null looks_like_integer): Likewise.
* src/md5sum.c (hex_digits): Likewise.
* src/od.c (get_lcm): Likewise.
* src/pathchk.c (component_start, component_len): Likewise.
* src/pinky.c (count_ampersands): Likewise.
* src/pr.c (cols_ready_to_print): Likewise.
* src/ptx.c (search_table): Likewise.
* src/sort.c (find_unit_order): Likewise.
* src/stty.c (mode_type_flag, string_to_baud, baud_to_value): Likewise.
* src/system.h (gcd, lcm): Likewise.
* src/tr.c (is_char_class_member, look_up_char_class): Likewise.
(star_digits_closebracket): Likewise.
* src/uniq.c (find_field): Likewise.
* src/wc.c (compute_number_width): Likewise.
* lib/xfts.h (cycle_warning_required): Likewise.
* gl/lib/randint.h (randint_get_source): Likewise.
* gl/lib/randperm.c (ceil_lg): Likewise.
* gl/lib/randperm.h (randperm_bound): Likewise.
* lib/strnumcmp.h (strintcmp): Likewise.
This commit is contained in:
Jim Meyering
2011-04-24 19:06:39 +02:00
parent 76d8e9abe1
commit 84d048002e
27 changed files with 46 additions and 38 deletions
+6
View File
@@ -101,6 +101,9 @@ if test "$gl_gcc_warnings" = yes; then
done
gl_WARN_ADD([-Wno-sign-compare]) # Too many warnings for now
gl_WARN_ADD([-Wno-unused-parameter]) # Too many warnings for now
gl_WARN_ADD([-Wsuggest-attribute=const])
gl_WARN_ADD([-Wsuggest-attribute=pure])
gl_WARN_ADD([-Wsuggest-attribute=noreturn])
# In spite of excluding -Wlogical-op above, it is enabled, as of
# gcc 4.5.0 20090517, and it provokes warnings in cat.c, dd.c, truncate.c
@@ -124,6 +127,9 @@ if test "$gl_gcc_warnings" = yes; then
nw="$nw -Wunused-macros"
nw="$nw -Wmissing-prototypes"
nw="$nw -Wold-style-definition"
# FIXME: remove/reenable the following two, once gnulib is adjusted.
nw="$nw -Wsuggest-attribute=const"
nw="$nw -Wsuggest-attribute=pure"
gl_MANYWARN_COMPLEMENT([GNULIB_WARN_CFLAGS], [$WARN_CFLAGS], [$nw])
AC_SUBST([GNULIB_WARN_CFLAGS])
+2 -1
View File
@@ -34,7 +34,8 @@ struct randint_source;
struct randint_source *randint_new (struct randread_source *);
struct randint_source *randint_all_new (char const *, size_t);
struct randread_source *randint_get_source (struct randint_source const *);
struct randread_source *randint_get_source (struct randint_source const *)
_GL_ATTRIBUTE_PURE;
randint randint_genmax (struct randint_source *, randint genmax);
/* Consume random data from *S to generate a random number in the range
+1 -1
View File
@@ -30,7 +30,7 @@
/* Return the ceiling of the log base 2 of N. If N is zero, return
an unspecified value. */
static size_t
static size_t _GL_ATTRIBUTE_CONST
ceil_lg (size_t n)
{
size_t b = 0;
+1 -1
View File
@@ -1,4 +1,4 @@
#include "randint.h"
#include <stddef.h>
size_t randperm_bound (size_t, size_t);
size_t randperm_bound (size_t, size_t) _GL_ATTRIBUTE_CONST;
size_t *randperm_new (struct randint_source *, size_t, size_t);
+1 -1
View File
@@ -22,7 +22,7 @@ index 2da5afe..562955a 100644
}
#endif /* _LIBC */
+static inline bool
+static inline bool _GL_ATTRIBUTE_PURE
+check_x_suffix (char const *s, size_t len)
+{
+ return len <= strspn (s, "X");
+2 -2
View File
@@ -71,7 +71,7 @@
if digit return -1, else 0
return 0 */
static inline int
static inline int _GL_ATTRIBUTE_PURE
fraccompare (char const *a, char const *b, char decimal_point)
{
if (*a == decimal_point && *b == decimal_point)
@@ -111,7 +111,7 @@ fraccompare (char const *a, char const *b, char decimal_point)
causes comparisons to act as if there is no decimal point
character, and likewise for THOUSANDS_SEP. */
static inline int
static inline int _GL_ATTRIBUTE_PURE
numcompare (char const *a, char const *b,
int decimal_point, int thousands_sep)
{
+1 -1
View File
@@ -23,7 +23,7 @@
/* Externally-visible name for numcompare. */
int
int _GL_ATTRIBUTE_PURE
strnumcmp (char const *a, char const *b,
int decimal_point, int thousands_sep)
{
+1 -1
View File
@@ -1,2 +1,2 @@
int strintcmp (char const *, char const *);
int strintcmp (char const *, char const *) _GL_ATTRIBUTE_PURE;
int strnumcmp (char const *, char const *, int, int);
+2 -1
View File
@@ -6,4 +6,5 @@ xfts_open (char * const *, int options,
int (*) (const FTSENT **, const FTSENT **));
bool
cycle_warning_required (FTS const *fts, FTSENT const *ent);
cycle_warning_required (FTS const *fts, FTSENT const *ent)
_GL_ATTRIBUTE_PURE;
+2 -2
View File
@@ -68,13 +68,13 @@ struct Chown_option
void
chopt_init (struct Chown_option *);
void
void _GL_ATTRIBUTE_PURE _GL_ATTRIBUTE_CONST
chopt_free (struct Chown_option *);
char *
gid_to_name (gid_t);
char *
char * _GL_ATTRIBUTE_PURE
uid_to_name (uid_t);
bool
+2 -2
View File
@@ -468,7 +468,7 @@ extent_copy (int src_fd, int dest_fd, char *buf, size_t buf_size,
performance hit that's probably noticeable only on trees deeper
than a few hundred levels. See use of active_dir_map in remove.c */
static bool
static bool _GL_ATTRIBUTE_PURE
is_ancestor (const struct stat *sb, const struct dir_list *ancestors)
{
while (ancestors != 0)
@@ -2535,7 +2535,7 @@ un_backup:
return false;
}
static bool
static bool _GL_ATTRIBUTE_PURE
valid_options (const struct cp_options *co)
{
assert (co != NULL);
+1 -1
View File
@@ -282,7 +282,7 @@ void dest_info_init (struct cp_options *);
void src_info_init (struct cp_options *);
void cp_options_default (struct cp_options *);
bool chown_failure_ok (struct cp_options const *);
bool chown_failure_ok (struct cp_options const *) _GL_ATTRIBUTE_PURE;
mode_t cached_umask (void);
#endif
+2 -2
View File
@@ -1028,7 +1028,7 @@ write_output (void)
/* Return true if STR is of the form "PATTERN" or "PATTERNDELIM...". */
static bool
static bool _GL_ATTRIBUTE_PURE
operand_matches (char const *str, char const *pattern, char delim)
{
while (*pattern)
@@ -1108,7 +1108,7 @@ parse_integer (const char *str, bool *invalid)
/* OPERAND is of the form "X=...". Return true if X is NAME. */
static bool
static bool _GL_ATTRIBUTE_PURE
operand_is (char const *operand, char const *name)
{
return operand_matches (operand, name, '=');
+2 -2
View File
@@ -321,7 +321,7 @@ get_header (void)
/* Is FSTYPE a type of file system that should be listed? */
static bool
static bool _GL_ATTRIBUTE_PURE
selected_fstype (const char *fstype)
{
const struct fs_type_list *fsp;
@@ -336,7 +336,7 @@ selected_fstype (const char *fstype)
/* Is FSTYPE a type of file system that should be omitted? */
static bool
static bool _GL_ATTRIBUTE_PURE
excluded_fstype (const char *fstype)
{
const struct fs_type_list *fsp;
+2 -2
View File
@@ -393,7 +393,7 @@ printv (VALUE *v)
/* Return true if V is a null-string or zero-number. */
static bool
static bool _GL_ATTRIBUTE_PURE
null (VALUE *v)
{
switch (v->type)
@@ -424,7 +424,7 @@ null (VALUE *v)
/* Return true if CP takes the form of an integer. */
static bool
static bool _GL_ATTRIBUTE_PURE
looks_like_integer (char const *cp)
{
cp += (*cp == '-');
+1 -1
View File
@@ -355,7 +355,7 @@ split_3 (char *s, size_t s_len,
/* Return true if S is a NUL-terminated string of DIGEST_HEX_BYTES hex digits.
Otherwise, return false. */
static bool
static bool _GL_ATTRIBUTE_PURE
hex_digits (unsigned char const *s)
{
unsigned int i;
+1 -1
View File
@@ -1257,7 +1257,7 @@ read_block (size_t n, char *block, size_t *n_bytes_in_buffer)
/* Return the least common multiple of the sizes associated
with the format specs. */
static int
static int _GL_ATTRIBUTE_PURE
get_lcm (void)
{
size_t i;
+2 -2
View File
@@ -211,7 +211,7 @@ portable_chars_only (char const *file, size_t filelen)
/* Return the address of the start of the next file name component in F. */
static char *
static char * _GL_ATTRIBUTE_PURE
component_start (char *f)
{
while (*f == '/')
@@ -221,7 +221,7 @@ component_start (char *f)
/* Return the size of the file name component F. F must be nonempty. */
static size_t
static size_t _GL_ATTRIBUTE_PURE
component_len (char const *f)
{
size_t len;
+1 -1
View File
@@ -82,7 +82,7 @@ static struct option const longopts[] =
/* Count and return the number of ampersands in STR. */
static size_t
static size_t _GL_ATTRIBUTE_PURE
count_ampersands (const char *str)
{
size_t count = 0;
+1 -1
View File
@@ -773,7 +773,7 @@ static struct option const long_options[] =
/* Return the number of columns that have either an open file or
stored lines. */
static int
static int _GL_ATTRIBUTE_PURE
cols_ready_to_print (void)
{
COLUMN *q;
+1 -1
View File
@@ -595,7 +595,7 @@ compare_occurs (const void *void_first, const void *void_second)
| Return !0 if WORD appears in TABLE. Uses a binary search. |
`------------------------------------------------------------*/
static int
static int _GL_ATTRIBUTE_PURE
search_table (WORD *word, WORD_TABLE *table)
{
int lowest; /* current lowest possible index */
+1 -1
View File
@@ -1846,7 +1846,7 @@ static char const unit_order[UCHAR_LIM] =
separators and a decimal point, but it may not contain leading blanks.
Negative numbers get negative orders; zero numbers have a zero order. */
static int
static int _GL_ATTRIBUTE_PURE
find_unit_order (char const *number)
{
bool minus_sign = (*number == '-');
+3 -3
View File
@@ -1428,7 +1428,7 @@ screen_columns (void)
}
}
static tcflag_t *
static tcflag_t * _GL_ATTRIBUTE_PURE
mode_type_flag (enum mode_type type, struct termios *mode)
{
switch (type)
@@ -1789,7 +1789,7 @@ static struct speed_map const speeds[] =
{NULL, 0, 0}
};
static speed_t
static speed_t _GL_ATTRIBUTE_PURE
string_to_baud (const char *arg)
{
int i;
@@ -1800,7 +1800,7 @@ string_to_baud (const char *arg)
return (speed_t) -1;
}
static unsigned long int
static unsigned long int _GL_ATTRIBUTE_PURE
baud_to_value (speed_t speed)
{
int i;
+2 -2
View File
@@ -439,7 +439,7 @@ enum
/* Compute the greatest common divisor of U and V using Euclid's
algorithm. U and V must be nonzero. */
static inline size_t
static inline size_t _GL_ATTRIBUTE_CONST
gcd (size_t u, size_t v)
{
do
@@ -457,7 +457,7 @@ gcd (size_t u, size_t v)
nonzero. There is no overflow checking, so callers should not
specify outlandish sizes. */
static inline size_t
static inline size_t _GL_ATTRIBUTE_CONST
lcm (size_t u, size_t v)
{
return u * (v / gcd (u, v));
+3 -3
View File
@@ -364,7 +364,7 @@ is_equiv_class_member (unsigned char equiv_class, unsigned char c)
/* Return true if the character C is a member of the
character class CHAR_CLASS. */
static bool
static bool _GL_ATTRIBUTE_PURE
is_char_class_member (enum Char_class char_class, unsigned char c)
{
int result;
@@ -542,7 +542,7 @@ unquote (char const *s, struct E_string *es)
/* If CLASS_STR is a valid character class string, return its index
in the global char_class_name array. Otherwise, return CC_NO_CLASS. */
static enum Char_class
static enum Char_class _GL_ATTRIBUTE_PURE
look_up_char_class (char const *class_str, size_t len)
{
enum Char_class i;
@@ -844,7 +844,7 @@ find_bracketed_repeat (const struct E_string *es, size_t start_idx,
expression `\*[0-9]*\]', false otherwise. The string does not
match if any of its characters are escaped. */
static bool
static bool _GL_ATTRIBUTE_PURE
star_digits_closebracket (const struct E_string *es, size_t idx)
{
size_t i;
+1 -1
View File
@@ -206,7 +206,7 @@ size_opt (char const *opt, char const *msgid)
/* Given a linebuffer LINE,
return a pointer to the beginning of the line's field to be compared. */
static char *
static char * _GL_ATTRIBUTE_PURE
find_field (struct linebuffer const *line)
{
size_t count;
+1 -1
View File
@@ -556,7 +556,7 @@ get_input_fstatus (int nfiles, char *const *file)
recorded in FSTATUS. Optimize the same special case that
get_input_fstatus optimizes. */
static int
static int _GL_ATTRIBUTE_PURE
compute_number_width (int nfiles, struct fstatus const *fstatus)
{
int width = 1;