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

Side by Side 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: A few more comments 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 unified diff | Download patch
« no previous file with comments | « no previous file | runtime/bin/utils.h » ('j') | runtime/bin/utils.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 "bin/dartutils.h" 5 #include "bin/dartutils.h"
6 #include "bin/io_buffer.h" 6 #include "bin/io_buffer.h"
7 #include "bin/platform.h" 7 #include "bin/platform.h"
8 #include "bin/process.h" 8 #include "bin/process.h"
9 #include "bin/socket.h" 9 #include "bin/socket.h"
10 #include "bin/utils.h" 10 #include "bin/utils.h"
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 intptr_t bytes_length = 0; 291 intptr_t bytes_length = 0;
292 Dart_Handle result = Dart_ListLength(bytes, &bytes_length); 292 Dart_Handle result = Dart_ListLength(bytes, &bytes_length);
293 if (Dart_IsError(result)) Dart_PropagateError(result); 293 if (Dart_IsError(result)) Dart_PropagateError(result);
294 uint8_t* buffer = new uint8_t[bytes_length + 1]; 294 uint8_t* buffer = new uint8_t[bytes_length + 1];
295 result = Dart_ListGetAsBytes(bytes, 0, buffer, bytes_length); 295 result = Dart_ListGetAsBytes(bytes, 0, buffer, bytes_length);
296 buffer[bytes_length] = '\0'; 296 buffer[bytes_length] = '\0';
297 if (Dart_IsError(result)) { 297 if (Dart_IsError(result)) {
298 delete[] buffer; 298 delete[] buffer;
299 Dart_PropagateError(result); 299 Dart_PropagateError(result);
300 } 300 }
301 intptr_t len;
301 char* str = 302 char* str =
302 StringUtils::ConsoleStringToUtf8(reinterpret_cast<char*>(buffer)); 303 StringUtils::ConsoleStringToUtf8(
303 Dart_SetReturnValue(args, DartUtils::NewString(str)); 304 reinterpret_cast<char*>(buffer),
305 bytes_length,
306 &len);
307 result =
308 Dart_NewStringFromUTF8(reinterpret_cast<const uint8_t*>(str), len);
309 // On some platforms StringUtils::Utf8ToConsoleString is a no op, and
Ivan Posva 2015/06/22 08:54:16 Comment does not match the call here?
Søren Gjesse 2015/06/23 11:17:59 Done.
310 // the data to convert is passed through. In that case don't free the
311 // result of the conversion as nothing is allocated.
304 if (str != reinterpret_cast<char*>(buffer)) free(str); 312 if (str != reinterpret_cast<char*>(buffer)) free(str);
313 delete[] buffer;
Ivan Posva 2015/06/22 08:54:16 Wouldn't it be easier and safer to use Dart_ScopeA
Søren Gjesse 2015/06/23 11:17:59 Changed it for the buffer variable used here. We c
314 if (Dart_IsError(result)) {
315 Dart_PropagateError(result);
316 }
317 Dart_SetReturnValue(args, result);
305 } 318 }
306 319
307 320
308 void FUNCTION_NAME(StringToSystemEncoding)(Dart_NativeArguments args) { 321 void FUNCTION_NAME(StringToSystemEncoding)(Dart_NativeArguments args) {
309 Dart_Handle str = Dart_GetNativeArgument(args, 0); 322 Dart_Handle str = Dart_GetNativeArgument(args, 0);
310 const char* utf8 = DartUtils::GetStringValue(str); 323 char* utf8;
311 const char* system_string = StringUtils::Utf8ToConsoleString(utf8); 324 intptr_t utf8_len;
312 int external_length = strlen(system_string); 325 Dart_Handle result = Dart_StringToUTF8(
326 str, reinterpret_cast<uint8_t **>(&utf8), &utf8_len);
327 if (Dart_IsError(result)) {
328 Dart_PropagateError(result);
329 }
330 intptr_t system_len;
331 const char* system_string =
332 StringUtils::Utf8ToConsoleString(utf8, utf8_len, &system_len);
313 uint8_t* buffer = NULL; 333 uint8_t* buffer = NULL;
314 Dart_Handle external_array = IOBuffer::Allocate(external_length, &buffer); 334 Dart_Handle external_array = IOBuffer::Allocate(system_len, &buffer);
Lasse Reichstein Nielsen 2015/06/22 12:08:34 Could Utf8ToConsoleString be made to allocate usin
Søren Gjesse 2015/06/23 11:17:58 I don't want Utf8ToConsoleString to allocate in a
315 memmove(buffer, system_string, external_length); 335 if (Dart_IsError(external_array)) {
336 // See comment further down.
Lasse Reichstein Nielsen 2015/06/22 12:08:34 Put comment here, say "See comment above for why t
Søren Gjesse 2015/06/23 11:17:58 Done.
337 if (utf8 != system_string) free(const_cast<char*>(system_string));
338 Dart_PropagateError(result);
339 }
340 memmove(buffer, system_string, system_len);
341 // On some platforms StringUtils::Utf8ToConsoleString is a no op, and
342 // the data to convert is passed through. In that case don't free the
343 // result of the conversion as nothing is allocated.
Lasse Reichstein Nielsen 2015/06/22 12:08:34 as nothing new has been allocated.
Søren Gjesse 2015/06/23 11:17:59 Done.
316 if (utf8 != system_string) free(const_cast<char*>(system_string)); 344 if (utf8 != system_string) free(const_cast<char*>(system_string));
317 Dart_SetReturnValue(args, external_array); 345 Dart_SetReturnValue(args, external_array);
318 } 346 }
319 347
320 } // namespace bin 348 } // namespace bin
321 } // namespace dart 349 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/bin/utils.h » ('j') | runtime/bin/utils.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698