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]
Other format: [Raw text]

[cs] patch to add '/' to include paths


I checked the attached patch into the compile-server branch.
It may be appropriate for mainline and/or the tree-ssa branch,
after some more testing.

The problem is that some struct file_hash_entry objects come
from various include paths, and some are constructed from
the directory of a file that contained the #include.  The
former generally don't include a final '/', while the latter
do include a final '/'.  The cache will more better and we'll
avoid some duplicates (which is more important for the compile
server) if we're consistent.
--
	--Per Bothner
per@bothner.com   http://per.bothner.com/


2003-12-08  Per Bothner  <pbothner@apple.com>

	* c-incpath.c (add_path):  Add final '/' if missing.
	(add_dup_path):  New function - optimized xstrdup + add_path.
	(add_env_var_paths):  Add final '/' after ".".
	* c-incpath.h (add_dup_path):  New declaration.
	* c-opts.c (c_common_handle_option):  Use add_dup_path.
	(add_prefixed_path):  Add final '/' if missing.
	* fix-header.c (read_scan_file):  Use add_dup_path.

Index: c-incpath.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-incpath.h,v
retrieving revision 1.3.4.1
diff -u -p -r1.3.4.1 c-incpath.h
--- c-incpath.h	29 Aug 2003 19:55:02 -0000	1.3.4.1
+++ c-incpath.h	8 Dec 2003 20:09:30 -0000
@@ -16,6 +16,7 @@ along with this program; if not, write t
 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 
 extern void split_quote_chain (void);
+extern void add_dup_path (const char *, int, int);
 extern void add_path (char *, int, int);
 extern void register_include_chains (cpp_reader *, const char *,
 				     const char *, int, int, int);
Index: c-incpath.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-incpath.c,v
retrieving revision 1.8.2.2
diff -u -p -r1.8.2.2 c-incpath.c
--- c-incpath.c	29 Aug 2003 19:55:02 -0000	1.8.2.2
+++ c-incpath.c	8 Dec 2003 20:09:30 -0000
@@ -106,7 +106,7 @@ add_env_var_paths (const char *env_var, 
 	q++;
 
       if (p == q)
-	path = xstrdup (".");
+	path = xstrdup ("./");
       else
 	{
 	  path = xmalloc (q - p + 1);
@@ -300,12 +300,35 @@ split_quote_chain (void)
   quote_ignores_source_dir = true;
 }
 
+/* Add PATH to the include chain CHAIN. PATH is copied. */
+
+void
+add_dup_path (const char *path, int chain, int cxx_aware)
+{
+  size_t len = strlen (path);
+  char *p;
+
+  if (len > 0 && path[len-1] != '/')
+    p = concat (path, "/", NULL);
+  else
+    p = xstrdup (path);
+  add_path (p, chain, cxx_aware);
+}
+
 /* Add PATH to the include chain CHAIN. PATH must be malloc-ed and
    NUL-terminated.  */
 void
 add_path (char *path, int chain, int cxx_aware)
 {
   cpp_dir *p;
+  size_t len = strlen (path);
+
+  if (len > 0 && path[len-1] != '/')
+    {
+      char *path_slash = concat (path, "/", NULL);
+      free (path);
+      path = path_slash;
+    }
 
   p = xmalloc (sizeof (cpp_dir));
   p->next = NULL;
Index: c-opts.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-opts.c,v
retrieving revision 1.79.2.12
diff -u -p -r1.79.2.12 c-opts.c
--- c-opts.c	1 Dec 2003 03:55:26 -0000	1.79.2.12
+++ c-opts.c	8 Dec 2003 20:09:30 -0000
@@ -291,7 +291,7 @@ c_common_handle_option (size_t scode, co
 
     case OPT_I:
       if (strcmp (arg, "-"))
-	add_path (xstrdup (arg), BRACKET, 0);
+	add_dup_path (arg, BRACKET, 0);
       else
 	{
 	  if (quote_chain_split)
@@ -927,7 +927,7 @@ c_common_handle_option (size_t scode, co
       break;
 
     case OPT_idirafter:
-      add_path (xstrdup (arg), AFTER, 0);
+      add_dup_path (arg, AFTER, 0);
       break;
 
     case OPT_imacros:
@@ -944,7 +944,7 @@ c_common_handle_option (size_t scode, co
       break;
 
     case OPT_isystem:
-      add_path (xstrdup (arg), SYSTEM, 0);
+      add_dup_path (arg, SYSTEM, 0);
       break;
 
     case OPT_iwithprefix:
@@ -1386,15 +1386,19 @@ add_prefixed_path (const char *suffix, s
   char *path;
   const char *prefix;
   size_t prefix_len, suffix_len;
+  int need_slash;
 
   suffix_len = strlen (suffix);
+  need_slash = suffix_len > 0 && suffix[suffix_len-1] != '/';
   prefix     = iprefix ? iprefix : cpp_GCC_INCLUDE_DIR;
   prefix_len = iprefix ? strlen (iprefix) : cpp_GCC_INCLUDE_DIR_len;
 
-  path = xmalloc (prefix_len + suffix_len + 1);
+  path = xmalloc (prefix_len + suffix_len + need_slash + 1);
   memcpy (path, prefix, prefix_len);
   memcpy (path + prefix_len, suffix, suffix_len);
-  path[prefix_len + suffix_len] = '\0';
+  if (need_slash)
+    path[prefix_len + suffix_len] = '/';
+  path[prefix_len + suffix_len + need_slash] = '\0';
 
   add_path (path, chain, 0);
 }
Index: fix-header.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fix-header.c,v
retrieving revision 1.100.2.4
diff -u -p -r1.100.2.4 fix-header.c
--- fix-header.c	18 Oct 2003 21:28:09 -0000	1.100.2.4
+++ fix-header.c	8 Dec 2003 20:09:31 -0000
@@ -628,12 +628,12 @@ read_scan_file (char *in_fname, int argc
 	      if (argv[i][2] != '\0')
 		{
 		  strings_processed = 1;
-		  add_path (xstrdup (argv[i] + 2), BRACKET, false);
+		  add_dup_path (argv[i] + 2, BRACKET, false);
 		}
 	      else if (i + 1 != argc)
 		{
 		  strings_processed = 2;
-		  add_path (xstrdup (argv[i + 1]), BRACKET, false);
+		  add_dup_path (argv[i + 1], BRACKET, false);
 		}
 	    }
 	  else if (argv[i][1] == 'D')

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