OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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/io_buffer.h" |
7 #include "bin/log.h" | 7 #include "bin/log.h" |
8 #include "bin/platform.h" | 8 #include "bin/platform.h" |
9 #include "bin/process.h" | 9 #include "bin/process.h" |
10 #include "bin/socket.h" | 10 #include "bin/socket.h" |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 status_handle, "_errorCode", error_code); | 181 status_handle, "_errorCode", error_code); |
182 if (Dart_IsError(result)) { | 182 if (Dart_IsError(result)) { |
183 Dart_PropagateError(result); | 183 Dart_PropagateError(result); |
184 } | 184 } |
185 result = DartUtils::SetStringField( | 185 result = DartUtils::SetStringField( |
186 status_handle, | 186 status_handle, |
187 "_errorMessage", | 187 "_errorMessage", |
188 os_error_message != NULL ? os_error_message | 188 os_error_message != NULL ? os_error_message |
189 : "Cannot get error message"); | 189 : "Cannot get error message"); |
190 if (Dart_IsError(result)) { | 190 if (Dart_IsError(result)) { |
| 191 delete[] string_args; |
| 192 delete[] string_environment; |
| 193 free(os_error_message); |
191 Dart_PropagateError(result); | 194 Dart_PropagateError(result); |
192 } | 195 } |
193 } | 196 } |
194 delete[] string_args; | 197 delete[] string_args; |
195 delete[] string_environment; | 198 delete[] string_environment; |
196 free(os_error_message); | 199 free(os_error_message); |
197 Dart_SetReturnValue(args, Dart_NewBoolean(error_code == 0)); | 200 Dart_SetReturnValue(args, Dart_NewBoolean(error_code == 0)); |
198 } | 201 } |
199 | 202 |
200 | 203 |
(...skipping 22 matching lines...) Expand all Loading... |
223 if (Dart_IsError(err)) Dart_PropagateError(err); | 226 if (Dart_IsError(err)) Dart_PropagateError(err); |
224 Dart_Handle list = Dart_NewList(4); | 227 Dart_Handle list = Dart_NewList(4); |
225 Dart_ListSetAt(list, 0, Dart_NewInteger(pid)); | 228 Dart_ListSetAt(list, 0, Dart_NewInteger(pid)); |
226 Dart_ListSetAt(list, 1, Dart_NewInteger(result.exit_code())); | 229 Dart_ListSetAt(list, 1, Dart_NewInteger(result.exit_code())); |
227 Dart_ListSetAt(list, 2, out); | 230 Dart_ListSetAt(list, 2, out); |
228 Dart_ListSetAt(list, 3, err); | 231 Dart_ListSetAt(list, 3, err); |
229 Dart_SetReturnValue(args, list); | 232 Dart_SetReturnValue(args, list); |
230 } else { | 233 } else { |
231 Dart_Handle error = DartUtils::NewDartOSError(); | 234 Dart_Handle error = DartUtils::NewDartOSError(); |
232 Process::Kill(pid, 9); | 235 Process::Kill(pid, 9); |
233 if (Dart_IsError(error)) Dart_PropagateError(error); | |
234 Dart_ThrowException(error); | 236 Dart_ThrowException(error); |
235 } | 237 } |
236 } | 238 } |
237 | 239 |
238 | 240 |
239 void FUNCTION_NAME(Process_KillPid)(Dart_NativeArguments args) { | 241 void FUNCTION_NAME(Process_KillPid)(Dart_NativeArguments args) { |
240 intptr_t pid = DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 0)); | 242 intptr_t pid = DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 0)); |
241 intptr_t signal = DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 1)); | 243 intptr_t signal = DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 1)); |
242 bool success = Process::Kill(pid, signal); | 244 bool success = Process::Kill(pid, signal); |
243 Dart_SetReturnValue(args, Dart_NewBoolean(success)); | 245 Dart_SetReturnValue(args, Dart_NewBoolean(success)); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 reinterpret_cast<char*>(buffer), | 335 reinterpret_cast<char*>(buffer), |
334 bytes_length, | 336 bytes_length, |
335 &len); | 337 &len); |
336 if (str == NULL) { | 338 if (str == NULL) { |
337 Dart_ThrowException( | 339 Dart_ThrowException( |
338 DartUtils::NewInternalError("SystemEncodingToString failed")); | 340 DartUtils::NewInternalError("SystemEncodingToString failed")); |
339 } | 341 } |
340 result = | 342 result = |
341 Dart_NewStringFromUTF8(reinterpret_cast<const uint8_t*>(str), len); | 343 Dart_NewStringFromUTF8(reinterpret_cast<const uint8_t*>(str), len); |
342 free(str); | 344 free(str); |
343 if (Dart_IsError(result)) Dart_PropagateError(result); | |
344 Dart_SetReturnValue(args, result); | 345 Dart_SetReturnValue(args, result); |
345 } | 346 } |
346 | 347 |
347 | 348 |
348 void FUNCTION_NAME(StringToSystemEncoding)(Dart_NativeArguments args) { | 349 void FUNCTION_NAME(StringToSystemEncoding)(Dart_NativeArguments args) { |
349 Dart_Handle str = Dart_GetNativeArgument(args, 0); | 350 Dart_Handle str = Dart_GetNativeArgument(args, 0); |
350 char* utf8; | 351 char* utf8; |
351 intptr_t utf8_len; | 352 intptr_t utf8_len; |
352 Dart_Handle result = Dart_StringToUTF8( | 353 Dart_Handle result = Dart_StringToUTF8( |
353 str, reinterpret_cast<uint8_t **>(&utf8), &utf8_len); | 354 str, reinterpret_cast<uint8_t **>(&utf8), &utf8_len); |
354 if (Dart_IsError(result)) { | 355 if (Dart_IsError(result)) { |
355 Dart_PropagateError(result); | 356 Dart_PropagateError(result); |
356 } | 357 } |
357 intptr_t system_len; | 358 intptr_t system_len; |
358 const char* system_string = | 359 const char* system_string = |
359 StringUtils::Utf8ToConsoleString(utf8, utf8_len, &system_len); | 360 StringUtils::Utf8ToConsoleString(utf8, utf8_len, &system_len); |
360 if (system_string == NULL) { | 361 if (system_string == NULL) { |
361 Dart_ThrowException( | 362 Dart_ThrowException( |
362 DartUtils::NewInternalError("StringToSystemEncoding failed")); | 363 DartUtils::NewInternalError("StringToSystemEncoding failed")); |
363 } | 364 } |
364 uint8_t* buffer = NULL; | 365 uint8_t* buffer = NULL; |
365 Dart_Handle external_array = IOBuffer::Allocate(system_len, &buffer); | 366 Dart_Handle external_array = IOBuffer::Allocate(system_len, &buffer); |
366 if (Dart_IsError(external_array)) { | 367 if (!Dart_IsError(external_array)) { |
367 free(const_cast<char*>(system_string)); | 368 memmove(buffer, system_string, system_len); |
368 Dart_PropagateError(result); | |
369 } | 369 } |
370 memmove(buffer, system_string, system_len); | 370 Dart_SetReturnValue(args, external_array); |
371 free(const_cast<char*>(system_string)); | 371 free(const_cast<char*>(system_string)); |
372 Dart_SetReturnValue(args, external_array); | |
373 } | 372 } |
374 | 373 |
375 } // namespace bin | 374 } // namespace bin |
376 } // namespace dart | 375 } // namespace dart |
OLD | NEW |