- Timestamp:
- Apr 28, 2015, 4:21:36 PM (10 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, with_gc
- Children:
- 42e2ad7
- Parents:
- ad17ba6a
- Location:
- driver
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
driver/cc1.cc
rad17ba6a rbdd516a 8 8 // Created On : Fri Aug 26 14:23:51 2005 9 9 // Last Modified By : Peter A. Buhr 10 // Last Modified On : Sat Jan 10 14:16:06201511 // Update Count : 1510 // Last Modified On : Mon Apr 27 23:11:52 2015 11 // Update Count : 39 12 12 // 13 13 … … 34 34 string D__CFA_FLAGPREFIX__( "-D__CFA_FLAG__=" ); 35 35 36 char tmpname[] = P_tmpdir "/CFAXXXXXX"; 37 int tmpfilefd = -1; 38 36 39 37 40 bool prefix( string arg, string pre ) { … … 69 72 } // if 70 73 } // checkEnv 74 75 76 void rmtmpfile() { 77 if ( unlink( tmpname ) == -1 ) { // remove tmpname 78 perror ( "CFA Translator error: cpp failed" ); 79 exit( EXIT_FAILURE ); 80 } // if 81 tmpfilefd = -1; // mark closed 82 } // rmtmpfile 83 84 85 void sigTermHandler( int signal ) { 86 if ( tmpfilefd != -1 ) { // RACE, file created ? 87 rmtmpfile(); // remove 88 exit( EXIT_FAILURE ); // terminate 89 } // if 90 } // sigTermHandler 71 91 72 92 … … 89 109 const char *uargs[20]; // leave space for 20 additional cfa-cpp command line values 90 110 int nuargs = 1; // 0 => command name 111 112 signal( SIGINT, sigTermHandler ); 113 signal( SIGTERM, sigTermHandler ); 91 114 92 115 // process all the arguments … … 116 139 i += 1; // and the argument 117 140 118 // strip cfa flags controlling cpp step 119 141 // strip flags controlling cpp step 142 143 } else if ( arg == "-D__CPP__" ) { 144 cpp_flag = true; 145 } else if ( arg == "-D" && string( argv[i + 1] ) == "__CPP__" ) { 146 i += 1; // and the argument 147 cpp_flag = true; 120 148 } else if ( arg == "-D__CFA__" ) { 121 149 CFA_flag = true; … … 123 151 i += 1; // and the argument 124 152 CFA_flag = true; 125 } else if ( arg == "-D__CPP__" ) {126 cpp_flag = true;127 } else if ( arg == "-D" && string( argv[i + 1] ) == "__CPP__" ) {128 i += 1; // and the argument129 cpp_flag = true;130 153 } else if ( prefix( arg, D__CFA_FLAGPREFIX__ ) ) { 131 154 uargs[nuargs] = ( *new string( arg.substr( D__CFA_FLAGPREFIX__.size() ) ) ).c_str(); … … 233 256 // Create a temporary file to store output of the C preprocessor. 234 257 235 char tmpname[] = P_tmpdir "/CFAXXXXXX"; 236 int tmpfile = mkstemp( tmpname ); 237 if ( tmpfile == -1 ) { 258 tmpfilefd = mkstemp( tmpname ); 259 if ( tmpfilefd == -1 ) { 238 260 perror( "CFA Translator error: cpp level, mkstemp" ); 239 261 exit( EXIT_FAILURE ); … … 241 263 242 264 #ifdef __DEBUG_H__ 243 cerr << "tmpname:" << tmpname << " tmpfile :" << tmpfile<< endl;265 cerr << "tmpname:" << tmpname << " tmpfilefd:" << tmpfilefd << endl; 244 266 #endif // __DEBUG_H__ 245 267 … … 280 302 281 303 if ( WIFSIGNALED(code) != 0 ) { // child failed ? 282 unlink( tmpname );// remove tmpname304 rmtmpfile(); // remove tmpname 283 305 cerr << "CFA Translator error: cpp failed with signal " << WTERMSIG(code) << endl; 284 306 exit( EXIT_FAILURE ); … … 286 308 287 309 if ( WEXITSTATUS(code) != 0 ) { // child error ? 288 unlink( tmpname );// remove tmpname310 rmtmpfile(); // remove tmpname 289 311 exit( WEXITSTATUS( code ) ); // do not continue 290 312 } // if … … 293 315 // output. Otherwise, run the cfa-cpp preprocessor on the temporary file and save the result into the output file. 294 316 295 if ( CFA_flag || fork() == 0 ) { // conditional fork ?317 if ( fork() == 0 ) { // child runs CFA 296 318 uargs[0] = ( *new string( bprefix + "/cfa-cpp" ) ).c_str(); 297 319 … … 330 352 331 353 // Must unlink here because file must exist across execvp. 332 if ( unlink( tmpname ) == -1 ) { 333 perror( "CFA Translator error: cpp level, unlink" ); 334 exit( EXIT_FAILURE ); 335 } // if 354 rmtmpfile(); // remove tmpname 336 355 337 356 if ( WIFSIGNALED(code) ) { // child failed ? -
driver/cpp.cc
rad17ba6a rbdd516a 8 8 // Created On : Thu Aug 29 12:24:06 2002 9 9 // Last Modified By : Peter A. Buhr 10 // Last Modified On : Sat Dec 6 08:31:49 201411 // Update Count : 5 110 // Last Modified On : Tue Apr 21 07:23:38 2015 11 // Update Count : 52 12 12 // 13 13 … … 218 218 if ( cpp_flag && CFA_flag ) { 219 219 cerr << argv[0] << " Error cannot use -E and -CFA flags together." << endl; 220 exit( -1);220 exit( EXIT_FAILURE ); 221 221 } // if 222 222 … … 234 234 if ( freopen( cpp_out.c_str(), "w", stdout ) == NULL ) { // redirect stdout if not -E 235 235 cerr << argv[0] << ": Error can't write to " << cpp_out << endl; 236 exit( -1);236 exit( EXIT_FAILURE ); 237 237 } // if 238 238 … … 274 274 execvp( args[0], (char *const *)args ); // should not return 275 275 perror( "CFA translator error: cpp level, exec" ); 276 exit( -1);276 exit( EXIT_FAILURE ); 277 277 } // if 278 278 … … 282 282 if ( freopen( tmpfile, "w", stdout ) == NULL) { // redirect output to tmpfile 283 283 cerr << argv[0] << ": Error can't write to " << tmpfile << endl; 284 exit( -1);284 exit( EXIT_FAILURE ); 285 285 } // if 286 286 … … 308 308 execvp( args[0], (char *const *)args ); // should not return 309 309 perror( "CFA translator error: cpp level, exec" ); 310 exit( -1);310 exit( EXIT_FAILURE ); 311 311 } // if 312 312 … … 316 316 unlink( tmpfile ); 317 317 cerr << "CFA translator error: cpp failed with signal " << WTERMSIG(code) << endl; 318 exit( -1);318 exit( EXIT_FAILURE ); 319 319 } // if 320 320 … … 357 357 wait( &code ); // wait for child to finish 358 358 359 unlink( tmpfile ); 359 if ( unlink( tmpfile ) == -1 ) { 360 cerr << "CFA translator error: cfa-cpp failed " << errno << " to remove temporary file \"" << tmpfile << "\"" << endl; 361 exit( EXIT_FAILURE ); 362 } // if 360 363 361 364 if ( WIFSIGNALED(code) != 0 ) { // child completed successfully ? 362 365 cerr << "CFA translator error: cfa-cpp failed with signal " << WTERMSIG(code) << endl; 363 exit( -1);366 exit( EXIT_FAILURE ); 364 367 } // if 365 368 366 369 if ( CFA_flag ) { // -CFA flag ? 367 exit( -1 );// tell gcc not to go any further370 exit( EXIT_FAILURE ); // tell gcc not to go any further 368 371 } else { 369 372 exit( WEXITSTATUS(code) );
Note: See TracChangeset
for help on using the changeset viewer.