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

Unified Diff: runtime/bin/file.cc

Issue 10698011: Support posting of external data into dart as external uint8 arrays through the Dart API. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 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
Index: runtime/bin/file.cc
diff --git a/runtime/bin/file.cc b/runtime/bin/file.cc
index ecc3cc70445c90cd4558c5152335d3630b9fb667..7b3edb62618ea7ecec8ec635e32e6192ffe4671e 100644
--- a/runtime/bin/file.cc
+++ b/runtime/bin/file.cc
@@ -774,6 +774,11 @@ static CObject* FileWriteByteRequest(const CObjectArray& request) {
}
+static void FinalizeExternalByteArray(void* peer) {
+ delete[] reinterpret_cast<uint8_t*>(peer);
+}
+
+
static CObject* FileReadListRequest(const CObjectArray& request) {
if (request.Length() == 3 &&
request[1]->IsIntptr() &&
@@ -782,15 +787,20 @@ static CObject* FileReadListRequest(const CObjectArray& request) {
ASSERT(file != NULL);
if (!file->IsClosed()) {
int64_t length = CObjectInt32OrInt64ToInt64(request[2]);
- CObjectUint8Array* byte_array =
- new CObjectUint8Array(CObject::NewUint8Array(length));
- void* buffer = reinterpret_cast<void*>(byte_array->Buffer());
- int bytes_read = file->Read(buffer, byte_array->Length());
+ uint8_t* buffer = new uint8_t[length];
+ int bytes_read = file->Read(buffer, length);
if (bytes_read >= 0) {
+ void* peer = reinterpret_cast<void*>(buffer);
+ CObject* external_array =
+ new CObjectExternalUint8Array(
+ CObject::NewExternalUint8Array(length,
+ buffer,
+ peer,
+ FinalizeExternalByteArray));
CObjectArray* result = new CObjectArray(CObject::NewArray(3));
result->SetAt(0, new CObjectIntptr(CObject::NewInt32(0)));
result->SetAt(1, new CObjectIntptr(CObject::NewIntptr(bytes_read)));
- result->SetAt(2, byte_array);
+ result->SetAt(2, external_array);
return result;
} else {
return CObject::NewOSError();

Powered by Google App Engine
This is Rietveld 408576698