OLD | NEW |
---|---|
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/dartutils.h" | 5 #include "bin/dartutils.h" |
6 #include "bin/io_buffer.h" | |
6 #include "bin/process.h" | 7 #include "bin/process.h" |
7 #include "bin/socket.h" | 8 #include "bin/socket.h" |
8 | 9 |
9 #include "include/dart_api.h" | 10 #include "include/dart_api.h" |
10 | 11 |
11 | 12 |
12 static const int kProcessIdNativeField = 0; | 13 static const int kProcessIdNativeField = 0; |
13 | 14 |
14 | 15 |
15 // Extract an array of C strings from a list of Dart strings. | 16 // Extract an array of C strings from a list of Dart strings. |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
170 Dart_Handle Process::GetProcessIdNativeField(Dart_Handle process, | 171 Dart_Handle Process::GetProcessIdNativeField(Dart_Handle process, |
171 intptr_t* pid) { | 172 intptr_t* pid) { |
172 return Dart_GetNativeInstanceField(process, kProcessIdNativeField, pid); | 173 return Dart_GetNativeInstanceField(process, kProcessIdNativeField, pid); |
173 } | 174 } |
174 | 175 |
175 | 176 |
176 Dart_Handle Process::SetProcessIdNativeField(Dart_Handle process, | 177 Dart_Handle Process::SetProcessIdNativeField(Dart_Handle process, |
177 intptr_t pid) { | 178 intptr_t pid) { |
178 return Dart_SetNativeInstanceField(process, kProcessIdNativeField, pid); | 179 return Dart_SetNativeInstanceField(process, kProcessIdNativeField, pid); |
179 } | 180 } |
181 | |
182 | |
183 void FUNCTION_NAME(SystemEncodingToString)(Dart_NativeArguments args) { | |
184 Dart_EnterScope(); | |
185 Dart_Handle bytes = Dart_GetNativeArgument(args, 0); | |
186 intptr_t bytes_length = 0; | |
187 Dart_Handle result = Dart_ListLength(bytes, &bytes_length); | |
188 if (Dart_IsError(result)) Dart_PropagateError(result); | |
189 uint8_t* buffer = new uint8_t[bytes_length + 1]; | |
Mads Ager (google)
2012/12/07 20:14:17
This and the '\0' assignment below are the only ch
| |
190 result = Dart_ListGetAsBytes(bytes, 0, buffer, bytes_length); | |
191 buffer[bytes_length] = '\0'; | |
192 if (Dart_IsError(result)) { | |
193 delete[] buffer; | |
194 Dart_PropagateError(result); | |
195 } | |
196 char* str = | |
197 StringUtils::SystemStringToUtf8(reinterpret_cast<char*>(buffer)); | |
198 Dart_SetReturnValue(args, DartUtils::NewString(str)); | |
199 if (str != reinterpret_cast<char*>(buffer)) free(str); | |
200 Dart_ExitScope(); | |
201 } | |
202 | |
203 | |
204 void FUNCTION_NAME(StringToSystemEncoding)(Dart_NativeArguments args) { | |
205 Dart_EnterScope(); | |
206 Dart_Handle str = Dart_GetNativeArgument(args, 0); | |
207 const char* utf8 = DartUtils::GetStringValue(str); | |
208 const char* system_string = StringUtils::Utf8ToSystemString(utf8); | |
209 int external_length = strlen(system_string); | |
210 uint8_t* buffer = NULL; | |
211 Dart_Handle external_array = IOBuffer::Allocate(external_length, &buffer); | |
212 memmove(buffer, system_string, external_length); | |
213 if (utf8 != system_string) free(const_cast<char*>(system_string)); | |
214 Dart_SetReturnValue(args, external_array); | |
215 Dart_ExitScope(); | |
216 } | |
OLD | NEW |