bug-idutils
[Top][All Lists]
Advanced

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

[bug-idutils] [PATCH 4/9] build: add const and pure attributes, per gcc


From: Jim Meyering
Subject: [bug-idutils] [PATCH 4/9] build: add const and pure attributes, per gcc recommendation
Date: Thu, 2 Feb 2012 08:38:43 +0100

From: Jim Meyering <address@hidden>

* src/mkid.c (ceil_log_8, ceil_log_2): Add "const" attribute.
(token_hash_1, token_hash_2): Add "pure" attribute.
(token_hash_cmp, token_qsort_cmp): Likewise.
(count_vec_size, count_buf_size): Likewise.

* libidu/idu-hash.c (round_up_2): Add "const" attribute.
* libidu/scanners.h (get_language): Add "pure" attribute.
* libidu/idfile.h (token_flags): Likewise.
(token_count): Likewise.
(member_file_qsort_compare): Likewise.
(tree8_count_levels): Add "const" attribute.
* libidu/walker.c (symlink_ancestry): Add "pure" attribute.
(links_depth): Likewise.
(file_link_hash_1): Likewise.
(vector_length): Likewise.
(file_link_hash_compare): Likewise.
(string_in_vector): Likewise.
* src/lid.c (vector_cardinality, get_radix, dtoi, otoi): Likewise.
(is_regexp): Likewise.
(vector_length): Remove forward decl and move function definition
to precede first use.
---
 libidu/idfile.h   |   14 ++++++++------
 libidu/idu-hash.c |    2 +-
 libidu/scanners.h |    3 ++-
 libidu/walker.c   |   29 ++++++++++++++---------------
 src/lid.c         |   14 +++++++-------
 src/mkid.c        |   16 ++++++++--------
 6 files changed, 40 insertions(+), 38 deletions(-)

diff --git a/libidu/idfile.h b/libidu/idfile.h
index fe531db..739819d 100644
--- a/libidu/idfile.h
+++ b/libidu/idfile.h
@@ -144,9 +144,10 @@ extern struct hash_table dev_ino_table;
 /* token flags (struct token is defined in scanners.h) */

 #define token_string(buf) (buf)
-extern unsigned int token_flags (char const *buf);
-extern unsigned short token_count (char const *buf);
-extern unsigned char const *token_hits_addr (char const *buf);
+extern unsigned int token_flags (char const *buf) _GL_ATTRIBUTE_PURE;
+extern unsigned short token_count (char const *buf) _GL_ATTRIBUTE_PURE;
+extern unsigned char const *token_hits_addr (char const *buf)
+  _GL_ATTRIBUTE_PURE;

 #define MAYBE_RETURN_PREFIX_MATCH(arg, str, val) do { \
     char const *_s_ = (str); \
@@ -187,7 +188,8 @@ extern struct file_link **deserialize_file_links (struct 
idhead *idhp);
 extern void serialize_file_links (struct idhead *idhp);

 extern void mark_member_file_links (struct idhead *idhp);
-extern int member_file_qsort_compare (void const *x, void const *y);
+extern int member_file_qsort_compare (void const *x, void const *y)
+  _GL_ATTRIBUTE_PURE;
 extern struct file_link *parse_file_name (char *file_name, struct file_link 
*relative_dir_link);
 extern void print_filenames (struct file_link **flinkv, enum separator_style 
separator_style);
 extern enum separator_style parse_separator_style (char const *arg);
@@ -202,11 +204,11 @@ extern char *absolute_file_name (char *buffer, struct 
file_link const *flink);
 extern char *maybe_relative_file_name (char *buffer, struct file_link const 
*to_link, struct file_link const *from_link);
 extern char const *locate_id_file_name (char const *arg);

-extern int tree8_count_levels (unsigned int cardinality);
+extern int tree8_count_levels (unsigned int cardinality) _GL_ATTRIBUTE_CONST;
 extern int gets_past_00 (char *tok, FILE *input_FILE);
 extern int skip_past_00 (FILE *input_FILE);

-extern int links_depth (struct file_link const *flink);
+extern int links_depth (struct file_link const *flink) _GL_ATTRIBUTE_PURE;

 #if HAVE_LINK

diff --git a/libidu/idu-hash.c b/libidu/idu-hash.c
index 58b6d3d..3d55c64 100644
--- a/libidu/idu-hash.c
+++ b/libidu/idu-hash.c
@@ -296,7 +296,7 @@ hash_dump (struct hash_table const *ht, void **vector_0, 
qsort_cmp_t compare)

 /* Round a given number up to the nearest power of 2. */

-static unsigned long
+static unsigned long _GL_ATTRIBUTE_CONST
 round_up_2 (unsigned long rough)
 {
   int round;
diff --git a/libidu/scanners.h b/libidu/scanners.h
index cc0dad0..b20ec3c 100644
--- a/libidu/scanners.h
+++ b/libidu/scanners.h
@@ -63,7 +63,8 @@ struct lang_args
 extern void language_help_me (void);
 extern void language_getopt (void);
 extern void language_save_arg (char *arg);
-extern struct language *get_language (char const *lang_name);
+extern struct language *get_language (char const *lang_name)
+  _GL_ATTRIBUTE_PURE;
 extern void parse_language_map (char const *file_name);
 extern void set_default_language (char const *lang_name);

diff --git a/libidu/walker.c b/libidu/walker.c
index 02e3d65..e268f35 100644
--- a/libidu/walker.c
+++ b/libidu/walker.c
@@ -59,7 +59,6 @@ static struct file_link *make_link_from_string (char const 
*name,
 static int lang_wanted (char const *lang_name);
 static char **append_strings_to_vector (char **vector_0, char *string,
                                        char const *delimiter_class);
-static int vector_length (char **vector);
 static int string_in_vector (char const *string, char **vector);
 static int same_as_dot (char const *cwd);
 static struct file_link const
@@ -365,7 +364,7 @@ find_alias_link (struct file_link *flink, struct stat *stp)
    directory.  PATH_MAX is considered an infinite distance (e.g.,
    there are no symlinks between `flink' and the root).  */

-static int
+static int _GL_ATTRIBUTE_PURE
 symlink_ancestry (struct file_link *flink)
 {
   int ancestry = 0;
@@ -506,6 +505,15 @@ exclude_languages (char *lang_names)
   langs_excluded = append_strings_to_vector (langs_excluded, lang_names, 
white_space);
 }

+static int _GL_ATTRIBUTE_PURE
+vector_length (char **vector)
+{
+  int length = 0;
+  while (*vector++)
+    length++;
+  return length;
+}
+
 static char **
 append_strings_to_vector (char **vector_0, char *string,
                          char const *delimiter_class)
@@ -527,16 +535,7 @@ append_strings_to_vector (char **vector_0, char *string,
   return xnrealloc (vector_0, vector - vector_0, sizeof *vector_0);
 }

-static int
-vector_length (char **vector)
-{
-  int length = 0;
-  while (*vector++)
-    length++;
-  return length;
-}
-
-static int
+static int _GL_ATTRIBUTE_PURE
 string_in_vector (char const *string, char **vector)
 {
   while (*vector)
@@ -1052,7 +1051,7 @@ member_file_qsort_compare (void const *x, void const *y)
 /****************************************************************************/
 /* Hash stuff for `struct file_link'.  */

-static unsigned long
+static unsigned long _GL_ATTRIBUTE_PURE
 file_link_hash_1 (void const *key)
 {
   unsigned long result = 0;
@@ -1063,7 +1062,7 @@ file_link_hash_1 (void const *key)
   return result;
 }

-static unsigned long
+static unsigned long _GL_ATTRIBUTE_PURE
 file_link_hash_2 (void const *key)
 {
   unsigned long result = 0;
@@ -1074,7 +1073,7 @@ file_link_hash_2 (void const *key)
   return result;
 }

-static int
+static int _GL_ATTRIBUTE_PURE
 file_link_hash_compare (void const *x, void const *y)
 {
   int result;
diff --git a/src/lid.c b/src/lid.c
index 9a5054b..cd307c0 100644
--- a/src/lid.c
+++ b/src/lid.c
@@ -810,7 +810,7 @@ report_nothing (char const *name, struct file_link **flinkv 
ATTRIBUTE_UNUSED)
     puts (name);
 }

-static int
+static int _GL_ATTRIBUTE_PURE
 vector_cardinality (void *vector)
 {
   void **v = (void **) vector;
@@ -1239,7 +1239,7 @@ query_binary_search (char const *token_0)

 /* Are there any regexp meta-characters in name?? */

-static int
+static int _GL_ATTRIBUTE_PURE
 is_regexp (char *name)
 {
   int backslash = 0;
@@ -1284,7 +1284,7 @@ has_right_delimiter (char const *pattern)

 /* Does `name' occur in `line' delimited by non-alphanumerics?? */

-static int
+static int _GL_ATTRIBUTE_PURE
 word_match (char const *name_0, char const *line)
 {
   char const *name = name_0;
@@ -1319,7 +1319,7 @@ word_match (char const *name_0, char const *line)
    apply.  In particular, it is impossible to determine the radix of
    0, so return all possibilities.  */

-static int
+static int _GL_ATTRIBUTE_PURE
 get_radix (char const *str)
 {
   if (!isdigit (*str))
@@ -1374,7 +1374,7 @@ stoi (char const *str)

 /* Convert an ascii octal number to an integer. */

-static int
+static int _GL_ATTRIBUTE_PURE
 otoi (char const *str)
 {
   int n = 0;
@@ -1391,7 +1391,7 @@ otoi (char const *str)

 /* Convert an ascii decimal number to an integer. */

-static int
+static int _GL_ATTRIBUTE_PURE
 dtoi (char const *str)
 {
   int n = 0;
@@ -1408,7 +1408,7 @@ dtoi (char const *str)

 /* Convert an ascii hex number to an integer. */

-static int
+static int _GL_ATTRIBUTE_PURE
 xtoi (char const *str)
 {
   int n = 0;
diff --git a/src/mkid.c b/src/mkid.c
index 821e8d3..082395e 100644
--- a/src/mkid.c
+++ b/src/mkid.c
@@ -443,7 +443,7 @@ main (int argc, char **argv)

 /* Return the integer ceiling of the base-8 logarithm of N.  */

-static int
+static int _GL_ATTRIBUTE_CONST
 ceil_log_8 (unsigned long n)
 {
   int log_8 = 0;
@@ -459,7 +459,7 @@ ceil_log_8 (unsigned long n)

 /* Return the integer ceiling of the base-2 logarithm of N.  */

-static int
+static int _GL_ATTRIBUTE_CONST
 ceil_log_2 (unsigned long n)
 {
   int log_2 = 0;
@@ -782,26 +782,26 @@ write_id_file (struct idhead *idhp)
 /* Define primary and secondary hash and comparison functions for the
    token table.  */

-static unsigned long
+static unsigned long _GL_ATTRIBUTE_PURE
 token_hash_1 (void const *key)
 {
   return_STRING_HASH_1 (TOKEN_NAME ((struct token const *) key));
 }

-static unsigned long
+static unsigned long _GL_ATTRIBUTE_PURE
 token_hash_2 (void const *key)
 {
   return_STRING_HASH_2 (TOKEN_NAME ((struct token const *) key));
 }

-static int
+static int _GL_ATTRIBUTE_PURE
 token_hash_cmp (void const *x, void const *y)
 {
   return_STRING_COMPARE (TOKEN_NAME ((struct token const *) x),
                         TOKEN_NAME ((struct token const *) y));
 }

-static int
+static int _GL_ATTRIBUTE_PURE
 token_qsort_cmp (void const *x, void const *y)
 {
   return_STRING_COMPARE (TOKEN_NAME (*(struct token const *const *) x),
@@ -938,7 +938,7 @@ make_sibling_summary (struct summary *summary)
   return summary;
 }

-static int
+static int _GL_ATTRIBUTE_PURE
 count_vec_size (struct summary *summary, unsigned char const *tail_hits)
 {
   struct summary **kids;
@@ -962,7 +962,7 @@ count_vec_size (struct summary *summary, unsigned char 
const *tail_hits)
     }
 }

-static int
+static int _GL_ATTRIBUTE_PURE
 count_buf_size (struct summary *summary, unsigned char const *tail_hits)
 {
   struct summary **kids;
-- 
1.7.9.49.g25388




reply via email to

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