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

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: Address comments 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
« no previous file with comments | « runtime/bin/file_win.cc ('k') | runtime/bin/platform.h » ('j') | 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 7cc8f0c46e5d6087e60be49512ea3e1cd97486bc..534f8866cb6e3727acf16aabe11206bf17dafaa7 100644
--- a/runtime/bin/main.cc
+++ b/runtime/bin/main.cc
@@ -231,6 +231,25 @@ static void WriteToPerfEventsFile(const char* buffer, int64_t num_bytes) {
perf_events_symbols_file->WriteFully(buffer, num_bytes);
}
+// Convert all the arguments to UTF8. On Windows, the arguments are
+// encoded in the current code page and not UTF8.
+//
+// Returns true if the arguments are converted. In that case
+// each of the arguments need to be deallocated using free.
+static bool Utf8ConvertArgv(int argc, char** argv) {
+ bool result = false;
+ for (int i = 0; i < argc; i++) {
+ char* arg = argv[i];
+ argv[i] = StringUtils::SystemStringToUtf8(arg);
+ if (i == 0) {
+ result = argv[i] != arg;
+ } else {
+ ASSERT(result == (argv[i] != arg));
+ }
+ }
+ return result;
+}
+
// Parse out the command line arguments. Returns -1 if the arguments
// are incorrect, 0 otherwise.
@@ -637,6 +656,10 @@ int main(int argc, char** argv) {
fprintf(stderr, "Initialization failed\n");
}
+ // On Windows, the argv strings are code page encoded and not
+ // utf8. We need to convert them to utf8.
+ bool argv_converted = Utf8ConvertArgv(argc, argv);
+
// Parse command line arguments.
if (ParseArguments(argc,
argv,
@@ -724,8 +747,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 +770,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;
}
« no previous file with comments | « runtime/bin/file_win.cc ('k') | runtime/bin/platform.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698