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

Unified Diff: runtime/bin/platform_win.cc

Issue 2698813002: [dart:io][windows] Make unicode characters display correctly. (Closed)
Patch Set: Address comments Created 3 years, 10 months 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/io_natives.cc ('k') | runtime/bin/process_patch.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/platform_win.cc
diff --git a/runtime/bin/platform_win.cc b/runtime/bin/platform_win.cc
index 601d4d7b7635f0031e63b320c2fa3a7b5bdf7526..6ab84246b7e6bb8d14a76d60acfc42cbd6773287 100644
--- a/runtime/bin/platform_win.cc
+++ b/runtime/bin/platform_win.cc
@@ -8,10 +8,12 @@
#include "bin/platform.h"
#include "bin/file.h"
+#include "bin/lockers.h"
#include "bin/log.h"
#if !defined(DART_IO_DISABLED) && !defined(PLATFORM_DISABLE_SOCKET)
#include "bin/socket.h"
#endif
+#include "bin/thread.h"
#include "bin/utils.h"
#include "bin/utils_win.h"
@@ -27,7 +29,42 @@ char* Platform::resolved_executable_name_ = NULL;
int Platform::script_index_ = 1;
char** Platform::argv_ = NULL;
+class PlatformWin {
+ public:
+ static void InitOnce() {
+ platform_win_mutex_ = new Mutex();
+ saved_output_cp_ = -1;
+ }
+
+ static void SaveAndSetOutputCP() {
+ MutexLocker ml(platform_win_mutex_);
+ ASSERT(saved_output_cp_ == -1);
+ saved_output_cp_ = GetConsoleOutputCP();
+ SetConsoleOutputCP(CP_UTF8);
+ }
+
+ static void RestoreOutputCP() {
+ MutexLocker ml(platform_win_mutex_);
+ if (saved_output_cp_ != -1) {
+ SetConsoleOutputCP(saved_output_cp_);
+ saved_output_cp_ = -1;
+ }
+ }
+
+ private:
+ static Mutex* platform_win_mutex_;
+ static int saved_output_cp_;
+
+ DISALLOW_ALLOCATION();
+ DISALLOW_IMPLICIT_CONSTRUCTORS(PlatformWin);
+};
+
+int PlatformWin::saved_output_cp_ = -1;
+Mutex* PlatformWin::platform_win_mutex_ = NULL;
+
bool Platform::Initialize() {
+ PlatformWin::InitOnce();
+ PlatformWin::SaveAndSetOutputCP();
SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);
return true;
}
@@ -124,6 +161,8 @@ const char* Platform::ResolveExecutablePath() {
void Platform::Exit(int exit_code) {
// TODO(zra): Remove once VM shuts down cleanly.
::dart::private_flag_windows_run_tls_destructors = false;
+ // Restore the console's output code page
+ PlatformWin::RestoreOutputCP();
// On Windows we use ExitProcess so that threads can't clobber the exit_code.
// See: https://code.google.com/p/nativeclient/issues/detail?id=2870
::ExitProcess(exit_code);
« no previous file with comments | « runtime/bin/io_natives.cc ('k') | runtime/bin/process_patch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698