| 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 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 return; | 144 return; |
| 145 } | 145 } |
| 146 } | 146 } |
| 147 int64_t mode = | 147 int64_t mode = |
| 148 DartUtils::GetInt64ValueCheckRange(Dart_GetNativeArgument(args, 5), 0, 2); | 148 DartUtils::GetInt64ValueCheckRange(Dart_GetNativeArgument(args, 5), 0, 2); |
| 149 Dart_Handle stdin_handle = Dart_GetNativeArgument(args, 6); | 149 Dart_Handle stdin_handle = Dart_GetNativeArgument(args, 6); |
| 150 Dart_Handle stdout_handle = Dart_GetNativeArgument(args, 7); | 150 Dart_Handle stdout_handle = Dart_GetNativeArgument(args, 7); |
| 151 Dart_Handle stderr_handle = Dart_GetNativeArgument(args, 8); | 151 Dart_Handle stderr_handle = Dart_GetNativeArgument(args, 8); |
| 152 Dart_Handle exit_handle = Dart_GetNativeArgument(args, 9); | 152 Dart_Handle exit_handle = Dart_GetNativeArgument(args, 9); |
| 153 intptr_t pid = -1; | 153 intptr_t pid = -1; |
| 154 char* os_error_message = NULL; | 154 char* os_error_message = NULL; // Scope allocated by Process::Start. |
| 155 | 155 |
| 156 int error_code = Process::Start(path, | 156 int error_code = Process::Start(path, |
| 157 string_args, | 157 string_args, |
| 158 args_length, | 158 args_length, |
| 159 working_directory, | 159 working_directory, |
| 160 string_environment, | 160 string_environment, |
| 161 environment_length, | 161 environment_length, |
| 162 static_cast<ProcessStartMode>(mode), | 162 static_cast<ProcessStartMode>(mode), |
| 163 &process_stdout, | 163 &process_stdout, |
| 164 &process_stdin, | 164 &process_stdin, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 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; | 191 delete[] string_args; |
| 192 delete[] string_environment; | 192 delete[] string_environment; |
| 193 free(os_error_message); | |
| 194 Dart_PropagateError(result); | 193 Dart_PropagateError(result); |
| 195 } | 194 } |
| 196 } | 195 } |
| 197 delete[] string_args; | 196 delete[] string_args; |
| 198 delete[] string_environment; | 197 delete[] string_environment; |
| 199 free(os_error_message); | |
| 200 Dart_SetReturnValue(args, Dart_NewBoolean(error_code == 0)); | 198 Dart_SetReturnValue(args, Dart_NewBoolean(error_code == 0)); |
| 201 } | 199 } |
| 202 | 200 |
| 203 | 201 |
| 204 void FUNCTION_NAME(Process_Wait)(Dart_NativeArguments args) { | 202 void FUNCTION_NAME(Process_Wait)(Dart_NativeArguments args) { |
| 205 Dart_Handle process = Dart_GetNativeArgument(args, 0); | 203 Dart_Handle process = Dart_GetNativeArgument(args, 0); |
| 206 intptr_t process_stdin = | 204 intptr_t process_stdin = |
| 207 Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 1)); | 205 Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 1)); |
| 208 intptr_t process_stdout = | 206 intptr_t process_stdout = |
| 209 Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 2)); | 207 Socket::GetSocketIdNativeField(Dart_GetNativeArgument(args, 2)); |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 Dart_Handle Process::SetProcessIdNativeField(Dart_Handle process, | 314 Dart_Handle Process::SetProcessIdNativeField(Dart_Handle process, |
| 317 intptr_t pid) { | 315 intptr_t pid) { |
| 318 return Dart_SetNativeInstanceField(process, kProcessIdNativeField, pid); | 316 return Dart_SetNativeInstanceField(process, kProcessIdNativeField, pid); |
| 319 } | 317 } |
| 320 | 318 |
| 321 | 319 |
| 322 void FUNCTION_NAME(SystemEncodingToString)(Dart_NativeArguments args) { | 320 void FUNCTION_NAME(SystemEncodingToString)(Dart_NativeArguments args) { |
| 323 Dart_Handle bytes = Dart_GetNativeArgument(args, 0); | 321 Dart_Handle bytes = Dart_GetNativeArgument(args, 0); |
| 324 intptr_t bytes_length = 0; | 322 intptr_t bytes_length = 0; |
| 325 Dart_Handle result = Dart_ListLength(bytes, &bytes_length); | 323 Dart_Handle result = Dart_ListLength(bytes, &bytes_length); |
| 326 if (Dart_IsError(result)) Dart_PropagateError(result); | 324 if (Dart_IsError(result)) { |
| 327 uint8_t* buffer = | 325 Dart_PropagateError(result); |
| 328 reinterpret_cast<uint8_t*>(Dart_ScopeAllocate(bytes_length + 1)); | 326 } |
| 327 uint8_t* buffer = Dart_ScopeAllocate(bytes_length + 1); |
| 329 result = Dart_ListGetAsBytes(bytes, 0, buffer, bytes_length); | 328 result = Dart_ListGetAsBytes(bytes, 0, buffer, bytes_length); |
| 330 buffer[bytes_length] = '\0'; | 329 buffer[bytes_length] = '\0'; |
| 331 if (Dart_IsError(result)) Dart_PropagateError(result); | 330 if (Dart_IsError(result)) { |
| 331 Dart_PropagateError(result); |
| 332 } |
| 332 intptr_t len; | 333 intptr_t len; |
| 333 char* str = | 334 char* str = StringUtils::ConsoleStringToUtf8( |
| 334 StringUtils::ConsoleStringToUtf8( | 335 reinterpret_cast<char*>(buffer), bytes_length, &len); |
| 335 reinterpret_cast<char*>(buffer), | |
| 336 bytes_length, | |
| 337 &len); | |
| 338 if (str == NULL) { | 336 if (str == NULL) { |
| 339 Dart_ThrowException( | 337 Dart_ThrowException( |
| 340 DartUtils::NewInternalError("SystemEncodingToString failed")); | 338 DartUtils::NewInternalError("SystemEncodingToString failed")); |
| 341 } | 339 } |
| 342 result = | 340 result = |
| 343 Dart_NewStringFromUTF8(reinterpret_cast<const uint8_t*>(str), len); | 341 Dart_NewStringFromUTF8(reinterpret_cast<const uint8_t*>(str), len); |
| 344 free(str); | |
| 345 Dart_SetReturnValue(args, result); | 342 Dart_SetReturnValue(args, result); |
| 346 } | 343 } |
| 347 | 344 |
| 348 | 345 |
| 349 void FUNCTION_NAME(StringToSystemEncoding)(Dart_NativeArguments args) { | 346 void FUNCTION_NAME(StringToSystemEncoding)(Dart_NativeArguments args) { |
| 350 Dart_Handle str = Dart_GetNativeArgument(args, 0); | 347 Dart_Handle str = Dart_GetNativeArgument(args, 0); |
| 351 char* utf8; | 348 char* utf8; |
| 352 intptr_t utf8_len; | 349 intptr_t utf8_len; |
| 353 Dart_Handle result = Dart_StringToUTF8( | 350 Dart_Handle result = Dart_StringToUTF8( |
| 354 str, reinterpret_cast<uint8_t **>(&utf8), &utf8_len); | 351 str, reinterpret_cast<uint8_t **>(&utf8), &utf8_len); |
| 355 if (Dart_IsError(result)) { | 352 if (Dart_IsError(result)) { |
| 356 Dart_PropagateError(result); | 353 Dart_PropagateError(result); |
| 357 } | 354 } |
| 358 intptr_t system_len; | 355 intptr_t system_len; |
| 359 const char* system_string = | 356 const char* system_string = |
| 360 StringUtils::Utf8ToConsoleString(utf8, utf8_len, &system_len); | 357 StringUtils::Utf8ToConsoleString(utf8, utf8_len, &system_len); |
| 361 if (system_string == NULL) { | 358 if (system_string == NULL) { |
| 362 Dart_ThrowException( | 359 Dart_ThrowException( |
| 363 DartUtils::NewInternalError("StringToSystemEncoding failed")); | 360 DartUtils::NewInternalError("StringToSystemEncoding failed")); |
| 364 } | 361 } |
| 365 uint8_t* buffer = NULL; | 362 uint8_t* buffer = NULL; |
| 366 Dart_Handle external_array = IOBuffer::Allocate(system_len, &buffer); | 363 Dart_Handle external_array = IOBuffer::Allocate(system_len, &buffer); |
| 367 if (!Dart_IsError(external_array)) { | 364 if (!Dart_IsError(external_array)) { |
| 368 memmove(buffer, system_string, system_len); | 365 memmove(buffer, system_string, system_len); |
| 369 } | 366 } |
| 370 Dart_SetReturnValue(args, external_array); | 367 Dart_SetReturnValue(args, external_array); |
| 371 free(const_cast<char*>(system_string)); | |
| 372 } | 368 } |
| 373 | 369 |
| 374 } // namespace bin | 370 } // namespace bin |
| 375 } // namespace dart | 371 } // namespace dart |
| OLD | NEW |