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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | vm/dart_api_impl.cc » ('j') | vm/dart_api_impl.cc » ('J')
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 "bin/builtin.h" 5 #include "bin/builtin.h"
6 6
7 #include <stdlib.h> 7 #include <stdlib.h>
8 #include <string.h> 8 #include <string.h>
9 9
10 #include "bin/dartutils.h" 10 #include "bin/dartutils.h"
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 } 96 }
97 } 97 }
98 return NULL; 98 return NULL;
99 } 99 }
100 100
101 101
102 // Implementation of native functions which are used for some 102 // Implementation of native functions which are used for some
103 // test/debug functionality in standalone dart mode. 103 // test/debug functionality in standalone dart mode.
104 104
105 void Builtin::PrintString(FILE* out, Dart_Handle str) { 105 void Builtin::PrintString(FILE* out, Dart_Handle str) {
106 const char* chars = NULL; 106 intptr_t length = 0;
107 107 Dart_Handle result = Dart_StringLength(str, &length);
108 Dart_Handle result = Dart_StringToCString(str, &chars); 108 DART_CHECK_VALID(result);
109 if (Dart_IsAsciiString(str)) {
110 length = (length * sizeof(uint8_t));
111 } else {
112 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,
113 }
114 uint8_t* chars = reinterpret_cast<uint8_t*>(malloc(length));
115 ASSERT(chars != NULL);
116 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
109 if (Dart_IsError(result)) { 117 if (Dart_IsError(result)) {
110 // TODO(turnidge): Consider propagating some errors here. What if 118 // TODO(turnidge): Consider propagating some errors here. What if
111 // an isolate gets interrupted by the embedder in the middle of 119 // an isolate gets interrupted by the embedder in the middle of
112 // Dart_StringToBytes? We need to make sure not to swallow the 120 // Dart_StringToBytes? We need to make sure not to swallow the
113 // interrupt. 121 // interrupt.
114 fputs(Dart_GetError(result), out); 122 fputs(Dart_GetError(result), out);
115 } else { 123 } else {
116 intptr_t length = strlen(chars);
117 fwrite(chars, sizeof(*chars), length, out); 124 fwrite(chars, sizeof(*chars), length, out);
118 } 125 }
119 fputc('\n', out); 126 fputc('\n', out);
120 fflush(out); 127 fflush(out);
128 free(chars);
121 } 129 }
122 130
123 131
124 void FUNCTION_NAME(Logger_PrintString)(Dart_NativeArguments args) { 132 void FUNCTION_NAME(Logger_PrintString)(Dart_NativeArguments args) {
125 Dart_EnterScope(); 133 Dart_EnterScope();
126 Builtin::PrintString(stdout, Dart_GetNativeArgument(args, 0)); 134 Builtin::PrintString(stdout, Dart_GetNativeArgument(args, 0));
127 Dart_ExitScope(); 135 Dart_ExitScope();
128 } 136 }
129 137
130 138
131 void FUNCTION_NAME(Exit)(Dart_NativeArguments args) { 139 void FUNCTION_NAME(Exit)(Dart_NativeArguments args) {
132 Dart_EnterScope(); 140 Dart_EnterScope();
133 int64_t status = 0; 141 int64_t status = 0;
134 // Ignore result if passing invalid argument and just exit 0. 142 // Ignore result if passing invalid argument and just exit 0.
135 DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 0), &status); 143 DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 0), &status);
136 Dart_ExitScope(); 144 Dart_ExitScope();
137 exit(status); 145 exit(status);
138 } 146 }
OLDNEW
« 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