Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(526)

Unified Diff: runtime/bin/main.cc

Issue 88853002: Call exit instead of returning from main (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/main.cc
diff --git a/runtime/bin/main.cc b/runtime/bin/main.cc
index ef204de5867ab12d1ebc1854c4f0b2c68644be94..eba550bbb5f5c21fdef061a77a8d16e3eb0ef512 100644
--- a/runtime/bin/main.cc
+++ b/runtime/bin/main.cc
@@ -689,8 +689,11 @@ static const int kCompilationErrorExitCode = 254;
// Exit code indicating an unhandled error that is not a compilation error.
static const int kErrorExitCode = 255;
+static void Exit(int exit_code) {
Ivan Posva 2013/11/26 18:05:53 Seems like extra unneeded abstraction.
+ exit(exit_code);
+}
-static int ErrorExit(int exit_code, const char* format, ...) {
+static void ErrorExit(int exit_code, const char* format, ...) {
va_list arguments;
va_start(arguments, format);
Log::VPrintErr(format, arguments);
@@ -702,14 +705,14 @@ static int ErrorExit(int exit_code, const char* format, ...) {
Dart_Cleanup();
- return exit_code;
+ Exit(exit_code);
}
-static int DartErrorExit(Dart_Handle error) {
+static void DartErrorExit(Dart_Handle error) {
Ivan Posva 2013/11/26 18:05:53 How about DartExitOnError(Dart_Handle result)? To
const int exit_code = Dart_IsCompilationError(error) ?
kCompilationErrorExitCode : kErrorExitCode;
- return ErrorExit(exit_code, "%s\n", Dart_GetError(error));
+ ErrorExit(exit_code, "%s\n", Dart_GetError(error));
}
@@ -754,7 +757,7 @@ static Dart_Handle GenerateScriptSource() {
}
-int main(int argc, char** argv) {
+void main(int argc, char** argv) {
char* script_name;
CommandLineOptions vm_options(argc);
CommandLineOptions dart_options(argc);
@@ -780,18 +783,18 @@ int main(int argc, char** argv) {
&verbose_debug_seen) < 0) {
if (has_help_option) {
PrintUsage();
- return 0;
+ Exit(0);
} else if (has_version_option) {
PrintVersion();
- return 0;
+ Exit(0);
} else if (print_flags_seen) {
// Will set the VM flags, print them out and then we exit as no
// script was specified on the command line.
Dart_SetVMFlags(vm_options.count(), vm_options.arguments());
- return 0;
+ Exit(0);
} else {
PrintUsage();
- return kErrorExitCode;
+ Exit(kErrorExitCode);
}
}
@@ -799,7 +802,7 @@ int main(int argc, char** argv) {
OSError err;
fprintf(stderr, "Error determinig current directory: %s\n", err.message());
fflush(stderr);
- return kErrorExitCode;
+ Exit(kErrorExitCode);
}
Dart_SetVMFlags(vm_options.count(), vm_options.arguments());
@@ -813,7 +816,7 @@ int main(int argc, char** argv) {
DartUtils::EntropySource)) {
fprintf(stderr, "%s", "VM initialization failed\n");
fflush(stderr);
- return kErrorExitCode;
+ Exit(kErrorExitCode);
}
// Start the debugger wire protocol handler if necessary.
@@ -854,7 +857,7 @@ int main(int argc, char** argv) {
Log::PrintErr("%s\n", error);
free(error);
delete [] isolate_name;
- return is_compile_error ? kCompilationErrorExitCode : kErrorExitCode;
+ Exit(is_compile_error ? kCompilationErrorExitCode : kErrorExitCode);
}
delete [] isolate_name;
@@ -873,7 +876,7 @@ int main(int argc, char** argv) {
result = Dart_CreateScriptSnapshot(&buffer, &size);
if (Dart_IsError(result)) {
Log::PrintErr("%s\n", Dart_GetError(result));
- return DartErrorExit(result);
+ DartErrorExit(result);
}
// Write the magic number to indicate file is a script snapshot.
@@ -895,19 +898,19 @@ int main(int argc, char** argv) {
if (has_compile_all) {
result = Dart_CompileAll();
if (Dart_IsError(result)) {
- return DartErrorExit(result);
+ DartErrorExit(result);
}
}
if (Dart_IsNull(root_lib)) {
- return ErrorExit(kErrorExitCode,
- "Unable to find root library for '%s'\n",
- script_name);
+ ErrorExit(kErrorExitCode,
+ "Unable to find root library for '%s'\n",
+ script_name);
}
if (has_print_script) {
result = GenerateScriptSource();
if (Dart_IsError(result)) {
- return DartErrorExit(result);
+ DartErrorExit(result);
}
} else {
// The helper function _getMainClosure creates a closure for the main
@@ -916,7 +919,7 @@ int main(int argc, char** argv) {
Dart_Handle main_closure = Dart_Invoke(
builtin_lib, Dart_NewStringFromCString("_getMainClosure"), 0, NULL);
if (Dart_IsError(main_closure)) {
- return DartErrorExit(result);
+ DartErrorExit(result);
Ivan Posva 2013/11/26 18:05:53 ?
}
// Set debug breakpoint if specified on the command line before calling
@@ -924,10 +927,10 @@ int main(int argc, char** argv) {
if (breakpoint_at != NULL) {
result = SetBreakpoint(breakpoint_at, root_lib);
if (Dart_IsError(result)) {
- return ErrorExit(kErrorExitCode,
- "Error setting breakpoint at '%s': %s\n",
- breakpoint_at,
- Dart_GetError(result));
+ ErrorExit(kErrorExitCode,
+ "Error setting breakpoint at '%s': %s\n",
+ breakpoint_at,
+ Dart_GetError(result));
}
}
@@ -949,20 +952,20 @@ int main(int argc, char** argv) {
result = Dart_ListSetAt(initial_startup_msg, 1,
CreateRuntimeOptions(&dart_options));
if (Dart_IsError(result)) {
- return DartErrorExit(result);
+ DartErrorExit(result);
}
Dart_Port main_port = Dart_GetMainPortId();
bool posted = Dart_Post(main_port, initial_startup_msg);
if (!posted) {
- return ErrorExit(kErrorExitCode,
- "Failed posting startup message to main "
- "isolate control port.");
+ ErrorExit(kErrorExitCode,
+ "Failed posting startup message to main "
+ "isolate control port.");
}
// Keep handling messages until the last active receive port is closed.
result = Dart_RunLoop();
if (Dart_IsError(result)) {
- return DartErrorExit(result);
+ DartErrorExit(result);
}
}
}
@@ -993,12 +996,13 @@ int main(int argc, char** argv) {
Platform::Cleanup();
- return Process::GlobalExitCode();
+ Exit(Process::GlobalExitCode());
}
} // namespace bin
} // namespace dart
int main(int argc, char** argv) {
- return dart::bin::main(argc, argv);
+ dart::bin::main(argc, argv);
+ UNREACHABLE();
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698