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/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/io_buffer.h" | 9 #include "bin/io_buffer.h" |
10 #include "bin/thread.h" | 10 #include "bin/thread.h" |
11 #include "bin/utils.h" | 11 #include "bin/utils.h" |
12 | 12 |
13 #include "include/dart_api.h" | 13 #include "include/dart_api.h" |
14 #include "include/dart_native_api.h" | |
14 | 15 |
15 namespace dart { | 16 namespace dart { |
16 namespace bin { | 17 namespace bin { |
17 | 18 |
18 static const int kMSPerSecond = 1000; | 19 static const int kMSPerSecond = 1000; |
19 | 20 |
20 | 21 |
21 // The file pointer has been passed into Dart as an intptr_t and it is safe | 22 // The file pointer has been passed into Dart as an intptr_t and it is safe |
22 // to pull it out of Dart as a 64-bit integer, cast it to an intptr_t and | 23 // to pull it out of Dart as a 64-bit integer, cast it to an intptr_t and |
23 // from there to a File pointer. | 24 // from there to a File pointer. |
24 static File* GetFilePointer(Dart_Handle handle) { | 25 static File* GetFilePointer(Dart_Handle handle) { |
25 intptr_t value = DartUtils::GetIntptrValue(handle); | 26 intptr_t value = DartUtils::GetIntptrValue(handle); |
26 return reinterpret_cast<File*>(value); | 27 return reinterpret_cast<File*>(value); |
27 } | 28 } |
28 | 29 |
29 | 30 |
30 bool File::ReadFully(void* buffer, int64_t num_bytes) { | 31 bool File::ReadFully(void* buffer, int64_t num_bytes) { |
31 int64_t remaining = num_bytes; | 32 int64_t remaining = num_bytes; |
32 char* current_buffer = reinterpret_cast<char*>(buffer); | 33 char* current_buffer = reinterpret_cast<char*>(buffer); |
34 Dart_DisableThreadInterrupter(); | |
siva
2013/12/13 21:29:14
I am wondering if we should have a macro around al
Cutch
2013/12/13 22:40:18
I'm not sure how to build a macro like that in a p
| |
33 while (remaining > 0) { | 35 while (remaining > 0) { |
34 int bytes_read = Read(current_buffer, remaining); | 36 int bytes_read = Read(current_buffer, remaining); |
35 if (bytes_read <= 0) { | 37 if (bytes_read <= 0) { |
38 Dart_EnableThreadInterrupter(); | |
36 return false; | 39 return false; |
37 } | 40 } |
38 remaining -= bytes_read; // Reduce the number of remaining bytes. | 41 remaining -= bytes_read; // Reduce the number of remaining bytes. |
39 current_buffer += bytes_read; // Move the buffer forward. | 42 current_buffer += bytes_read; // Move the buffer forward. |
40 } | 43 } |
44 Dart_EnableThreadInterrupter(); | |
41 return true; | 45 return true; |
42 } | 46 } |
43 | 47 |
44 | 48 |
45 bool File::WriteFully(const void* buffer, int64_t num_bytes) { | 49 bool File::WriteFully(const void* buffer, int64_t num_bytes) { |
46 int64_t remaining = num_bytes; | 50 int64_t remaining = num_bytes; |
47 const char* current_buffer = reinterpret_cast<const char*>(buffer); | 51 const char* current_buffer = reinterpret_cast<const char*>(buffer); |
52 Dart_DisableThreadInterrupter(); | |
48 while (remaining > 0) { | 53 while (remaining > 0) { |
49 int bytes_read = Write(current_buffer, remaining); | 54 int bytes_read = Write(current_buffer, remaining); |
50 if (bytes_read < 0) { | 55 if (bytes_read < 0) { |
56 Dart_EnableThreadInterrupter(); | |
51 return false; | 57 return false; |
52 } | 58 } |
53 remaining -= bytes_read; // Reduce the number of remaining bytes. | 59 remaining -= bytes_read; // Reduce the number of remaining bytes. |
54 current_buffer += bytes_read; // Move the buffer forward. | 60 current_buffer += bytes_read; // Move the buffer forward. |
55 } | 61 } |
62 Dart_EnableThreadInterrupter(); | |
56 return true; | 63 return true; |
57 } | 64 } |
58 | 65 |
59 | 66 |
60 File::FileOpenMode File::DartModeToFileMode(DartFileOpenMode mode) { | 67 File::FileOpenMode File::DartModeToFileMode(DartFileOpenMode mode) { |
61 ASSERT(mode == File::kDartRead || | 68 ASSERT(mode == File::kDartRead || |
62 mode == File::kDartWrite || | 69 mode == File::kDartWrite || |
63 mode == File::kDartAppend); | 70 mode == File::kDartAppend); |
64 if (mode == File::kDartWrite) { | 71 if (mode == File::kDartWrite) { |
65 return File::kWriteTruncate; | 72 return File::kWriteTruncate; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
108 ASSERT(file != NULL); | 115 ASSERT(file != NULL); |
109 delete file; | 116 delete file; |
110 Dart_SetReturnValue(args, Dart_NewInteger(0)); | 117 Dart_SetReturnValue(args, Dart_NewInteger(0)); |
111 } | 118 } |
112 | 119 |
113 | 120 |
114 void FUNCTION_NAME(File_ReadByte)(Dart_NativeArguments args) { | 121 void FUNCTION_NAME(File_ReadByte)(Dart_NativeArguments args) { |
115 File* file = GetFilePointer(Dart_GetNativeArgument(args, 0)); | 122 File* file = GetFilePointer(Dart_GetNativeArgument(args, 0)); |
116 ASSERT(file != NULL); | 123 ASSERT(file != NULL); |
117 uint8_t buffer; | 124 uint8_t buffer; |
125 Dart_DisableThreadInterrupter(); | |
118 int64_t bytes_read = file->Read(reinterpret_cast<void*>(&buffer), 1); | 126 int64_t bytes_read = file->Read(reinterpret_cast<void*>(&buffer), 1); |
127 Dart_EnableThreadInterrupter(); | |
119 if (bytes_read == 1) { | 128 if (bytes_read == 1) { |
120 Dart_SetReturnValue(args, Dart_NewInteger(buffer)); | 129 Dart_SetReturnValue(args, Dart_NewInteger(buffer)); |
121 } else if (bytes_read == 0) { | 130 } else if (bytes_read == 0) { |
122 Dart_SetReturnValue(args, Dart_NewInteger(-1)); | 131 Dart_SetReturnValue(args, Dart_NewInteger(-1)); |
123 } else { | 132 } else { |
124 Dart_Handle err = DartUtils::NewDartOSError(); | 133 Dart_Handle err = DartUtils::NewDartOSError(); |
125 if (Dart_IsError(err)) Dart_PropagateError(err); | 134 if (Dart_IsError(err)) Dart_PropagateError(err); |
126 Dart_SetReturnValue(args, err); | 135 Dart_SetReturnValue(args, err); |
127 } | 136 } |
128 } | 137 } |
129 | 138 |
130 | 139 |
131 void FUNCTION_NAME(File_WriteByte)(Dart_NativeArguments args) { | 140 void FUNCTION_NAME(File_WriteByte)(Dart_NativeArguments args) { |
132 File* file = GetFilePointer(Dart_GetNativeArgument(args, 0)); | 141 File* file = GetFilePointer(Dart_GetNativeArgument(args, 0)); |
133 ASSERT(file != NULL); | 142 ASSERT(file != NULL); |
134 int64_t byte = 0; | 143 int64_t byte = 0; |
135 if (DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 1), &byte)) { | 144 if (DartUtils::GetInt64Value(Dart_GetNativeArgument(args, 1), &byte)) { |
136 uint8_t buffer = static_cast<uint8_t>(byte & 0xff); | 145 uint8_t buffer = static_cast<uint8_t>(byte & 0xff); |
146 Dart_DisableThreadInterrupter(); | |
137 int64_t bytes_written = file->Write(reinterpret_cast<void*>(&buffer), 1); | 147 int64_t bytes_written = file->Write(reinterpret_cast<void*>(&buffer), 1); |
148 Dart_EnableThreadInterrupter(); | |
138 if (bytes_written >= 0) { | 149 if (bytes_written >= 0) { |
139 Dart_SetReturnValue(args, Dart_NewInteger(bytes_written)); | 150 Dart_SetReturnValue(args, Dart_NewInteger(bytes_written)); |
140 } else { | 151 } else { |
141 Dart_Handle err = DartUtils::NewDartOSError(); | 152 Dart_Handle err = DartUtils::NewDartOSError(); |
142 if (Dart_IsError(err)) Dart_PropagateError(err); | 153 if (Dart_IsError(err)) Dart_PropagateError(err); |
143 Dart_SetReturnValue(args, err); | 154 Dart_SetReturnValue(args, err); |
144 } | 155 } |
145 } else { | 156 } else { |
146 OSError os_error(-1, "Invalid argument", OSError::kUnknown); | 157 OSError os_error(-1, "Invalid argument", OSError::kUnknown); |
147 Dart_Handle err = DartUtils::NewDartOSError(&os_error); | 158 Dart_Handle err = DartUtils::NewDartOSError(&os_error); |
148 if (Dart_IsError(err)) Dart_PropagateError(err); | 159 if (Dart_IsError(err)) Dart_PropagateError(err); |
149 Dart_SetReturnValue(args, err); | 160 Dart_SetReturnValue(args, err); |
150 } | 161 } |
151 } | 162 } |
152 | 163 |
153 | 164 |
154 void FUNCTION_NAME(File_Read)(Dart_NativeArguments args) { | 165 void FUNCTION_NAME(File_Read)(Dart_NativeArguments args) { |
155 File* file = GetFilePointer(Dart_GetNativeArgument(args, 0)); | 166 File* file = GetFilePointer(Dart_GetNativeArgument(args, 0)); |
156 ASSERT(file != NULL); | 167 ASSERT(file != NULL); |
157 Dart_Handle length_object = Dart_GetNativeArgument(args, 1); | 168 Dart_Handle length_object = Dart_GetNativeArgument(args, 1); |
158 int64_t length = 0; | 169 int64_t length = 0; |
159 if (DartUtils::GetInt64Value(length_object, &length)) { | 170 if (DartUtils::GetInt64Value(length_object, &length)) { |
160 uint8_t* buffer = NULL; | 171 uint8_t* buffer = NULL; |
161 Dart_Handle external_array = IOBuffer::Allocate(length, &buffer); | 172 Dart_Handle external_array = IOBuffer::Allocate(length, &buffer); |
173 Dart_DisableThreadInterrupter(); | |
162 int64_t bytes_read = file->Read(reinterpret_cast<void*>(buffer), length); | 174 int64_t bytes_read = file->Read(reinterpret_cast<void*>(buffer), length); |
175 Dart_EnableThreadInterrupter(); | |
163 if (bytes_read < 0) { | 176 if (bytes_read < 0) { |
164 Dart_Handle err = DartUtils::NewDartOSError(); | 177 Dart_Handle err = DartUtils::NewDartOSError(); |
165 if (Dart_IsError(err)) Dart_PropagateError(err); | 178 if (Dart_IsError(err)) Dart_PropagateError(err); |
166 Dart_SetReturnValue(args, err); | 179 Dart_SetReturnValue(args, err); |
167 } else { | 180 } else { |
168 if (bytes_read < length) { | 181 if (bytes_read < length) { |
169 const int kNumArgs = 3; | 182 const int kNumArgs = 3; |
170 Dart_Handle dart_args[kNumArgs]; | 183 Dart_Handle dart_args[kNumArgs]; |
171 dart_args[0] = external_array; | 184 dart_args[0] = external_array; |
172 dart_args[1] = Dart_NewInteger(0); | 185 dart_args[1] = Dart_NewInteger(0); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
207 intptr_t start = | 220 intptr_t start = |
208 DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 2)); | 221 DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 2)); |
209 intptr_t end = | 222 intptr_t end = |
210 DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 3)); | 223 DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 3)); |
211 intptr_t length = end - start; | 224 intptr_t length = end - start; |
212 intptr_t array_len = 0; | 225 intptr_t array_len = 0; |
213 Dart_Handle result = Dart_ListLength(buffer_obj, &array_len); | 226 Dart_Handle result = Dart_ListLength(buffer_obj, &array_len); |
214 if (Dart_IsError(result)) Dart_PropagateError(result); | 227 if (Dart_IsError(result)) Dart_PropagateError(result); |
215 ASSERT(end <= array_len); | 228 ASSERT(end <= array_len); |
216 uint8_t* buffer = new uint8_t[length]; | 229 uint8_t* buffer = new uint8_t[length]; |
230 Dart_DisableThreadInterrupter(); | |
217 int64_t bytes_read = file->Read(reinterpret_cast<void*>(buffer), length); | 231 int64_t bytes_read = file->Read(reinterpret_cast<void*>(buffer), length); |
232 Dart_EnableThreadInterrupter(); | |
218 if (bytes_read >= 0) { | 233 if (bytes_read >= 0) { |
219 result = Dart_ListSetAsBytes(buffer_obj, start, buffer, bytes_read); | 234 result = Dart_ListSetAsBytes(buffer_obj, start, buffer, bytes_read); |
220 if (Dart_IsError(result)) { | 235 if (Dart_IsError(result)) { |
221 delete[] buffer; | 236 delete[] buffer; |
222 Dart_PropagateError(result); | 237 Dart_PropagateError(result); |
223 } | 238 } |
224 Dart_SetReturnValue(args, Dart_NewInteger(bytes_read)); | 239 Dart_SetReturnValue(args, Dart_NewInteger(bytes_read)); |
225 } else { | 240 } else { |
226 Dart_Handle err = DartUtils::NewDartOSError(); | 241 Dart_Handle err = DartUtils::NewDartOSError(); |
227 if (Dart_IsError(err)) Dart_PropagateError(err); | 242 if (Dart_IsError(err)) Dart_PropagateError(err); |
(...skipping 26 matching lines...) Expand all Loading... | |
254 void* buffer = NULL; | 269 void* buffer = NULL; |
255 Dart_Handle result = | 270 Dart_Handle result = |
256 Dart_TypedDataAcquireData(buffer_obj, &type, &buffer, &buffer_len); | 271 Dart_TypedDataAcquireData(buffer_obj, &type, &buffer, &buffer_len); |
257 if (Dart_IsError(result)) Dart_PropagateError(result); | 272 if (Dart_IsError(result)) Dart_PropagateError(result); |
258 | 273 |
259 ASSERT(type == Dart_TypedData_kUint8 || type == Dart_TypedData_kInt8); | 274 ASSERT(type == Dart_TypedData_kUint8 || type == Dart_TypedData_kInt8); |
260 ASSERT(end <= buffer_len); | 275 ASSERT(end <= buffer_len); |
261 ASSERT(buffer != NULL); | 276 ASSERT(buffer != NULL); |
262 | 277 |
263 // Write the data out into the file. | 278 // Write the data out into the file. |
279 Dart_DisableThreadInterrupter(); | |
264 int64_t bytes_written = file->Write(reinterpret_cast<void*>(buffer), length); | 280 int64_t bytes_written = file->Write(reinterpret_cast<void*>(buffer), length); |
265 | 281 Dart_EnableThreadInterrupter(); |
266 // Release the direct pointer acquired above. | 282 // Release the direct pointer acquired above. |
267 result = Dart_TypedDataReleaseData(buffer_obj); | 283 result = Dart_TypedDataReleaseData(buffer_obj); |
268 if (Dart_IsError(result)) Dart_PropagateError(result); | 284 if (Dart_IsError(result)) Dart_PropagateError(result); |
269 | 285 |
270 if (bytes_written != length) { | 286 if (bytes_written != length) { |
271 Dart_Handle err = DartUtils::NewDartOSError(); | 287 Dart_Handle err = DartUtils::NewDartOSError(); |
272 if (Dart_IsError(err)) Dart_PropagateError(err); | 288 if (Dart_IsError(err)) Dart_PropagateError(err); |
273 Dart_SetReturnValue(args, err); | 289 Dart_SetReturnValue(args, err); |
274 } | 290 } |
275 } | 291 } |
(...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
859 return CObject::IllegalArgumentError(); | 875 return CObject::IllegalArgumentError(); |
860 } | 876 } |
861 | 877 |
862 | 878 |
863 CObject* File::ReadByteRequest(const CObjectArray& request) { | 879 CObject* File::ReadByteRequest(const CObjectArray& request) { |
864 if (request.Length() == 1 && request[0]->IsIntptr()) { | 880 if (request.Length() == 1 && request[0]->IsIntptr()) { |
865 File* file = CObjectToFilePointer(request[0]); | 881 File* file = CObjectToFilePointer(request[0]); |
866 ASSERT(file != NULL); | 882 ASSERT(file != NULL); |
867 if (!file->IsClosed()) { | 883 if (!file->IsClosed()) { |
868 uint8_t buffer; | 884 uint8_t buffer; |
885 Dart_DisableThreadInterrupter(); | |
869 int64_t bytes_read = file->Read(reinterpret_cast<void*>(&buffer), 1); | 886 int64_t bytes_read = file->Read(reinterpret_cast<void*>(&buffer), 1); |
887 Dart_EnableThreadInterrupter(); | |
870 if (bytes_read > 0) { | 888 if (bytes_read > 0) { |
871 return new CObjectIntptr(CObject::NewIntptr(buffer)); | 889 return new CObjectIntptr(CObject::NewIntptr(buffer)); |
872 } else if (bytes_read == 0) { | 890 } else if (bytes_read == 0) { |
873 return new CObjectIntptr(CObject::NewIntptr(-1)); | 891 return new CObjectIntptr(CObject::NewIntptr(-1)); |
874 } else { | 892 } else { |
875 return CObject::NewOSError(); | 893 return CObject::NewOSError(); |
876 } | 894 } |
877 } else { | 895 } else { |
878 return CObject::FileClosedError(); | 896 return CObject::FileClosedError(); |
879 } | 897 } |
880 } | 898 } |
881 return CObject::IllegalArgumentError(); | 899 return CObject::IllegalArgumentError(); |
882 } | 900 } |
883 | 901 |
884 | 902 |
885 CObject* File::WriteByteRequest(const CObjectArray& request) { | 903 CObject* File::WriteByteRequest(const CObjectArray& request) { |
886 if (request.Length() == 2 && | 904 if (request.Length() == 2 && |
887 request[0]->IsIntptr() && | 905 request[0]->IsIntptr() && |
888 request[1]->IsInt32OrInt64()) { | 906 request[1]->IsInt32OrInt64()) { |
889 File* file = CObjectToFilePointer(request[0]); | 907 File* file = CObjectToFilePointer(request[0]); |
890 ASSERT(file != NULL); | 908 ASSERT(file != NULL); |
891 if (!file->IsClosed()) { | 909 if (!file->IsClosed()) { |
892 int64_t byte = CObjectInt32OrInt64ToInt64(request[1]); | 910 int64_t byte = CObjectInt32OrInt64ToInt64(request[1]); |
893 uint8_t buffer = static_cast<uint8_t>(byte & 0xff); | 911 uint8_t buffer = static_cast<uint8_t>(byte & 0xff); |
912 Dart_DisableThreadInterrupter(); | |
894 int64_t bytes_written = file->Write(reinterpret_cast<void*>(&buffer), 1); | 913 int64_t bytes_written = file->Write(reinterpret_cast<void*>(&buffer), 1); |
914 Dart_EnableThreadInterrupter(); | |
895 if (bytes_written > 0) { | 915 if (bytes_written > 0) { |
896 return new CObjectInt64(CObject::NewInt64(bytes_written)); | 916 return new CObjectInt64(CObject::NewInt64(bytes_written)); |
897 } else { | 917 } else { |
898 return CObject::NewOSError(); | 918 return CObject::NewOSError(); |
899 } | 919 } |
900 } else { | 920 } else { |
901 return CObject::FileClosedError(); | 921 return CObject::FileClosedError(); |
902 } | 922 } |
903 } | 923 } |
904 return CObject::IllegalArgumentError(); | 924 return CObject::IllegalArgumentError(); |
905 } | 925 } |
906 | 926 |
907 | 927 |
908 CObject* File::ReadRequest(const CObjectArray& request) { | 928 CObject* File::ReadRequest(const CObjectArray& request) { |
909 if (request.Length() == 2 && | 929 if (request.Length() == 2 && |
910 request[0]->IsIntptr() && | 930 request[0]->IsIntptr() && |
911 request[1]->IsInt32OrInt64()) { | 931 request[1]->IsInt32OrInt64()) { |
912 File* file = CObjectToFilePointer(request[0]); | 932 File* file = CObjectToFilePointer(request[0]); |
913 ASSERT(file != NULL); | 933 ASSERT(file != NULL); |
914 if (!file->IsClosed()) { | 934 if (!file->IsClosed()) { |
915 int64_t length = CObjectInt32OrInt64ToInt64(request[1]); | 935 int64_t length = CObjectInt32OrInt64ToInt64(request[1]); |
916 Dart_CObject* io_buffer = CObject::NewIOBuffer(length); | 936 Dart_CObject* io_buffer = CObject::NewIOBuffer(length); |
917 ASSERT(io_buffer != NULL); | 937 ASSERT(io_buffer != NULL); |
918 uint8_t* data = io_buffer->value.as_external_typed_data.data; | 938 uint8_t* data = io_buffer->value.as_external_typed_data.data; |
939 Dart_DisableThreadInterrupter(); | |
919 int64_t bytes_read = file->Read(data, length); | 940 int64_t bytes_read = file->Read(data, length); |
941 Dart_EnableThreadInterrupter(); | |
920 if (bytes_read >= 0) { | 942 if (bytes_read >= 0) { |
921 CObjectExternalUint8Array* external_array = | 943 CObjectExternalUint8Array* external_array = |
922 new CObjectExternalUint8Array(io_buffer); | 944 new CObjectExternalUint8Array(io_buffer); |
923 external_array->SetLength(bytes_read); | 945 external_array->SetLength(bytes_read); |
924 CObjectArray* result = new CObjectArray(CObject::NewArray(2)); | 946 CObjectArray* result = new CObjectArray(CObject::NewArray(2)); |
925 result->SetAt(0, new CObjectIntptr(CObject::NewInt32(0))); | 947 result->SetAt(0, new CObjectIntptr(CObject::NewInt32(0))); |
926 result->SetAt(1, external_array); | 948 result->SetAt(1, external_array); |
927 return result; | 949 return result; |
928 } else { | 950 } else { |
929 CObject::FreeIOBufferData(io_buffer); | 951 CObject::FreeIOBufferData(io_buffer); |
(...skipping 11 matching lines...) Expand all Loading... | |
941 if (request.Length() == 2 && | 963 if (request.Length() == 2 && |
942 request[0]->IsIntptr() && | 964 request[0]->IsIntptr() && |
943 request[1]->IsInt32OrInt64()) { | 965 request[1]->IsInt32OrInt64()) { |
944 File* file = CObjectToFilePointer(request[0]); | 966 File* file = CObjectToFilePointer(request[0]); |
945 ASSERT(file != NULL); | 967 ASSERT(file != NULL); |
946 if (!file->IsClosed()) { | 968 if (!file->IsClosed()) { |
947 int64_t length = CObjectInt32OrInt64ToInt64(request[1]); | 969 int64_t length = CObjectInt32OrInt64ToInt64(request[1]); |
948 Dart_CObject* io_buffer = CObject::NewIOBuffer(length); | 970 Dart_CObject* io_buffer = CObject::NewIOBuffer(length); |
949 ASSERT(io_buffer != NULL); | 971 ASSERT(io_buffer != NULL); |
950 uint8_t* data = io_buffer->value.as_external_typed_data.data; | 972 uint8_t* data = io_buffer->value.as_external_typed_data.data; |
973 Dart_DisableThreadInterrupter(); | |
951 int64_t bytes_read = file->Read(data, length); | 974 int64_t bytes_read = file->Read(data, length); |
975 Dart_EnableThreadInterrupter(); | |
952 if (bytes_read >= 0) { | 976 if (bytes_read >= 0) { |
953 CObjectExternalUint8Array* external_array = | 977 CObjectExternalUint8Array* external_array = |
954 new CObjectExternalUint8Array(io_buffer); | 978 new CObjectExternalUint8Array(io_buffer); |
955 external_array->SetLength(bytes_read); | 979 external_array->SetLength(bytes_read); |
956 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); | 980 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); |
957 result->SetAt(0, new CObjectIntptr(CObject::NewInt32(0))); | 981 result->SetAt(0, new CObjectIntptr(CObject::NewInt32(0))); |
958 result->SetAt(1, new CObjectInt64(CObject::NewInt64(bytes_read))); | 982 result->SetAt(1, new CObjectInt64(CObject::NewInt64(bytes_read))); |
959 result->SetAt(2, external_array); | 983 result->SetAt(2, external_array); |
960 return result; | 984 return result; |
961 } else { | 985 } else { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1021 int64_t value = CObjectInt32OrInt64ToInt64(array[i + start]); | 1045 int64_t value = CObjectInt32OrInt64ToInt64(array[i + start]); |
1022 buffer_start[i] = static_cast<uint8_t>(value & 0xFF); | 1046 buffer_start[i] = static_cast<uint8_t>(value & 0xFF); |
1023 } else { | 1047 } else { |
1024 // Unsupported type. | 1048 // Unsupported type. |
1025 delete[] buffer_start; | 1049 delete[] buffer_start; |
1026 return CObject::IllegalArgumentError(); | 1050 return CObject::IllegalArgumentError(); |
1027 } | 1051 } |
1028 } | 1052 } |
1029 start = 0; | 1053 start = 0; |
1030 } | 1054 } |
1055 Dart_DisableThreadInterrupter(); | |
1031 int64_t bytes_written = | 1056 int64_t bytes_written = |
1032 file->Write(reinterpret_cast<void*>(buffer_start), length); | 1057 file->Write(reinterpret_cast<void*>(buffer_start), length); |
1058 Dart_EnableThreadInterrupter(); | |
1033 if (!request[1]->IsTypedData()) { | 1059 if (!request[1]->IsTypedData()) { |
1034 delete[] buffer_start; | 1060 delete[] buffer_start; |
1035 } | 1061 } |
1036 if (bytes_written >= 0) { | 1062 if (bytes_written >= 0) { |
1037 return new CObjectInt64(CObject::NewInt64(bytes_written)); | 1063 return new CObjectInt64(CObject::NewInt64(bytes_written)); |
1038 } else { | 1064 } else { |
1039 return CObject::NewOSError(); | 1065 return CObject::NewOSError(); |
1040 } | 1066 } |
1041 } else { | 1067 } else { |
1042 return CObject::FileClosedError(); | 1068 return CObject::FileClosedError(); |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1156 CObjectArray* wrapper = new CObjectArray(CObject::NewArray(2)); | 1182 CObjectArray* wrapper = new CObjectArray(CObject::NewArray(2)); |
1157 wrapper->SetAt(0, new CObjectInt32(CObject::NewInt32(CObject::kSuccess))); | 1183 wrapper->SetAt(0, new CObjectInt32(CObject::NewInt32(CObject::kSuccess))); |
1158 wrapper->SetAt(1, result); | 1184 wrapper->SetAt(1, result); |
1159 return wrapper; | 1185 return wrapper; |
1160 } | 1186 } |
1161 return CObject::IllegalArgumentError(); | 1187 return CObject::IllegalArgumentError(); |
1162 } | 1188 } |
1163 | 1189 |
1164 } // namespace bin | 1190 } // namespace bin |
1165 } // namespace dart | 1191 } // namespace dart |
OLD | NEW |