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

Unified Diff: bin/builtin_natives.cc

Issue 11275107: Fix length computation in Dart_StringToUTF8. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: 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 | « no previous file | vm/dart_api_impl.cc » ('j') | vm/dart_api_impl.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: bin/builtin_natives.cc
===================================================================
--- bin/builtin_natives.cc (revision 14418)
+++ bin/builtin_natives.cc (working copy)
@@ -103,9 +103,17 @@
// test/debug functionality in standalone dart mode.
void Builtin::PrintString(FILE* out, Dart_Handle str) {
- const char* chars = NULL;
-
- Dart_Handle result = Dart_StringToCString(str, &chars);
+ intptr_t length = 0;
+ Dart_Handle result = Dart_StringLength(str, &length);
+ DART_CHECK_VALID(result);
+ if (Dart_IsAsciiString(str)) {
+ length = (length * sizeof(uint8_t));
+ } else {
+ length = (length * sizeof(uint16_t));
Bill Hesse 2012/11/01 20:38:01 This is not enough. Some 16-bit code points are e
cshapiro 2012/11/02 17:01:56 We should be emitting UTF-8, not CESU-8. However,
+ }
+ uint8_t* chars = reinterpret_cast<uint8_t*>(malloc(length));
+ ASSERT(chars != NULL);
+ result = Dart_StringToUTF8(str, chars, &length);
Bill Hesse 2012/11/01 20:38:01 I don't see what the problem is with using Dart_St
siva 2012/11/01 21:23:03 Because that would mean we are assuming that the s
if (Dart_IsError(result)) {
// TODO(turnidge): Consider propagating some errors here. What if
// an isolate gets interrupted by the embedder in the middle of
@@ -113,11 +121,11 @@
// interrupt.
fputs(Dart_GetError(result), out);
} else {
- intptr_t length = strlen(chars);
fwrite(chars, sizeof(*chars), length, out);
}
fputc('\n', out);
fflush(out);
+ free(chars);
}
« no previous file with comments | « no previous file | vm/dart_api_impl.cc » ('j') | vm/dart_api_impl.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698