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

Unified Diff: runtime/bin/main.cc

Issue 11275281: Update dart:io to convert strings between UTF8 and current code page (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 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
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;
}

Powered by Google App Engine
This is Rietveld 408576698