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" | |
7 #include "bin/process.h" | 6 #include "bin/process.h" |
8 #include "bin/socket.h" | 7 #include "bin/socket.h" |
9 | 8 |
10 #include "include/dart_api.h" | 9 #include "include/dart_api.h" |
11 | 10 |
12 | 11 |
13 static const int kProcessIdNativeField = 0; | 12 static const int kProcessIdNativeField = 0; |
14 | 13 |
15 | 14 |
16 // Extract an array of C strings from a list of Dart strings. | 15 // 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... |
171 Dart_Handle Process::GetProcessIdNativeField(Dart_Handle process, | 170 Dart_Handle Process::GetProcessIdNativeField(Dart_Handle process, |
172 intptr_t* pid) { | 171 intptr_t* pid) { |
173 return Dart_GetNativeInstanceField(process, kProcessIdNativeField, pid); | 172 return Dart_GetNativeInstanceField(process, kProcessIdNativeField, pid); |
174 } | 173 } |
175 | 174 |
176 | 175 |
177 Dart_Handle Process::SetProcessIdNativeField(Dart_Handle process, | 176 Dart_Handle Process::SetProcessIdNativeField(Dart_Handle process, |
178 intptr_t pid) { | 177 intptr_t pid) { |
179 return Dart_SetNativeInstanceField(process, kProcessIdNativeField, pid); | 178 return Dart_SetNativeInstanceField(process, kProcessIdNativeField, pid); |
180 } | 179 } |
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]; | |
190 result = Dart_ListGetAsBytes(bytes, 0, buffer, bytes_length); | |
191 if (Dart_IsError(result)) { | |
192 delete[] buffer; | |
193 Dart_PropagateError(result); | |
194 } | |
195 char* str = | |
196 StringUtils::SystemStringToUtf8(reinterpret_cast<char*>(buffer)); | |
197 Dart_SetReturnValue(args, DartUtils::NewString(str)); | |
198 if (str != reinterpret_cast<char*>(buffer)) free(str); | |
199 Dart_ExitScope(); | |
200 } | |
201 | |
202 | |
203 void FUNCTION_NAME(StringToSystemEncoding)(Dart_NativeArguments args) { | |
204 Dart_EnterScope(); | |
205 Dart_Handle str = Dart_GetNativeArgument(args, 0); | |
206 const char* utf8 = DartUtils::GetStringValue(str); | |
207 const char* system_string = StringUtils::Utf8ToSystemString(utf8); | |
208 int external_length = strlen(system_string); | |
209 uint8_t* buffer = NULL; | |
210 Dart_Handle external_array = IOBuffer::Allocate(external_length, &buffer); | |
211 memmove(buffer, system_string, external_length); | |
212 if (utf8 != system_string) free(const_cast<char*>(system_string)); | |
213 Dart_SetReturnValue(args, external_array); | |
214 Dart_ExitScope(); | |
215 } | |
OLD | NEW |