Chromium Code Reviews| Index: runtime/bin/main.cc |
| diff --git a/runtime/bin/main.cc b/runtime/bin/main.cc |
| index 7cc8f0c46e5d6087e60be49512ea3e1cd97486bc..2042a17eb0da5d9b779e0ac1112942b775c45871 100644 |
| --- a/runtime/bin/main.cc |
| +++ b/runtime/bin/main.cc |
| @@ -231,6 +231,18 @@ static void WriteToPerfEventsFile(const char* buffer, int64_t num_bytes) { |
| perf_events_symbols_file->WriteFully(buffer, num_bytes); |
| } |
| +static bool Utf8ConvertArgv(int argc, char** argv) { |
| + // Convert all the arguments to UTF8. On Windows, the arguments are |
| + // encoded in the current code page and not UTF8. |
|
Søren Gjesse
2012/11/13 12:48:45
Document return value.
Mads Ager (google)
2012/11/13 14:50:17
Done.
|
| + bool result = false; |
| + for (int i = 0; i < argc; i++) { |
| + char* arg = argv[i]; |
| + argv[i] = StringUtils::SystemStringToUtf8(arg); |
| + if (argv[i] != arg) result = true; |
|
Søren Gjesse
2012/11/13 12:48:45
Maybe change this to
if (argv == 0) {
result =
Mads Ager (google)
2012/11/13 14:50:17
Done.
|
| + } |
| + return result; |
| +} |
| + |
| // Parse out the command line arguments. Returns -1 if the arguments |
| // are incorrect, 0 otherwise. |
| @@ -637,6 +649,10 @@ int main(int argc, char** argv) { |
| fprintf(stderr, "Initialization failed\n"); |
| } |
| + // On Windows, the argv strings are code page incoded and not |
|
Søren Gjesse
2012/11/13 12:48:45
incoded -> encoded
Mads Ager (google)
2012/11/13 14:50:17
Done.
|
| + // utf8. We need to convert them to utf8. |
| + bool argv_converted = Utf8ConvertArgv(argc, argv); |
| + |
| // Parse command line arguments. |
| if (ParseArguments(argc, |
| argv, |
| @@ -724,8 +740,8 @@ int main(int argc, char** argv) { |
| result = SetBreakpoint(breakpoint_at, library); |
| if (Dart_IsError(result)) { |
| return ErrorExit("Error setting breakpoint at '%s': %s\n", |
| - breakpoint_at, |
| - Dart_GetError(result)); |
| + breakpoint_at, |
| + Dart_GetError(result)); |
| } |
| } |
| @@ -747,6 +763,10 @@ int main(int argc, char** argv) { |
| Dart_ShutdownIsolate(); |
| // Terminate process exit-code handler. |
| Process::TerminateExitCodeHandler(); |
| + // Free copied argument strings if converted. |
| + if (argv_converted) { |
| + for (int i = 0; i < argc; i++) free(argv[i]); |
| + } |
| return 0; |
| } |