This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Patch installed for const-ification, & concat/xstrdup cleanup


A grab-bag of cleanups.

Note, I think the CROSS_COMPILE case for collect2.c has a minor memory
leak case (both before and after my patch) in that it doesn't free the
memory allocated by concat.  (This happens a lot all over gcc.)
Perhaps there's a way to allocate this memory from alloca?  Hmm...

Anyway, bootstrapped on sparc-sun-solaris2.7, no regressions.
Installed as obvious.

		--Kaveh


Index: ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/gcc/ChangeLog,v
retrieving revision 1.11340
diff -u -p -r1.11340 ChangeLog
--- ChangeLog	2001/09/15 11:51:23	1.11340
+++ ChangeLog	2001/09/15 14:00:25
@@ -1,3 +1,10 @@
+2001-09-15  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>
+
+	* collect2.c (main): Const-ification.
+	* gcc.c (translate_options, process_command): Use xstrdup in
+	lieu of xmalloc/strcpy.
+	(main): Use concat in lieu of xmalloc/strcpy/strcat.
+
 2001-09-14  Roman Lechtchinsky  <rl@cs.tu-berlin.de>
 
 	* doc/install.texi (Specific, alphaev5-cray-unicosmk*): Fix
Index: collect2.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/collect2.c,v
retrieving revision 1.118
diff -u -p -r1.118 collect2.c
--- collect2.c	2001/09/13 14:37:09	1.118
+++ collect2.c	2001/09/15 14:00:25
@@ -797,21 +797,47 @@ main (argc, argv)
      char *argv[];
 {
   static const char *const ld_suffix	= "ld";
-  const char *full_ld_suffix	= ld_suffix;
   static const char *const real_ld_suffix = "real-ld";
   static const char *const collect_ld_suffix = "collect-ld";
   static const char *const nm_suffix	= "nm";
-  const char *full_nm_suffix	= nm_suffix;
   static const char *const gnm_suffix	= "gnm";
-  const char *full_gnm_suffix	= gnm_suffix;
 #ifdef LDD_SUFFIX
   static const char *const ldd_suffix	= LDD_SUFFIX;
-  const char *full_ldd_suffix	= ldd_suffix;
 #endif
   static const char *const strip_suffix = "strip";
-  const char *full_strip_suffix = strip_suffix;
   static const char *const gstrip_suffix = "gstrip";
-  const char *full_gstrip_suffix = gstrip_suffix;
+
+#ifdef CROSS_COMPILE
+  /* If we look for a program in the compiler directories, we just use
+     the short name, since these directories are already system-specific.
+     But it we look for a program in the system directories, we need to
+     qualify the program name with the target machine.  */
+
+  const char *const full_ld_suffix =
+    concat(target_machine, "-", ld_suffix, NULL);
+  const char *const full_nm_suffix =
+    concat (target_machine, "-", nm_suffix, NULL);
+  const char *const full_gnm_suffix =
+    concat (target_machine, "-", gnm_suffix, NULL);
+#ifdef LDD_SUFFIX
+  const char *const full_ldd_suffix =
+    concat (target_machine, "-", ldd_suffix, NULL);
+#endif
+  const char *const full_strip_suffix =
+    concat (target_machine, "-", strip_suffix, NULL);
+  const char *const full_gstrip_suffix =
+    concat (target_machine, "-", gstrip_suffix, NULL);
+#else
+  const char *const full_ld_suffix	= ld_suffix;
+  const char *const full_nm_suffix	= nm_suffix;
+  const char *const full_gnm_suffix	= gnm_suffix;
+#ifdef LDD_SUFFIX
+  const char *const full_ldd_suffix	= ldd_suffix;
+#endif
+  const char *const full_strip_suffix	= strip_suffix;
+  const char *const full_gstrip_suffix	= gstrip_suffix;
+#endif /* CROSS_COMPILE */
+
   const char *arg;
   FILE *outf;
 #ifdef COLLECT_EXPORT_LIST
@@ -935,31 +961,6 @@ main (argc, argv)
   /* Extract COMPILER_PATH and PATH into our prefix list.  */
   prefix_from_env ("COMPILER_PATH", &cpath);
   prefix_from_env ("PATH", &path);
-
-#ifdef CROSS_COMPILE
-  /* If we look for a program in the compiler directories, we just use
-     the short name, since these directories are already system-specific.
-     But it we look for a program in the system directories, we need to
-     qualify the program name with the target machine.  */
-
-  full_ld_suffix = concat(target_machine, "-", ld_suffix, NULL);
-
-#if 0
-  full_gld_suffix = concat (target_machine, "-", gld_suffix, NULL);
-#endif
-
-  full_nm_suffix = concat (target_machine, "-", nm_suffix, NULL);
-
-  full_gnm_suffix = concat (target_machine, "-", gnm_suffix, NULL);
-  
-#ifdef LDD_SUFFIX
-  full_ldd_suffix = concat (target_machine, "-", ldd_suffix, NULL);
-#endif
-
-  full_strip_suffix = concat (target_machine, "-", strip_suffix, NULL);
-  
-  full_gstrip_suffix = concat (target_machine, "-", gstrip_suffix, NULL);
-#endif /* CROSS_COMPILE */
 
   /* Try to discover a valid linker/nm/strip to use.  */
 
Index: gcc.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/gcc.c,v
retrieving revision 1.250
diff -u -p -r1.250 gcc.c
--- gcc.c	2001/09/13 14:37:11	1.250
+++ gcc.c	2001/09/15 14:00:26
@@ -1011,8 +1011,7 @@ translate_options (argcp, argvp)
 	      newv = (const char **) xrealloc (newv, newvsize);
 
 	      sp = target_option_translations[tott_idx].replacements;
-	      np = (char *) xmalloc (strlen (sp) + 1);
-	      strcpy (np, sp);
+	      np = xstrdup (sp);
 
 	      while (1)
 		{
@@ -3910,15 +3909,13 @@ process_command (argc, argv)
 	      /* On some systems, ld cannot handle some options without
 		 a space.  So split the option from its argument.  */
 	      char *part1 = (char *) xmalloc (2);
-	      char *tmp;
 	      part1[0] = c;
 	      part1[1] = '\0';
 
 	      switches[n_switches].part1 = part1;
 	      switches[n_switches].args
 		= (const char **) xmalloc (2 * sizeof (const char *));
-	      switches[n_switches].args[0] = tmp = xmalloc (strlen (p));
-	      strcpy (tmp, &p[1]);
+	      switches[n_switches].args[0] = xstrdup (p+1);
 	      switches[n_switches].args[1] = 0;
 	    }
 	  else
@@ -5812,17 +5809,8 @@ main (argc, argv)
 
   /* If we have a GCC_EXEC_PREFIX envvar, modify it for cpp's sake.  */
   if (gcc_exec_prefix)
-    {
-      char *temp = (char *) xmalloc (strlen (gcc_exec_prefix)
-				     + strlen (spec_version)
-				     + strlen (spec_machine) + 3);
-      strcpy (temp, gcc_exec_prefix);
-      strcat (temp, spec_machine);
-      strcat (temp, dir_separator_str);
-      strcat (temp, spec_version);
-      strcat (temp, dir_separator_str);
-      gcc_exec_prefix = temp;
-    }
+    gcc_exec_prefix = concat (gcc_exec_prefix, spec_machine, dir_separator_str,
+			      spec_version, dir_separator_str, NULL);
 
   /* Now we have the specs.
      Set the `valid' bits for switches that match anything in any spec.  */
Index: cp/ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/ChangeLog,v
retrieving revision 1.2496
diff -u -p -r1.2496 ChangeLog
--- ChangeLog	2001/09/13 14:37:12	1.2496
+++ ChangeLog	2001/09/15 14:00:27
@@ -1,3 +1,8 @@
+2001-09-15  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>
+
+	* mangle.c (mangle_conv_op_name_for_type): Use concat in lieu of
+	xmalloc/strcpy/strcat.
+
 2001-09-13  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>
 
 	* decl.c (warn_extern_redeclared_static, cp_make_fname_decl):
Index: cp/mangle.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/mangle.c,v
retrieving revision 1.36
diff -u -p -r1.36 mangle.c
--- mangle.c	2001/07/25 15:04:30	1.36
+++ mangle.c	2001/09/15 14:00:28
@@ -2392,11 +2392,7 @@ mangle_conv_op_name_for_type (type)
   /* Build the mangling for TYPE.  */
   const char *mangled_type = mangle_type_string (type);
   /* Allocate a temporary buffer for the complete name.  */
-  char *op_name = (char *) xmalloc (strlen ("operator ") 
-				    + strlen (mangled_type) + 1);
-  /* Assemble the mangling.  */
-  strcpy (op_name, "operator ");
-  strcat (op_name, mangled_type);
+  char *op_name = concat ("operator ", mangled_type, NULL);
   /* Find or create an identifier.  */
   identifier = get_identifier (op_name);
   /* Done with the temporary buffer.  */


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]