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

Unified Diff: runtime/bin/file.cc

Issue 11438045: Make all allocation of external arrays used for IO use the IOBuffer class (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years 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/dartutils.cc ('k') | runtime/bin/io_buffer.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/file.cc
diff --git a/runtime/bin/file.cc b/runtime/bin/file.cc
index 2bbbd2c81e554209d67f255fb7621ff8113a3e8a..bd32b5b5dc94b5635c940de870a91364088c3140 100644
--- a/runtime/bin/file.cc
+++ b/runtime/bin/file.cc
@@ -779,11 +779,6 @@ static CObject* FileWriteByteRequest(const CObjectArray& request) {
}
-static void FinalizeExternalByteArray(void* peer) {
- delete[] reinterpret_cast<uint8_t*>(peer);
-}
-
-
static CObject* FileReadRequest(const CObjectArray& request) {
if (request.Length() == 3 &&
request[1]->IsIntptr() &&
@@ -792,21 +787,19 @@ static CObject* FileReadRequest(const CObjectArray& request) {
ASSERT(file != NULL);
if (!file->IsClosed()) {
int64_t length = CObjectInt32OrInt64ToInt64(request[2]);
- uint8_t* buffer = new uint8_t[length];
- int64_t bytes_read = file->Read(buffer, length);
+ Dart_CObject* io_buffer = CObject::NewIOBuffer(length);
+ uint8_t* data = io_buffer->value.as_external_byte_array.data;
+ int64_t bytes_read = file->Read(data, length);
if (bytes_read >= 0) {
- void* peer = reinterpret_cast<void*>(buffer);
- CObject* external_array =
- new CObjectExternalUint8Array(
- CObject::NewExternalUint8Array(bytes_read,
- buffer,
- peer,
- FinalizeExternalByteArray));
+ CObjectExternalUint8Array* external_array =
+ new CObjectExternalUint8Array(io_buffer);
+ external_array->SetLength(bytes_read);
CObjectArray* result = new CObjectArray(CObject::NewArray(2));
result->SetAt(0, new CObjectIntptr(CObject::NewInt32(0)));
result->SetAt(1, external_array);
return result;
} else {
+ CObject::FreeIOBufferData(io_buffer);
return CObject::NewOSError();
}
} else {
@@ -825,22 +818,20 @@ static CObject* FileReadListRequest(const CObjectArray& request) {
ASSERT(file != NULL);
if (!file->IsClosed()) {
int64_t length = CObjectInt32OrInt64ToInt64(request[2]);
- uint8_t* buffer = new uint8_t[length];
- int64_t bytes_read = file->Read(buffer, length);
+ Dart_CObject* io_buffer = CObject::NewIOBuffer(length);
+ uint8_t* data = io_buffer->value.as_external_byte_array.data;
+ int64_t bytes_read = file->Read(data, length);
if (bytes_read >= 0) {
- void* peer = reinterpret_cast<void*>(buffer);
- CObject* external_array =
- new CObjectExternalUint8Array(
- CObject::NewExternalUint8Array(length,
- buffer,
- peer,
- FinalizeExternalByteArray));
+ CObjectExternalUint8Array* external_array =
+ new CObjectExternalUint8Array(io_buffer);
+ external_array->SetLength(bytes_read);
CObjectArray* result = new CObjectArray(CObject::NewArray(3));
result->SetAt(0, new CObjectIntptr(CObject::NewInt32(0)));
result->SetAt(1, new CObjectInt64(CObject::NewInt64(bytes_read)));
result->SetAt(2, external_array);
return result;
} else {
+ CObject::FreeIOBufferData(io_buffer);
return CObject::NewOSError();
}
} else {
« no previous file with comments | « runtime/bin/dartutils.cc ('k') | runtime/bin/io_buffer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698