Chromium Code Reviews| 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/file.h" | 5 #include "bin/file.h" |
| 6 | 6 |
| 7 #include "bin/builtin.h" | 7 #include "bin/builtin.h" |
| 8 #include "bin/dartutils.h" | 8 #include "bin/dartutils.h" |
| 9 #include "bin/thread.h" | 9 #include "bin/thread.h" |
| 10 | 10 |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 172 File* file = reinterpret_cast<File*>(value); | 172 File* file = reinterpret_cast<File*>(value); |
| 173 if (file != NULL) { | 173 if (file != NULL) { |
| 174 Dart_Handle buffer_obj = Dart_GetNativeArgument(args, 1); | 174 Dart_Handle buffer_obj = Dart_GetNativeArgument(args, 1); |
| 175 ASSERT(Dart_IsList(buffer_obj)); | 175 ASSERT(Dart_IsList(buffer_obj)); |
| 176 int64_t offset = | 176 int64_t offset = |
| 177 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 2)); | 177 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 2)); |
| 178 int64_t length = | 178 int64_t length = |
| 179 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 3)); | 179 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 3)); |
| 180 intptr_t array_len = 0; | 180 intptr_t array_len = 0; |
| 181 Dart_Handle result = Dart_ListLength(buffer_obj, &array_len); | 181 Dart_Handle result = Dart_ListLength(buffer_obj, &array_len); |
| 182 ASSERT(!Dart_IsError(result)); | 182 if (Dart_IsError(result)) { |
| 183 Dart_PropagateError(result); | |
| 184 } | |
| 183 ASSERT((offset + length) <= array_len); | 185 ASSERT((offset + length) <= array_len); |
| 184 uint8_t* buffer = new uint8_t[length]; | 186 uint8_t* buffer = new uint8_t[length]; |
| 185 int total_bytes_read = | 187 int total_bytes_read = |
| 186 file->Read(reinterpret_cast<void*>(buffer), length); | 188 file->Read(reinterpret_cast<void*>(buffer), length); |
| 187 /* | 189 /* |
| 188 * Reading 0 indicates end of file. | 190 * Reading 0 indicates end of file. |
| 189 */ | 191 */ |
| 190 if (total_bytes_read >= 0) { | 192 if (total_bytes_read >= 0) { |
| 191 result = | 193 result = |
| 192 Dart_ListSetAsBytes(buffer_obj, offset, buffer, total_bytes_read); | 194 Dart_ListSetAsBytes(buffer_obj, offset, buffer, total_bytes_read); |
| 193 if (!Dart_IsError(result)) { | 195 if (Dart_IsError(result)) { |
|
Søren Gjesse
2012/03/08 21:18:46
Missing delete[] buffer.
turnidge
2012/03/08 22:19:26
Done.
| |
| 194 return_value = total_bytes_read; | 196 Dart_PropagateError(result); |
| 195 } | 197 } |
| 198 return_value = total_bytes_read; | |
| 196 } | 199 } |
| 197 delete[] buffer; | 200 delete[] buffer; |
| 198 } | 201 } |
| 199 Dart_SetReturnValue(args, Dart_NewInteger(return_value)); | 202 Dart_SetReturnValue(args, Dart_NewInteger(return_value)); |
| 200 Dart_ExitScope(); | 203 Dart_ExitScope(); |
| 201 } | 204 } |
| 202 | 205 |
| 203 | 206 |
| 204 void FUNCTION_NAME(File_WriteList)(Dart_NativeArguments args) { | 207 void FUNCTION_NAME(File_WriteList)(Dart_NativeArguments args) { |
| 205 Dart_EnterScope(); | 208 Dart_EnterScope(); |
| 206 intptr_t return_value = -1; | 209 intptr_t return_value = -1; |
| 207 intptr_t value = | 210 intptr_t value = |
| 208 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); | 211 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 0)); |
| 209 File* file = reinterpret_cast<File*>(value); | 212 File* file = reinterpret_cast<File*>(value); |
| 210 if (file != NULL) { | 213 if (file != NULL) { |
| 211 Dart_Handle buffer_obj = Dart_GetNativeArgument(args, 1); | 214 Dart_Handle buffer_obj = Dart_GetNativeArgument(args, 1); |
| 212 ASSERT(Dart_IsList(buffer_obj)); | 215 ASSERT(Dart_IsList(buffer_obj)); |
| 213 int64_t offset = | 216 int64_t offset = |
| 214 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 2)); | 217 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 2)); |
| 215 int64_t length = | 218 int64_t length = |
| 216 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 3)); | 219 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 3)); |
| 217 intptr_t buffer_len = 0; | 220 intptr_t buffer_len = 0; |
| 218 Dart_Handle result = Dart_ListLength(buffer_obj, &buffer_len); | 221 Dart_Handle result = Dart_ListLength(buffer_obj, &buffer_len); |
| 219 ASSERT(!Dart_IsError(result)); | 222 if (Dart_IsError(result)) { |
| 223 Dart_PropagateError(result); | |
| 224 } | |
| 220 ASSERT((offset + length) <= buffer_len); | 225 ASSERT((offset + length) <= buffer_len); |
| 221 uint8_t* buffer = new uint8_t[length]; | 226 uint8_t* buffer = new uint8_t[length]; |
| 222 result = Dart_ListGetAsBytes(buffer_obj, offset, buffer, length); | 227 result = Dart_ListGetAsBytes(buffer_obj, offset, buffer, length); |
| 223 ASSERT(!Dart_IsError(result)); | 228 if (Dart_IsError(result)) { |
|
Søren Gjesse
2012/03/08 21:18:46
Missing delete[] buffer.
turnidge
2012/03/08 22:19:26
Done.
| |
| 229 Dart_PropagateError(result); | |
| 230 } | |
| 224 int total_bytes_written = | 231 int total_bytes_written = |
| 225 file->Write(reinterpret_cast<void*>(buffer), length); | 232 file->Write(reinterpret_cast<void*>(buffer), length); |
| 226 if (total_bytes_written >= 0) { | 233 if (total_bytes_written >= 0) { |
| 227 return_value = total_bytes_written; | 234 return_value = total_bytes_written; |
| 228 } | 235 } |
| 229 delete[] buffer; | 236 delete[] buffer; |
| 230 } | 237 } |
| 231 Dart_SetReturnValue(args, Dart_NewInteger(return_value)); | 238 Dart_SetReturnValue(args, Dart_NewInteger(return_value)); |
| 232 Dart_ExitScope(); | 239 Dart_ExitScope(); |
| 233 } | 240 } |
| (...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 759 Dart_EnterScope(); | 766 Dart_EnterScope(); |
| 760 Dart_SetReturnValue(args, Dart_Null()); | 767 Dart_SetReturnValue(args, Dart_Null()); |
| 761 Dart_Port service_port = File::GetServicePort(); | 768 Dart_Port service_port = File::GetServicePort(); |
| 762 if (service_port != kIllegalPort) { | 769 if (service_port != kIllegalPort) { |
| 763 // Return a send port for the service port. | 770 // Return a send port for the service port. |
| 764 Dart_Handle send_port = Dart_NewSendPort(service_port); | 771 Dart_Handle send_port = Dart_NewSendPort(service_port); |
| 765 Dart_SetReturnValue(args, send_port); | 772 Dart_SetReturnValue(args, send_port); |
| 766 } | 773 } |
| 767 Dart_ExitScope(); | 774 Dart_ExitScope(); |
| 768 } | 775 } |
| OLD | NEW |