| 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/io_buffer.h" |
| 7 #include "bin/process.h" | 7 #include "bin/process.h" |
| 8 #include "bin/socket.h" | 8 #include "bin/socket.h" |
| 9 | 9 |
| 10 #include "include/dart_api.h" | 10 #include "include/dart_api.h" |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 if (Dart_IsError(result)) Dart_PropagateError(result); | 188 if (Dart_IsError(result)) Dart_PropagateError(result); |
| 189 uint8_t* buffer = new uint8_t[bytes_length]; | 189 uint8_t* buffer = new uint8_t[bytes_length]; |
| 190 result = Dart_ListGetAsBytes(bytes, 0, buffer, bytes_length); | 190 result = Dart_ListGetAsBytes(bytes, 0, buffer, bytes_length); |
| 191 if (Dart_IsError(result)) { | 191 if (Dart_IsError(result)) { |
| 192 delete[] buffer; | 192 delete[] buffer; |
| 193 Dart_PropagateError(result); | 193 Dart_PropagateError(result); |
| 194 } | 194 } |
| 195 char* str = | 195 char* str = |
| 196 StringUtils::SystemStringToUtf8(reinterpret_cast<char*>(buffer)); | 196 StringUtils::SystemStringToUtf8(reinterpret_cast<char*>(buffer)); |
| 197 Dart_SetReturnValue(args, DartUtils::NewString(str)); | 197 Dart_SetReturnValue(args, DartUtils::NewString(str)); |
| 198 if (str != reinterpret_cast<char*>(buffer)) free(str); |
| 198 Dart_ExitScope(); | 199 Dart_ExitScope(); |
| 199 } | 200 } |
| 200 | 201 |
| 201 | 202 |
| 202 void FUNCTION_NAME(StringToSystemEncoding)(Dart_NativeArguments args) { | 203 void FUNCTION_NAME(StringToSystemEncoding)(Dart_NativeArguments args) { |
| 203 Dart_EnterScope(); | 204 Dart_EnterScope(); |
| 204 Dart_Handle str = Dart_GetNativeArgument(args, 0); | 205 Dart_Handle str = Dart_GetNativeArgument(args, 0); |
| 205 const char* utf8 = DartUtils::GetStringValue(str); | 206 const char* utf8 = DartUtils::GetStringValue(str); |
| 206 const char* system_string = StringUtils::Utf8ToSystemString(utf8); | 207 const char* system_string = StringUtils::Utf8ToSystemString(utf8); |
| 207 int external_length = strlen(system_string); | 208 int external_length = strlen(system_string); |
| 208 uint8_t* buffer = NULL; | 209 uint8_t* buffer = NULL; |
| 209 Dart_Handle external_array = IOBuffer::Allocate(external_length, &buffer); | 210 Dart_Handle external_array = IOBuffer::Allocate(external_length, &buffer); |
| 210 memmove(buffer, system_string, external_length); | 211 memmove(buffer, system_string, external_length); |
| 212 if (utf8 != system_string) free(const_cast<char*>(system_string)); |
| 211 Dart_SetReturnValue(args, external_array); | 213 Dart_SetReturnValue(args, external_array); |
| 212 Dart_ExitScope(); | 214 Dart_ExitScope(); |
| 213 } | 215 } |
| OLD | NEW |