[phc-internals] [phc commit] r1146 - trunk/src/codegen

codesite-noreply at google.com codesite-noreply at google.com
Fri Apr 4 17:33:37 IST 2008


Author: paul.biggar
Date: Fri Apr  4 09:33:09 2008
New Revision: 1146

Modified:
   trunk/src/codegen/Compile_C.cpp

Log:
When gcc fails, print an error. If I can waste half an hour figuring it 
out was gcc failing, not phc, then a user will too.


Modified: trunk/src/codegen/Compile_C.cpp
==============================================================================
--- trunk/src/codegen/Compile_C.cpp	(original)
+++ trunk/src/codegen/Compile_C.cpp	Fri Apr  4 09:33:09 2008
@@ -96,11 +96,14 @@
 	for(unsigned int i = 0; i < args.size (); i++)
 		argv[i] = strdup(args[i]->str().c_str());

+	// convert to a string in case of error
+	stringstream command;
+	for(unsigned int i = 0; i < args.size (); i++)
+		command << argv[i] << " ";
+
 	if(pm->args_info->verbose_flag)
 	{
-		for(unsigned int i = 0; i < args.size (); i++)
-			cout << argv[i] << " ";
-		cout << endl;
+		cout << command.str () << endl;
 	}


@@ -109,17 +112,11 @@
 #define READ_END 0
 #define WRITE_END 1
 	if(pipe(pfd) == -1)
-	{
-		cerr << "Could not create pipe" << endl;
-		exit(-1);
-	}
+		phc_error ("Could not create pipe");

 	int cpid = fork();
 	if(cpid == -1)
-	{
-		cerr << "Could not fork" << endl;
-		exit(-1);
-	}
+		phc_error ("Could not fork");

 	if(cpid == 0)
 	{
@@ -146,8 +143,13 @@
 		close(STDOUT_FILENO);
 		close(pfd[WRITE_END]);

-		// Wait for gcc to finish
-		waitpid(cpid, NULL, 0);
+		// Wait for gcc to finish (get the exit code)
+		int exit_code;
+		waitpid(cpid, &exit_code, 0);
+		if (WEXITSTATUS (exit_code))
+		{
+			phc_error ("gcc exited with error %d (executed via '%s')", 
exit_code, command.str().c_str ());
+		}

 		// Restore stdout
 		dup(old_stdout);


More information about the phc-internals mailing list