bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] mark functions with const and pure attributes


From: Jim Meyering
Subject: [PATCH] mark functions with const and pure attributes
Date: Sun, 27 Nov 2011 20:16:48 +0100

I began this months ago and then forgot about it.
Luckily I'd marked a change in coreutils' configure.ac with FIXME, and
that served as a reminder.  I have just gone back to finish the job.
This change adds the attributes only to those functions that are
compiled via coreutils.  There are certainly many more.

With the gnulib change below, I will be able to apply
the following change in coreutils that makes it use
-Wsuggest-attribute=pure|const also in lib/:

>From 1862d03dc1a0f2fe74f8dca15ca37342c1d06747 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Sun, 27 Nov 2011 16:13:26 +0100
Subject: [PATCH] build: enable -Wsuggest-attribute=pure|const in lib/,...

but not in gnulib-tests/.
* configure.ac (GNULIB_WARN_CFLAGS): Do not exclude
-Wsuggest-attribute=pure|const, thus enabling these two warning
options in lib/, since gnulib now toes the line.
Continue to disable them in gnulib-tests/, since some programs
there trigger these suggestions and are not worth fixing.
---
 configure.ac |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/configure.ac b/configure.ac
index a174178..8c4fff4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -156,15 +156,15 @@ if test "$gl_gcc_warnings" = yes; then
   # FIXME: it may be easy to remove this, since it affects only one file:
   # the snprintf call at ftoastr.c:132.
   nw="$nw -Wdouble-promotion"
-  # 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])

   # For gnulib-tests, the set is slightly smaller still.
   nw=
   nw="$nw -Wstrict-prototypes"
+  # It's not worth being this picky about test programs.
+  nw="$nw -Wsuggest-attribute=const"
+  nw="$nw -Wsuggest-attribute=pure"
   gl_MANYWARN_COMPLEMENT([GNULIB_TEST_WARN_CFLAGS],
                          [$GNULIB_WARN_CFLAGS], [$nw])
   AC_SUBST([GNULIB_TEST_WARN_CFLAGS])
--
1.7.8.rc3.31.g017d1



>From 29e5474139c53b0507035fc4dd34645145f3d396 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
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 and applying
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.
---
 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         |    7 +++++-
 lib/sockets.h          |   13 ++++++++++-
 lib/strnlen1.h         |    3 +-
 lib/uniwidth.in.h      |    2 +-
 30 files changed, 131 insertions(+), 60 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 9623f17..9c1cfdc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,53 @@
+2011-11-27  Jim Meyering  <address@hidden>
+
+       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 and applying
+       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-25  Jim Meyering  <address@hidden>

        test-update-copyright.sh: avoid false-positive failure
diff --git a/lib/argmatch.h b/lib/argmatch.h
index f87729d..b1a1193 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 9f76f28..73db77d 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 98f962f..1d65edc 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 ed8859e..078bd9a 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 66a5492..df2f070 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 96b750c..af41b12 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 2ef9882..ba9c56e 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 0a314a9..63e94d3 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 0d1b9a4..d7c66e9 100644
--- a/lib/file-type.h
+++ b/lib/file-type.h
@@ -24,6 +24,6 @@
 # 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 */
diff --git a/lib/filenamecat-lgpl.c b/lib/filenamecat-lgpl.c
index 8cb2da4..26d1c73 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 f6ed248..fd9e9f4 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 af03b89..0ddb826 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 f61a91e..ccd1980 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 80c1838..36b776a 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 51863c9..0658d81 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 9f2d075..a0e6416 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 572032d..541abc4 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 f0700b6..ae81f68 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 1d0754c..db0c685 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 eadb489..6b5966a 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 d2e14ac..502b856 100644
--- a/lib/memcasecmp.h
+++ b/lib/memcasecmp.h
@@ -19,4 +19,4 @@

 #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;
diff --git a/lib/memchr2.h b/lib/memchr2.h
index e575223..c34acbd 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 cbe6e8c..21552b2 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 d99c955..5621adc 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 d2a1e3b..a4eac01 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 da8ba1e..d3cd643 100644
--- a/lib/quotearg.c
+++ b/lib/quotearg.c
@@ -17,6 +17,11 @@

 /* Written by Paul Eggert <address@hidden> */

+/* Without this pragma, gcc 4.7.0 20111124 mistakenly suggests that
+   the quoting_options_from_style function might be candidate for
+   attribute 'pure'  */
+# pragma GCC diagnostic ignored "-Wsuggest-attribute=pure"
+
 #include <config.h>

 #include "quotearg.h"
@@ -165,7 +170,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 323f68c..68bf731 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 1bb13de..a0634fe 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 be99b97..12b04ab 100644
--- a/lib/uniwidth.in.h
+++ b/lib/uniwidth.in.h
@@ -38,7 +38,7 @@ 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) _GL_ATTRIBUTE_PURE;

 /* Determine number of column positions required for first N units
    (or fewer if S ends before this) in S.  */
--
1.7.8.rc3.31.g017d1



reply via email to

[Prev in Thread] Current Thread [Next in Thread]