[PATCH] Rename pwait for LynxOS

Adam Nemet anemet@lnxw.com
Tue Aug 24 19:35:00 GMT 2004


Zack, DJ,

On Tue, 17 Aug 2004 14:22:04 -0700, Zack Weinberg <zack@codesourcery.com> said:
> That suggests another potential fix, which is to change tlink.c to use
> pexecute instead of system, thus preventing libc's pwait from being
> dragged in.

Thanks for the idea.  The patch below replaces the call to system()
with tlink_execute(). 

I almost missed how gcc.c encodes quotes within arguments so I was
trying to add this testcase:

  // { dg-options "-frepo -DF='a'" } 
   
  template <typename A, typename B> void f () {} 
  template <typename A, typename B> void g () { f<int,int>(); } 
  int main () { g<int,int>(); } 
   
  char c = F; 

But for some reason, dg fails to find -frepo in dg-options and the
testcase fails.  The same testcase works if I run it manually.  Has
anybody encountered this?  I will look into it more and then post the
testcase in a separate patch.

Anyway, the patch below was regression-tested on i686-pc-linux-gnu and
also collect2 builds on i386-lynx-lynxos now.

Is it OK to apply?

Adam

2004-08-24  Adam Nemet  <anemet@lnxw.com> 
 
        * tlink.c (recompile_files): Use tlink_execute() instead of 
        system().  Don't duplicate verbose output of collect_execute. 
        Update comment before the function. 

Index: tlink.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tlink.c,v
retrieving revision 1.56
diff -u -p -r1.56 tlink.c
--- tlink.c	29 Jul 2004 17:59:24 -0000	1.56
+++ tlink.c	24 Aug 2004 01:51:35 -0000
@@ -432,9 +432,7 @@ maybe_tweak (char *line, file *f)
 }
 
 /* Update the repo files for each of the object files we have adjusted and
-   recompile.
-
-   XXX Should this use collect_execute instead of system?  */
+   recompile.  */
 
 static int
 recompile_files (void)
@@ -446,7 +444,10 @@ recompile_files (void)
 
   while ((f = file_pop ()) != NULL)
     {
-      char *line, *command;
+      char *line;
+      const char *p, *q;
+      char **argv;
+      struct obstack arg_stack;
       FILE *stream = fopen (f->key, "r");
       const char *const outname = frob_extension (f->key, ".rnw");
       FILE *output = fopen (outname, "w");
@@ -465,31 +466,67 @@ recompile_files (void)
       fclose (output);
       rename (outname, f->key);
 
-      obstack_grow (&temporary_obstack, "cd ", 3);
-      obstack_grow (&temporary_obstack, f->dir, strlen (f->dir));
-      obstack_grow (&temporary_obstack, "; ", 2);
-      obstack_grow (&temporary_obstack, c_file_name, strlen (c_file_name));
-      obstack_1grow (&temporary_obstack, ' ');
       if (!f->args)
 	{
 	  error ("repository file `%s' does not contain command-line "
 		 "arguments", f->key);
 	  return 0;
 	}
-      obstack_grow (&temporary_obstack, f->args, strlen (f->args));
-      obstack_1grow (&temporary_obstack, ' ');
-      command = obstack_copy0 (&temporary_obstack, f->main, strlen (f->main));
+
+      /* Build a null-terminated argv array suitable for
+	 tlink_execute().  Manipulate arguments on the arg_stack while
+	 building argv on the temporary_obstack.  */
+
+      obstack_init (&arg_stack);
+      obstack_ptr_grow (&temporary_obstack, c_file_name);
+
+      for (p = f->args; *p != '\0'; p = q + 1)
+	{
+	  /* Arguments are delimited by single-quotes.  Find the
+	     opening quote.  */
+	  p = strchr (p, '\'');
+	  if (!p)
+	    goto done;
+
+	  /* Find the closing quote.  */
+	  q = strchr (p + 1, '\'');
+	  if (!q)
+	    goto done;
+
+	  obstack_grow (&arg_stack, p + 1, q - (p + 1));
+
+	  /* Replace '\'' with '.  This is how set_collect_gcc_options
+	     encodes a single-quote.  */
+	  while (q[1] == '\\' && q[2] == '\'' && q[3] == '\'')
+	    {
+	      const char *r;
+
+	      r = strchr (q + 4, '\'');
+	      if (!r)
+		goto done;
+
+	      obstack_grow (&arg_stack, q + 3, r - (q + 3));
+	      q = r;
+	    }
+
+	  obstack_1grow (&arg_stack, '\0');
+	  obstack_ptr_grow (&temporary_obstack, obstack_finish (&arg_stack));
+	}
+    done:
+      obstack_ptr_grow (&temporary_obstack, f->main);
+      obstack_ptr_grow (&temporary_obstack, NULL);
+      argv = obstack_finish (&temporary_obstack);
 
       if (tlink_verbose)
 	fprintf (stderr, _("collect: recompiling %s\n"), f->main);
-      if (tlink_verbose >= 3)
-	fprintf (stderr, "%s\n", command);
 
-      if (system (command) != 0)
+      if (chdir (f->dir) != 0
+	  || tlink_execute (c_file_name, argv, NULL) != 0)
 	return 0;
 
       read_repo_file (f);
 
+      obstack_free (&arg_stack, NULL);
       obstack_free (&temporary_obstack, temporary_firstobj);
     }
   return 1;



More information about the Gcc-patches mailing list