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

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

Issue 10306002: Do not externalize Dart strings as C strings for "print()". (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: address review comments Created 8 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | runtime/include/dart_api.h » ('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 "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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 } 97 }
98 } 98 }
99 return NULL; 99 return NULL;
100 } 100 }
101 101
102 102
103 // Implementation of native functions which are used for some 103 // Implementation of native functions which are used for some
104 // test/debug functionality in standalone dart mode. 104 // test/debug functionality in standalone dart mode.
105 105
106 void Builtin::PrintString(FILE* out, Dart_Handle str) { 106 void Builtin::PrintString(FILE* out, Dart_Handle str) {
107 const char* cstring = NULL; 107 const uint8_t* characters = NULL;
108 Dart_Handle result = Dart_StringToCString(str, &cstring); 108 intptr_t length;
109 Dart_Handle result = Dart_StringToBytes(str, &characters, &length);
109 if (Dart_IsError(result)) { 110 if (Dart_IsError(result)) {
110 // TODO(turnidge): Consider propagating some errors here. What if 111 // TODO(turnidge): Consider propagating some errors here. What if
111 // an isolate gets interrupted by the embedder in the middle of 112 // an isolate gets interrupted by the embedder in the middle of
112 // Dart_StringToCString? We need to make sure not to swallow the 113 // Dart_StringToBytes? We need to make sure not to swallow the
113 // interrupt. 114 // interrupt.
114 cstring = Dart_GetError(result); 115 fputs(Dart_GetError(result));
116 } else {
117 fwrite(characters, sizeof(*characters), length, out);
115 } 118 }
116 fprintf(out, "%s\n", cstring); 119 fputc('\n', out);
117 fflush(out); 120 fflush(out);
118 } 121 }
119 122
120 123
121 void FUNCTION_NAME(Logger_PrintString)(Dart_NativeArguments args) { 124 void FUNCTION_NAME(Logger_PrintString)(Dart_NativeArguments args) {
122 Dart_EnterScope(); 125 Dart_EnterScope();
123 Builtin::PrintString(stdout, Dart_GetNativeArgument(args, 0)); 126 Builtin::PrintString(stdout, Dart_GetNativeArgument(args, 0));
124 Dart_ExitScope(); 127 Dart_ExitScope();
125 } 128 }
126 129
(...skipping 12 matching lines...) Expand all
139 } else { 142 } else {
140 ASSERT(id == Builtin::kIOLibrary); 143 ASSERT(id == Builtin::kIOLibrary);
141 url = Dart_NewString(DartUtils::kIOLibURL); 144 url = Dart_NewString(DartUtils::kIOLibURL);
142 } 145 }
143 Dart_Handle builtin_lib = Dart_LookupLibrary(url); 146 Dart_Handle builtin_lib = Dart_LookupLibrary(url);
144 DART_CHECK_VALID(builtin_lib); 147 DART_CHECK_VALID(builtin_lib);
145 // Setup the native resolver for built in library functions. 148 // Setup the native resolver for built in library functions.
146 Dart_Handle result = Dart_SetNativeResolver(builtin_lib, NativeLookup); 149 Dart_Handle result = Dart_SetNativeResolver(builtin_lib, NativeLookup);
147 DART_CHECK_VALID(result); 150 DART_CHECK_VALID(result);
148 } 151 }
OLDNEW
« no previous file with comments | « no previous file | runtime/include/dart_api.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698