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

Unified Diff: runtime/bin/process.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, 6 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/platform_win.cc ('k') | runtime/bin/process_win.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/process.cc
diff --git a/runtime/bin/process.cc b/runtime/bin/process.cc
index 88ace0e95913842e103fc0e82fbf2adb884bed59..2c90c11cdbebc29c364aaea4675c86cfc5b14c30 100644
--- a/runtime/bin/process.cc
+++ b/runtime/bin/process.cc
@@ -291,29 +291,53 @@ void FUNCTION_NAME(SystemEncodingToString)(Dart_NativeArguments args) {
intptr_t bytes_length = 0;
Dart_Handle result = Dart_ListLength(bytes, &bytes_length);
if (Dart_IsError(result)) Dart_PropagateError(result);
- uint8_t* buffer = new uint8_t[bytes_length + 1];
+ uint8_t* buffer =
+ reinterpret_cast<uint8_t*>(Dart_ScopeAllocate(bytes_length + 1));
result = Dart_ListGetAsBytes(bytes, 0, buffer, bytes_length);
buffer[bytes_length] = '\0';
- if (Dart_IsError(result)) {
- delete[] buffer;
- Dart_PropagateError(result);
- }
+ if (Dart_IsError(result)) Dart_PropagateError(result);
+ intptr_t len;
char* str =
- StringUtils::ConsoleStringToUtf8(reinterpret_cast<char*>(buffer));
- Dart_SetReturnValue(args, DartUtils::NewString(str));
- if (str != reinterpret_cast<char*>(buffer)) free(str);
+ StringUtils::ConsoleStringToUtf8(
+ reinterpret_cast<char*>(buffer),
+ bytes_length,
+ &len);
+ if (str == NULL) {
+ Dart_ThrowException(
+ DartUtils::NewInternalError("SystemEncodingToString failed"));
+ }
+ result =
+ Dart_NewStringFromUTF8(reinterpret_cast<const uint8_t*>(str), len);
+ free(str);
+ if (Dart_IsError(result)) Dart_PropagateError(result);
+ Dart_SetReturnValue(args, result);
}
void FUNCTION_NAME(StringToSystemEncoding)(Dart_NativeArguments args) {
Dart_Handle str = Dart_GetNativeArgument(args, 0);
- const char* utf8 = DartUtils::GetStringValue(str);
- const char* system_string = StringUtils::Utf8ToConsoleString(utf8);
- int external_length = strlen(system_string);
+ char* utf8;
+ intptr_t utf8_len;
+ Dart_Handle result = Dart_StringToUTF8(
+ str, reinterpret_cast<uint8_t **>(&utf8), &utf8_len);
+ if (Dart_IsError(result)) {
+ Dart_PropagateError(result);
+ }
+ intptr_t system_len;
+ const char* system_string =
+ StringUtils::Utf8ToConsoleString(utf8, utf8_len, &system_len);
+ if (system_string == NULL) {
+ Dart_ThrowException(
+ DartUtils::NewInternalError("StringToSystemEncoding failed"));
+ }
uint8_t* buffer = NULL;
- Dart_Handle external_array = IOBuffer::Allocate(external_length, &buffer);
- memmove(buffer, system_string, external_length);
- if (utf8 != system_string) free(const_cast<char*>(system_string));
+ Dart_Handle external_array = IOBuffer::Allocate(system_len, &buffer);
+ if (Dart_IsError(external_array)) {
+ free(const_cast<char*>(system_string));
+ Dart_PropagateError(result);
+ }
+ memmove(buffer, system_string, system_len);
+ free(const_cast<char*>(system_string));
Dart_SetReturnValue(args, external_array);
}
« no previous file with comments | « runtime/bin/platform_win.cc ('k') | runtime/bin/process_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698