]> git.ipfire.org Git - thirdparty/make.git/commitdiff
[SV 65777] Add more const
authorDan D <bulk88@hotmail.com>
Mon, 2 Sep 2024 13:54:17 +0000 (09:54 -0400)
committerPaul Smith <psmith@gnu.org>
Mon, 2 Sep 2024 17:48:30 +0000 (13:48 -0400)
Add more const to static arrays.  On some systems this allows more
data to be placed in RO segments and shared between multiple
instances of the make executable.  Anyway more const is good hygiene.

* src/default.c: Add const to arrays.
* src/function.c: Ditto.
* src/hash.c: Ditto.
* src/hash.h: Ditto.
* src/job.c: Ditto.
* src/read.c: Ditto.
* src/remake.c: Ditto.
* src/rule.c: Ditto.
* src/rule.h: Ditto.

src/default.c
src/function.c
src/hash.c
src/hash.h
src/job.c
src/read.c
src/remake.c
src/rule.c
src/rule.h

index 89939c157687b0c3fc46fd9d4d5d41fbc7d76ec0..c731817e19e94dcfa50fa0ade27496977288af04 100644 (file)
@@ -36,7 +36,7 @@ this program.  If not, see <https://www.gnu.org/licenses/>.  */
    '.s' must come last, so that a '.o' file will be made from
    a '.c' or '.p' or ... file rather than from a .s file.  */
 
-static char default_suffixes[]
+static const char default_suffixes[]
 #if MK_OS_VMS
   /* VMS should include all UNIX/POSIX + some VMS extensions */
   = ".out .exe .a .olb .hlb .tlb .mlb .ln .o .obj .c .cxx .cc .cpp .pas .p \
@@ -53,7 +53,7 @@ static char default_suffixes[]
 .w .ch .web .sh .elc .el";
 #endif
 
-static struct pspec default_pattern_rules[] =
+static const struct pspec default_pattern_rules[] =
   {
 #if MK_OS_VMS
     { "(%)", "%",
@@ -93,7 +93,7 @@ static struct pspec default_pattern_rules[] =
     { 0, 0, 0 }
   };
 
-static struct pspec default_terminal_rules[] =
+static const struct pspec default_terminal_rules[] =
   {
 #if MK_OS_VMS
 
@@ -128,7 +128,7 @@ static struct pspec default_terminal_rules[] =
     { 0, 0, 0 }
   };
 
-static const char *default_suffix_rules[] =
+static const char *const default_suffix_rules[] =
   {
 #if MK_OS_VMS
     ".o",
@@ -398,7 +398,7 @@ static const char *default_suffix_rules[] =
     0, 0,
   };
 
-static const char *default_variables[] =
+static const char *const default_variables[] =
   {
 #if MK_OS_VMS
 #ifdef __ALPHA
@@ -707,7 +707,7 @@ set_default_suffixes (void)
 void
 install_default_suffix_rules ()
 {
-  const char **s;
+  const char *const *s;
 
   if (no_builtin_rules_flag)
     return;
@@ -734,7 +734,7 @@ install_default_suffix_rules ()
 void
 install_default_implicit_rules (void)
 {
-  struct pspec *p;
+  const struct pspec *p;
 
   if (no_builtin_rules_flag)
     return;
@@ -749,7 +749,7 @@ install_default_implicit_rules (void)
 void
 define_default_variables (void)
 {
-  const char **s;
+  const char *const *s;
 
   if (no_builtin_variables_flag)
     return;
@@ -761,7 +761,7 @@ define_default_variables (void)
 void
 undefine_default_variables (void)
 {
-  const char **s;
+  const char *const *s;
 
   for (s = default_variables; *s != 0; s += 2)
     undefine_variable_global (NILF, s[0], strlen (s[0]), o_default);
index 82a9fe26c773975887231c7c28699f88c4e4aa02..b88ea184477dcea5f722dcd72b170aaa4c5e7411 100644 (file)
@@ -2392,7 +2392,7 @@ static char *func_call (char *o, char **argv, const char *funcname);
 #define FT_ENTRY(_name, _min, _max, _exp, _func) \
   { { (_func) }, STRING_SIZE_TUPLE(_name), (_min), (_max), (_exp), 0, 0 }
 
-static struct function_table_entry function_table_init[] =
+static const struct function_table_entry function_table_init[] =
 {
  /*         Name            MIN MAX EXP? Function */
   FT_ENTRY ("abspath",       0,  1,  1,  func_abspath),
index d1652f84b4e73c8026af4be18fa7433d6d73e4d1..41e16895d0674249d29c42ac562aae7146b1fbb7 100644 (file)
@@ -33,7 +33,7 @@ static unsigned long round_up_2 __P((unsigned long rough));
    potentially hit every slot in the table during collision
    resolution.  */
 
-void *hash_deleted_item = &hash_deleted_item;
+const void *hash_deleted_item = &hash_deleted_item;
 
 /* Force the table size to be a power of two, possibly rounding up the
    given size.  */
@@ -65,10 +65,10 @@ hash_init (struct hash_table *ht, unsigned long size,
 /* Load an array of items into 'ht'.  */
 
 void
-hash_load (struct hash_table *ht, void *item_table,
+hash_load (struct hash_table *ht, const void *item_table,
            unsigned long cardinality, unsigned long size)
 {
-  char *items = (char *) item_table;
+  const char *items = (const char *) item_table;
   while (cardinality--)
     {
       hash_insert (ht, items);
index 56f9a90b722dacf8aafb13636603bda989e42df1..1bbda0f7d9cf48caa0fce5bc0ebaacd107df2cee 100644 (file)
@@ -57,7 +57,7 @@ typedef int (*qsort_cmp_t) __P((void const *, void const *));
 
 void hash_init __P((struct hash_table *ht, unsigned long size,
                     hash_func_t hash_1, hash_func_t hash_2, hash_cmp_func_t hash_cmp));
-void hash_load __P((struct hash_table *ht, void *item_table,
+void hash_load __P((struct hash_table *ht, const void *item_table,
                     unsigned long cardinality, unsigned long size));
 void **hash_find_slot __P((struct hash_table *ht, void const *key));
 void *hash_find_item __P((struct hash_table *ht, void const *key));
@@ -76,7 +76,7 @@ void **hash_dump __P((struct hash_table *ht, void **vector_0, qsort_cmp_t compar
 extern unsigned jhash(unsigned char const *key, int n);
 extern unsigned jhash_string(unsigned char const *key);
 
-extern void *hash_deleted_item;
+extern const void *hash_deleted_item;
 #define HASH_VACANT(item) ((item) == 0 || (void *) (item) == hash_deleted_item)
 
 \f
index db741fc055baf7f30dc61025e3dfb93113ab617c..27fc764026eab2285cd439ae555130e5345175bc 100644 (file)
--- a/src/job.c
+++ b/src/job.c
@@ -2727,50 +2727,50 @@ construct_command_argv_internal (char *line, char **restp, const char *shell,
        DOS_CHARS also include characters special to 4DOS/NDOS, so we
        won't have to tell one from another and have one more set of
        commands and special characters.  */
-  static const char *sh_chars_dos = "*?[];|<>%^&()";
-  static const char *sh_cmds_dos[] =
+  static const char *const sh_chars_dos = "*?[];|<>%^&()";
+  static const char *const sh_cmds_dos[] =
     { "break", "call", "cd", "chcp", "chdir", "cls", "copy", "ctty", "date",
       "del", "dir", "echo", "erase", "exit", "for", "goto", "if", "md",
       "mkdir", "path", "pause", "prompt", "rd", "rmdir", "rem", "ren",
       "rename", "set", "shift", "time", "type", "ver", "verify", "vol", ":",
       0 };
 
-  static const char *sh_chars_sh = "#;\"*?[]&|<>(){}$`^";
-  static const char *sh_cmds_sh[] =
+  static const char *const sh_chars_sh = "#;\"*?[]&|<>(){}$`^";
+  static const char *const sh_cmds_sh[] =
     { "cd", "echo", "eval", "exec", "exit", "login", "logout", "set", "umask",
       "wait", "while", "for", "case", "if", ":", ".", "break", "continue",
       "export", "read", "readonly", "shift", "times", "trap", "switch",
       "unset", "ulimit", "command", 0 };
 
   const char *sh_chars;
-  const char **sh_cmds;
+  const char *const *sh_cmds;
 
 #elif MK_OS_OS2
-  static const char *sh_chars_dos = "*?[];|<>%^&()";
-  static const char *sh_cmds_dos[] =
+  static const char *const sh_chars_dos = "*?[];|<>%^&()";
+  static const char *const sh_cmds_dos[] =
     { "break", "call", "cd", "chcp", "chdir", "cls", "copy", "ctty", "date",
       "del", "dir", "echo", "erase", "exit", "for", "goto", "if", "md",
       "mkdir", "path", "pause", "prompt", "rd", "rmdir", "rem", "ren",
       "rename", "set", "shift", "time", "type", "ver", "verify", "vol", ":",
       0 };
 
-  static const char *sh_chars_os2 = "*?[];|<>%^()\"'&";
-  static const char *sh_cmds_os2[] =
+  static const char *const sh_chars_os2 = "*?[];|<>%^()\"'&";
+  static const char *const sh_cmds_os2[] =
     { "call", "cd", "chcp", "chdir", "cls", "copy", "date", "del", "detach",
       "dir", "echo", "endlocal", "erase", "exit", "for", "goto", "if", "keys",
       "md", "mkdir", "move", "path", "pause", "prompt", "rd", "rem", "ren",
       "rename", "rmdir", "set", "setlocal", "shift", "start", "time", "type",
       "ver", "verify", "vol", ":", 0 };
 
-  static const char *sh_chars_sh = "#;\"*?[]&|<>(){}$`^~'";
-  static const char *sh_cmds_sh[] =
+  static const char *const sh_chars_sh = "#;\"*?[]&|<>(){}$`^~'";
+  static const char *const sh_cmds_sh[] =
     { "echo", "cd", "eval", "exec", "exit", "login", "logout", "set", "umask",
       "wait", "while", "for", "case", "if", ":", ".", "break", "continue",
       "export", "read", "readonly", "shift", "times", "trap", "switch",
       "unset", "command", 0 };
 
   const char *sh_chars;
-  const char **sh_cmds;
+  const char *const *sh_cmds;
 
 #elif MK_OS_W32
   /* We used to have a double quote (") in sh_chars_dos[] below, but
@@ -2780,17 +2780,17 @@ construct_command_argv_internal (char *line, char **restp, const char *shell,
      can handle quoted file names just fine, removing the quote lifts
      the limit from a very frequent use case, because using quoted
      file names is commonplace on MS-Windows.  */
-  static const char *sh_chars_dos = "|&<>";
-  static const char *sh_cmds_dos[] =
+  static const char *const sh_chars_dos = "|&<>";
+  static const char *const sh_cmds_dos[] =
     { "assoc", "break", "call", "cd", "chcp", "chdir", "cls", "color", "copy",
       "ctty", "date", "del", "dir", "echo", "echo.", "endlocal", "erase",
-      "exit", "for", "ftype", "goto", "if", "if", "md", "mkdir", "move",
+      "exit", "for", "ftype", "goto", "if", "md", "mkdir", "move",
       "path", "pause", "prompt", "rd", "rem", "ren", "rename", "rmdir",
       "set", "setlocal", "shift", "time", "title", "type", "ver", "verify",
       "vol", ":", 0 };
 
-  static const char *sh_chars_sh = "#;\"*?[]&|<>(){}$`^";
-  static const char *sh_cmds_sh[] =
+  static const char *const sh_chars_sh = "#;\"*?[]&|<>(){}$`^";
+  static const char *const sh_cmds_sh[] =
     { "cd", "eval", "exec", "exit", "login", "logout", "set", "umask", "wait",
       "while", "for", "case", "if", ":", ".", "break", "continue", "export",
       "read", "readonly", "shift", "times", "trap", "switch", "test", "command",
@@ -2800,13 +2800,13 @@ construct_command_argv_internal (char *line, char **restp, const char *shell,
       0 };
 
   const char *sh_chars;
-  const char **sh_cmds;
+  const char *const *sh_cmds;
 #elif defined(__riscos__)
-  static const char *sh_chars = "";
-  static const char *sh_cmds[] = { 0 };
+  static const char *const sh_chars = "";
+  static const char *const sh_cmds[] = { 0 };
 #else  /* must be UNIX-ish */
-  static const char *sh_chars = "#;\"*?[]&|<>(){}$`^~!";
-  static const char *sh_cmds[] =
+  static const char *const sh_chars = "#;\"*?[]&|<>(){}$`^~!";
+  static const char *const sh_cmds[] =
     { ".", ":", "alias", "bg", "break", "case", "cd", "command", "continue",
       "eval", "exec", "exit", "export", "fc", "fg", "for", "getopts", "hash",
       "if", "jobs", "login", "logout", "read", "readonly", "return", "set",
@@ -2818,7 +2818,7 @@ construct_command_argv_internal (char *line, char **restp, const char *shell,
      MK_OS_W32) are compiled with HAVE_DOS_PATHS defined, which uses
      sh_chars_sh directly (see below).  The value must be identical
      to that of sh_chars immediately above.  */
-  static const char *sh_chars_sh =  "#;\"*?[]&|<>(){}$`^~!";
+  static const char *const sh_chars_sh =  "#;\"*?[]&|<>(){}$`^~!";
 # endif  /* HAVE_DOS_PATHS */
 #endif
   size_t i;
index 8a487a948783f22e8a5839afccabc4ad9349418e..f9b0dd7549dc9c224305071d8fa998b0dbad43ca 100644 (file)
@@ -96,7 +96,7 @@ static struct conditionals *conditionals = &toplevel_conditionals;
 
 /* Default directories to search for include files in  */
 
-static const char *default_include_directories[] =
+static const char *const default_include_directories[] =
   {
 #if MK_OS_W32 && !defined(INCLUDEDIR)
 /* This completely up to the user when they install MSVC or other packages.
@@ -222,7 +222,7 @@ read_all_makefiles (const char **makefiles)
 
   if (num_makefiles == 0)
     {
-      static const char *default_makefiles[] =
+      static const char *const default_makefiles[] =
 #if MK_OS_VMS
         /* all lower case since readdir() (the vms version) 'lowercasifies' */
         /* TODO: Above is not always true, this needs more work */
@@ -234,7 +234,7 @@ read_all_makefiles (const char **makefiles)
         { "GNUmakefile", "makefile", "Makefile", 0 };
 #endif /* !MK_OS_VMS && !MK_OS_W32 */
 #endif /* MK_OS_VMS */
-      const char **p = default_makefiles;
+      const char *const *p = default_makefiles;
       while (*p != 0 && !file_exists_p (*p))
         ++p;
 
@@ -2925,6 +2925,7 @@ construct_include_path (const char **arg_dirs)
   /* Now add the standard default dirs at the end.  */
   if (!disable)
     {
+      const char *const *ccpp;
 #if MK_OS_DOS
       /* The environment variable $DJDIR holds the root of the DJGPP directory
          tree; add ${DJDIR}/include.  */
@@ -2942,20 +2943,20 @@ construct_include_path (const char **arg_dirs)
             max_incl_len = len;
         }
 #endif
-      for (cpp = default_include_directories; *cpp != 0; ++cpp)
+      for (ccpp = default_include_directories; *ccpp != 0; ++ccpp)
         {
           int e;
 
-          EINTRLOOP (e, stat (*cpp, &stbuf));
+          EINTRLOOP (e, stat (*ccpp, &stbuf));
           if (e == 0 && S_ISDIR (stbuf.st_mode))
             {
-              size_t len = strlen (*cpp);
+              size_t len = strlen (*ccpp);
               /* If dir name is written with trailing slashes, discard them.  */
-              while (len > 1 && (*cpp)[len - 1] == '/')
+              while (len > 1 && (*ccpp)[len - 1] == '/')
                 --len;
               if (len > max_incl_len)
                 max_incl_len = len;
-              dirs[idx++] = strcache_add_len (*cpp, len);
+              dirs[idx++] = strcache_add_len (*ccpp, len);
             }
         }
     }
index 50d8f7ec72417e656e664dcb6edb87cf0086a041..9d7ae8fdbb5b30380911ed90182197e88f5c4af6 100644 (file)
@@ -1751,7 +1751,7 @@ name_mtime (const char *name)
 static const char *
 library_search (const char *lib, FILE_TIMESTAMP *mtime_ptr)
 {
-  static const char *dirs[] =
+  static const char *const dirs[] =
     {
       "/lib",
       "/usr/lib",
@@ -1779,7 +1779,7 @@ library_search (const char *lib, FILE_TIMESTAMP *mtime_ptr)
   /* Information about the earliest (in the vpath sequence) match.  */
   unsigned int best_vpath = 0, best_path = 0;
 
-  const char **dp;
+  const char *const *dp;
 
   libpatterns = allocated_expand_variable (STRING_SIZE_TUPLE (".LIBPATTERNS"));
 
index 8da27fcc28fd9e13193d828b06a2ccfcc303ebb7..d6bad4726fbd0b8258144f75df513aa697aa6423 100644 (file)
@@ -472,7 +472,7 @@ new_pattern_rule (struct rule *rule, int override)
    TERMINAL specifies what the 'terminal' field of the rule should be.  */
 
 void
-install_pattern_rule (struct pspec *p, int terminal)
+install_pattern_rule (const struct pspec *p, int terminal)
 {
   struct rule *r;
   const char *ptr;
index 8c29f89c37d30d2c0cb1502672d856d1660ffc0a..973f87497f4834e73ec37b283e51bf856897279e 100644 (file)
@@ -51,7 +51,7 @@ extern struct file *suffix_file;
 
 void snap_implicit_rules (void);
 void convert_to_pattern (void);
-void install_pattern_rule (struct pspec *p, int terminal);
+void install_pattern_rule (const struct pspec *p, int terminal);
 void create_pattern_rule (const char **targets, const char **target_percents,
                           unsigned short num, int terminal, struct dep *deps,
                           struct commands *commands, int override);