constification for lang_specific_driver
Zack Weinberg
zack@wolery.cumb.org
Wed Aug 2 13:21:00 GMT 2000
This patch eliminates the remaining warnings about losing const
qualifiers in gcc.c. It was necessary to change the interface to
lang_specific_driver. None of the foospec.c files actually modified
their arguments in place, and most of them get simpler with this
patch.
Bootstrapped i386-linux, applied.
Does anyone know why the second argument of execvp() is declared as
char * const *, instead of const char *const * ?
zw
* gcc.h (lang_specific_driver): Constify second argument.
* gcc.c (translate_options, process_command, main): Likewise.
Constify variables to match. Cast second argument to
pexecute.
* cppspec.c, gccspec.c, g++spec.c, g77spec.c, jvspec.c: Adjust
type of second argument to lang_specific_driver, and update
code as necessary.
===================================================================
Index: gcc.h
--- gcc.h 2000/02/15 16:36:32 1.2
+++ gcc.h 2000/08/02 20:12:48
@@ -34,7 +34,7 @@ extern void fatal PARAMS ((const char *,
/* Spec files linked with gcc.c must provide definitions for these. */
/* Called before processing to change/add/remove arguments. */
-extern void lang_specific_driver PARAMS ((int *, char ***, int *));
+extern void lang_specific_driver PARAMS ((int *, const char *const **, int *));
/* Called before linking. Returns 0 on success and -1 on failure. */
extern int lang_specific_pre_link PARAMS ((void));
===================================================================
Index: gcc.c
--- gcc.c 2000/07/31 18:29:56 1.156
+++ gcc.c 2000/08/02 20:12:49
@@ -210,7 +210,7 @@ static int access_check PARAMS ((const
static char *find_a_file PARAMS ((struct path_prefix *, const char *, int));
static void add_prefix PARAMS ((struct path_prefix *, const char *,
const char *, int, int, int *));
-static void translate_options PARAMS ((int *, const char ***));
+static void translate_options PARAMS ((int *, const char *const **));
static char *skip_whitespace PARAMS ((char *));
static void record_temp_file PARAMS ((const char *, int, int));
static void delete_if_ordinary PARAMS ((const char *));
@@ -242,7 +242,7 @@ static void display_help PARAMS ((void)
static void add_preprocessor_option PARAMS ((const char *, int));
static void add_assembler_option PARAMS ((const char *, int));
static void add_linker_option PARAMS ((const char *, int));
-static void process_command PARAMS ((int, const char **));
+static void process_command PARAMS ((int, const char *const *));
static int execute PARAMS ((void));
static void unused_prefix_warnings PARAMS ((struct path_prefix *));
static void clear_args PARAMS ((void));
@@ -854,11 +854,11 @@ struct option_map option_map[] =
static void
translate_options (argcp, argvp)
int *argcp;
- const char ***argvp;
+ const char *const **argvp;
{
int i;
int argc = *argcp;
- const char **argv = *argvp;
+ const char *const *argv = *argvp;
const char **newv =
(const char **) xmalloc ((argc + 2) * 2 * sizeof (const char *));
int newindex = 0;
@@ -2492,7 +2492,7 @@ execute ()
/* Print each piped command as a separate line. */
for (i = 0; i < n_commands ; i++)
{
- const char **j;
+ const char *const *j;
for (j = commands[i].argv; *j; j++)
fprintf (stderr, " %s", *j);
@@ -2523,7 +2523,9 @@ execute ()
char *errmsg_fmt, *errmsg_arg;
const char *string = commands[i].argv[0];
- commands[i].pid = pexecute (string, commands[i].argv,
+ /* For some bizarre reason, the second argument of execvp() is
+ char *const *, not const char *const *. */
+ commands[i].pid = pexecute (string, (char *const *) commands[i].argv,
programname, temp_filename,
&errmsg_fmt, &errmsg_arg,
((i == 0 ? PEXECUTE_FIRST : 0)
@@ -2860,7 +2862,7 @@ add_linker_option (option, len)
static void
process_command (argc, argv)
int argc;
- const char **argv;
+ const char *const *argv;
{
register int i;
const char *temp;
@@ -5088,12 +5090,12 @@ fatal_error (signum)
kill (getpid (), signum);
}
-extern int main PARAMS ((int, char **));
+extern int main PARAMS ((int, const char *const *));
int
main (argc, argv)
int argc;
- char **argv;
+ const char *const *argv;
{
size_t i;
int value;
@@ -5213,7 +5215,7 @@ main (argc, argv)
first_time = TRUE;
for (i = 0; (int)i < n_switches; i++)
{
- const char **args;
+ const char *const *args;
const char *p, *q;
if (!first_time)
obstack_grow (&collect_obstack, " ", 1);
===================================================================
Index: cppspec.c
--- cppspec.c 2000/08/02 07:08:49 1.10
+++ cppspec.c 2000/08/02 20:12:49
@@ -72,12 +72,12 @@ static const char *const known_suffixes[
void
lang_specific_driver (in_argc, in_argv, in_added_libraries)
int *in_argc;
- char ***in_argv;
+ const char *const **in_argv;
int *in_added_libraries ATTRIBUTE_UNUSED;
{
int argc = *in_argc;
- char **argv = *in_argv;
-
+ const char *const *argv = *in_argv;
+
/* Do we need to read stdin? */
int read_stdin = 1;
@@ -100,7 +100,6 @@ lang_specific_driver (in_argc, in_argv,
int need_fixups = 1;
int i, j, quote = 0;
- char **real_new_argv;
const char **new_argv;
int new_argc;
@@ -196,8 +195,7 @@ lang_specific_driver (in_argc, in_argv,
return;
/* One more slot for a terminating null. */
- real_new_argv = (char **) xmalloc ((new_argc + 1) * sizeof(char *));
- new_argv = (const char **) real_new_argv;
+ new_argv = (const char **) xmalloc ((new_argc + 1) * sizeof(char *));
new_argv[0] = argv[0];
j = 1;
@@ -225,7 +223,7 @@ lang_specific_driver (in_argc, in_argv,
new_argv[j] = NULL;
*in_argc = new_argc;
- *in_argv = real_new_argv;
+ *in_argv = new_argv;
}
/* Called before linking. Returns 0 on success and -1 on failure. */
===================================================================
Index: gccspec.c
--- gccspec.c 1999/09/13 03:57:37 1.3
+++ gccspec.c 2000/08/02 20:12:49
@@ -26,7 +26,7 @@ Boston, MA 02111-1307, USA. */
void
lang_specific_driver (in_argc, in_argv, in_added_libraries)
int *in_argc ATTRIBUTE_UNUSED;
- char ***in_argv ATTRIBUTE_UNUSED;
+ const char *const **in_argv ATTRIBUTE_UNUSED;
int *in_added_libraries ATTRIBUTE_UNUSED;
{
return; /* Not used for C. */
===================================================================
Index: cp/g++spec.c
--- cp/g++spec.c 2000/03/03 02:27:15 1.20
+++ cp/g++spec.c 2000/08/02 20:12:49
@@ -40,7 +40,7 @@ Boston, MA 02111-1307, USA. */
void
lang_specific_driver (in_argc, in_argv, in_added_libraries)
int *in_argc;
- char ***in_argv;
+ const char *const **in_argv;
int *in_added_libraries;
{
int i, j;
@@ -62,7 +62,6 @@ lang_specific_driver (in_argc, in_argv,
const char *quote = NULL;
/* The new argument list will be contained in this. */
- char **real_arglist;
const char **arglist;
/* Non-zero if we saw a `-xfoo' language specification on the
@@ -87,7 +86,7 @@ lang_specific_driver (in_argc, in_argv,
int argc;
/* The argument list. */
- char **argv;
+ const char *const *argv;
/* The number of libraries added in. */
int added_libraries;
@@ -203,14 +202,13 @@ lang_specific_driver (in_argc, in_argv,
/* Make sure to have room for the trailing NULL argument. */
num_args = argc + added + need_math + 1;
- real_arglist = (char **) xmalloc (num_args * sizeof (char *));
- arglist = (const char **) real_arglist;
+ arglist = (const char **) xmalloc (num_args * sizeof (char *));
i = 0;
j = 0;
/* Copy the 0th argument, i.e., the name of the program itself. */
- arglist[i++] = arglist[j++];
+ arglist[i++] = argv[j++];
#if ENABLE_NEW_GXX_ABI
/* If we should use the new ABI by default, add the appropriate flag
@@ -274,7 +272,7 @@ lang_specific_driver (in_argc, in_argv,
arglist[j] = NULL;
*in_argc = j;
- *in_argv = real_arglist;
+ *in_argv = arglist;
*in_added_libraries = added_libraries;
}
===================================================================
Index: f/g77spec.c
--- f/g77spec.c 2000/02/18 12:26:49 1.25
+++ f/g77spec.c 2000/08/02 20:12:49
@@ -86,14 +86,13 @@ typedef enum
/* The original argument list and related info is copied here. */
static int g77_xargc;
-static const char **g77_xargv;
+static const char *const *g77_xargv;
static void lookup_option PARAMS ((Option *, int *, const char **,
const char *));
static void append_arg PARAMS ((const char *));
/* The new argument list will be built here. */
static int g77_newargc;
-static char **real_g77_newargv;
static const char **g77_newargv;
/* --- This comes from gcc.c (2.8.1) verbatim: */
@@ -240,8 +239,7 @@ append_arg (arg)
int i;
newargsize = (g77_xargc << 2) + 20; /* This should handle all. */
- real_g77_newargv = (char **) xmalloc (newargsize * sizeof (char *));
- g77_newargv = (const char **) real_g77_newargv;
+ g77_newargv = (const char **) xmalloc (newargsize * sizeof (char *));
/* Copy what has been done so far. */
for (i = 0; i < g77_newargc; ++i)
@@ -257,11 +255,11 @@ append_arg (arg)
void
lang_specific_driver (in_argc, in_argv, in_added_libraries)
int *in_argc;
- char ***in_argv;
+ const char *const **in_argv;
int *in_added_libraries ATTRIBUTE_UNUSED;
{
int argc = *in_argc;
- const char **argv = (const char **) *in_argv;
+ const char *const *argv = *in_argv;
int i;
int verbose = 0;
Option opt;
@@ -302,12 +300,10 @@ lang_specific_driver (in_argc, in_argv,
fprintf (stderr, "\n");
#endif
- real_g77_newargv = *in_argv;
-
g77_xargc = argc;
g77_xargv = argv;
g77_newargc = 0;
- g77_newargv = argv;
+ g77_newargv = (const char **) argv;
/* First pass through arglist.
@@ -572,7 +568,7 @@ For bug reporting instructions, please s
}
*in_argc = g77_newargc;
- *in_argv = real_g77_newargv;
+ *in_argv = g77_newargv;
}
/* Called before linking. Returns 0 on success and -1 on failure. */
===================================================================
Index: java/jvspec.c
--- java/jvspec.c 2000/03/27 00:30:47 1.30
+++ java/jvspec.c 2000/08/02 20:12:50
@@ -93,7 +93,7 @@ find_spec_file (dir)
void
lang_specific_driver (in_argc, in_argv, in_added_libraries)
int *in_argc;
- char ***in_argv;
+ const char *const **in_argv;
int *in_added_libraries;
{
int i, j;
@@ -139,7 +139,6 @@ lang_specific_driver (in_argc, in_argv,
const char *quote = NULL;
/* The new argument list will be contained in this. */
- char **real_arglist;
const char **arglist;
/* Non-zero if we saw a `-xfoo' language specification on the
@@ -181,7 +180,7 @@ lang_specific_driver (in_argc, in_argv,
int argc;
/* The argument list. */
- char **argv;
+ const char *const *argv;
/* The number of libraries added in. */
int added_libraries;
@@ -392,9 +391,9 @@ lang_specific_driver (in_argc, in_argv,
if (saw_g + saw_O == 0)
num_args++;
num_args++;
- arglist = (const char **)
- (real_arglist = (char **) xmalloc ((num_args + 1) * sizeof (char *)));
+ arglist = (const char **) xmalloc ((num_args + 1) * sizeof (char *));
+
for (i = 0, j = 0; i < argc; i++, j++)
{
arglist[j] = argv[i];
@@ -488,7 +487,7 @@ lang_specific_driver (in_argc, in_argv,
arglist[j] = NULL;
*in_argc = j;
- *in_argv = real_arglist;
+ *in_argv = arglist;
*in_added_libraries = added_libraries;
}
More information about the Gcc-patches
mailing list