Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(135)

Unified Diff: runtime/bin/file.cc

Issue 18115002: Make writes consistent across socket and file synchronous/asynchronus writes in terms of truncation… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/bin/common_patch.dart ('k') | runtime/bin/io_impl_sources.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/file.cc
===================================================================
--- runtime/bin/file.cc (revision 24619)
+++ runtime/bin/file.cc (working copy)
@@ -254,8 +254,9 @@
Dart_EnterScope();
File* file = GetFilePointer(Dart_GetNativeArgument(args, 0));
ASSERT(file != NULL);
+
Dart_Handle buffer_obj = Dart_GetNativeArgument(args, 1);
- ASSERT(Dart_IsList(buffer_obj));
+
// Offset and length arguments are checked in Dart code to be
// integers and have the property that (offset + length) <=
// list.length. Therefore, it is safe to extract their value as
@@ -264,24 +265,33 @@
DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 2));
intptr_t end =
DartUtils::GetIntptrValue(Dart_GetNativeArgument(args, 3));
+
+ // The buffer object passed in has to be an Int8List or Uint8List object.
+ // Acquire a direct pointer to the data area of the buffer object.
+ Dart_TypedData_Type type;
intptr_t length = end - start;
intptr_t buffer_len = 0;
- Dart_Handle result = Dart_ListLength(buffer_obj, &buffer_len);
+ void* buffer = NULL;
+ Dart_Handle result =
+ Dart_TypedDataAcquireData(buffer_obj, &type, &buffer, &buffer_len);
if (Dart_IsError(result)) Dart_PropagateError(result);
+
+ ASSERT(type == Dart_TypedData_kUint8 || type == Dart_TypedData_kInt8);
ASSERT(end <= buffer_len);
- uint8_t* buffer = new uint8_t[length];
- result = Dart_ListGetAsBytes(buffer_obj, start, buffer, length);
- if (Dart_IsError(result)) {
- delete[] buffer;
- Dart_PropagateError(result);
- }
+ ASSERT(buffer != NULL);
+
+ // Write the data out into the file.
int64_t bytes_written = file->Write(reinterpret_cast<void*>(buffer), length);
+
+ // Release the direct pointer acquired above.
+ result = Dart_TypedDataReleaseData(buffer_obj);
+ if (Dart_IsError(result)) Dart_PropagateError(result);
+
if (bytes_written != length) {
Dart_Handle err = DartUtils::NewDartOSError();
if (Dart_IsError(err)) Dart_PropagateError(err);
Dart_SetReturnValue(args, err);
}
- delete[] buffer;
Dart_ExitScope();
}
« no previous file with comments | « runtime/bin/common_patch.dart ('k') | runtime/bin/io_impl_sources.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698