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

Side by Side Diff: runtime/bin/process_win.cc

Issue 1194883002: Improve the encoding/decoding to/from system encoding on Windows (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Addressed review comments from lrn@ Created 5 years, 5 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 unified diff | Download patch
« no previous file with comments | « runtime/bin/process.cc ('k') | runtime/bin/socket_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "platform/globals.h" 5 #include "platform/globals.h"
6 #if defined(TARGET_OS_WINDOWS) 6 #if defined(TARGET_OS_WINDOWS)
7 7
8 #include <process.h> // NOLINT 8 #include <process.h> // NOLINT
9 9
10 #include "bin/builtin.h" 10 #include "bin/builtin.h"
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 CloseProcessPipe(handles3); 302 CloseProcessPipe(handles3);
303 CloseProcessPipe(handles4); 303 CloseProcessPipe(handles4);
304 } 304 }
305 305
306 306
307 static int SetOsErrorMessage(char** os_error_message) { 307 static int SetOsErrorMessage(char** os_error_message) {
308 int error_code = GetLastError(); 308 int error_code = GetLastError();
309 const int kMaxMessageLength = 256; 309 const int kMaxMessageLength = 256;
310 wchar_t message[kMaxMessageLength]; 310 wchar_t message[kMaxMessageLength];
311 FormatMessageIntoBuffer(error_code, message, kMaxMessageLength); 311 FormatMessageIntoBuffer(error_code, message, kMaxMessageLength);
312 *os_error_message = StringUtils::WideToUtf8(message); 312 *os_error_message = StringUtilsWin::WideToUtf8(message);
313 return error_code; 313 return error_code;
314 } 314 }
315 315
316 316
317 // Open an inheritable handle to NUL. 317 // Open an inheritable handle to NUL.
318 static HANDLE OpenNul() { 318 static HANDLE OpenNul() {
319 SECURITY_ATTRIBUTES inherit_handle; 319 SECURITY_ATTRIBUTES inherit_handle;
320 inherit_handle.nLength = sizeof(SECURITY_ATTRIBUTES); 320 inherit_handle.nLength = sizeof(SECURITY_ATTRIBUTES);
321 inherit_handle.bInheritHandle = TRUE; 321 inherit_handle.bInheritHandle = TRUE;
322 inherit_handle.lpSecurityDescriptor = NULL; 322 inherit_handle.lpSecurityDescriptor = NULL;
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 stdin_handles_[kReadHandle] = INVALID_HANDLE_VALUE; 426 stdin_handles_[kReadHandle] = INVALID_HANDLE_VALUE;
427 stdin_handles_[kWriteHandle] = INVALID_HANDLE_VALUE; 427 stdin_handles_[kWriteHandle] = INVALID_HANDLE_VALUE;
428 stdout_handles_[kReadHandle] = INVALID_HANDLE_VALUE; 428 stdout_handles_[kReadHandle] = INVALID_HANDLE_VALUE;
429 stdout_handles_[kWriteHandle] = INVALID_HANDLE_VALUE; 429 stdout_handles_[kWriteHandle] = INVALID_HANDLE_VALUE;
430 stderr_handles_[kReadHandle] = INVALID_HANDLE_VALUE; 430 stderr_handles_[kReadHandle] = INVALID_HANDLE_VALUE;
431 stderr_handles_[kWriteHandle] = INVALID_HANDLE_VALUE; 431 stderr_handles_[kWriteHandle] = INVALID_HANDLE_VALUE;
432 exit_handles_[kReadHandle] = INVALID_HANDLE_VALUE; 432 exit_handles_[kReadHandle] = INVALID_HANDLE_VALUE;
433 exit_handles_[kWriteHandle] = INVALID_HANDLE_VALUE; 433 exit_handles_[kWriteHandle] = INVALID_HANDLE_VALUE;
434 434
435 // Transform input strings to system format. 435 // Transform input strings to system format.
436 const wchar_t* system_path = StringUtils::Utf8ToWide(path_); 436 const wchar_t* system_path = StringUtilsWin::Utf8ToWide(path_);
437 wchar_t** system_arguments = new wchar_t*[arguments_length]; 437 wchar_t** system_arguments = new wchar_t*[arguments_length];
438 for (int i = 0; i < arguments_length; i++) { 438 for (int i = 0; i < arguments_length; i++) {
439 system_arguments[i] = StringUtils::Utf8ToWide(arguments[i]); 439 system_arguments[i] = StringUtilsWin::Utf8ToWide(arguments[i]);
440 } 440 }
441 441
442 // Compute command-line length. 442 // Compute command-line length.
443 int command_line_length = wcslen(system_path); 443 int command_line_length = wcslen(system_path);
444 for (int i = 0; i < arguments_length; i++) { 444 for (int i = 0; i < arguments_length; i++) {
445 command_line_length += wcslen(system_arguments[i]); 445 command_line_length += wcslen(system_arguments[i]);
446 } 446 }
447 // Account for null termination and one space per argument. 447 // Account for null termination and one space per argument.
448 command_line_length += arguments_length + 1; 448 command_line_length += arguments_length + 1;
449 449
(...skipping 17 matching lines...) Expand all
467 free(const_cast<wchar_t*>(system_path)); 467 free(const_cast<wchar_t*>(system_path));
468 for (int i = 0; i < arguments_length; i++) free(system_arguments[i]); 468 for (int i = 0; i < arguments_length; i++) free(system_arguments[i]);
469 delete[] system_arguments; 469 delete[] system_arguments;
470 470
471 // Create environment block if an environment is supplied. 471 // Create environment block if an environment is supplied.
472 environment_block_ = NULL; 472 environment_block_ = NULL;
473 if (environment != NULL) { 473 if (environment != NULL) {
474 wchar_t** system_environment = new wchar_t*[environment_length]; 474 wchar_t** system_environment = new wchar_t*[environment_length];
475 // Convert environment strings to system strings. 475 // Convert environment strings to system strings.
476 for (intptr_t i = 0; i < environment_length; i++) { 476 for (intptr_t i = 0; i < environment_length; i++) {
477 system_environment[i] = StringUtils::Utf8ToWide(environment[i]); 477 system_environment[i] = StringUtilsWin::Utf8ToWide(environment[i]);
478 } 478 }
479 479
480 // An environment block is a sequence of zero-terminated strings 480 // An environment block is a sequence of zero-terminated strings
481 // followed by a block-terminating zero char. 481 // followed by a block-terminating zero char.
482 intptr_t block_size = 1; 482 intptr_t block_size = 1;
483 for (intptr_t i = 0; i < environment_length; i++) { 483 for (intptr_t i = 0; i < environment_length; i++) {
484 block_size += wcslen(system_environment[i]) + 1; 484 block_size += wcslen(system_environment[i]) + 1;
485 } 485 }
486 environment_block_ = new wchar_t[block_size]; 486 environment_block_ = new wchar_t[block_size];
487 intptr_t block_index = 0; 487 intptr_t block_index = 0;
(...skipping 11 matching lines...) Expand all
499 environment_block_[block_index++] = '\0'; 499 environment_block_[block_index++] = '\0';
500 ASSERT(block_index == block_size); 500 ASSERT(block_index == block_size);
501 for (intptr_t i = 0; i < environment_length; i++) { 501 for (intptr_t i = 0; i < environment_length; i++) {
502 free(system_environment[i]); 502 free(system_environment[i]);
503 } 503 }
504 delete[] system_environment; 504 delete[] system_environment;
505 } 505 }
506 506
507 system_working_directory_ = NULL; 507 system_working_directory_ = NULL;
508 if (working_directory_ != NULL) { 508 if (working_directory_ != NULL) {
509 system_working_directory_ = StringUtils::Utf8ToWide(working_directory_); 509 system_working_directory_ =
510 StringUtilsWin::Utf8ToWide(working_directory_);
510 } 511 }
511 512
512 attribute_list_ = NULL; 513 attribute_list_ = NULL;
513 } 514 }
514 515
515 516
516 ~ProcessStarter() { 517 ~ProcessStarter() {
517 // Deallocate command-line and environment block strings. 518 // Deallocate command-line and environment block strings.
518 delete[] command_line_; 519 delete[] command_line_;
519 delete[] environment_block_; 520 delete[] environment_block_;
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after
1042 USE(SetConsoleCtrlHandler(SignalHandler, false)); 1043 USE(SetConsoleCtrlHandler(SignalHandler, false));
1043 } 1044 }
1044 } 1045 }
1045 delete handler; 1046 delete handler;
1046 } 1047 }
1047 1048
1048 } // namespace bin 1049 } // namespace bin
1049 } // namespace dart 1050 } // namespace dart
1050 1051
1051 #endif // defined(TARGET_OS_WINDOWS) 1052 #endif // defined(TARGET_OS_WINDOWS)
OLDNEW
« no previous file with comments | « runtime/bin/process.cc ('k') | runtime/bin/socket_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698