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

Unified Diff: runtime/vm/dart_api_message.cc

Issue 9348019: Add support for byte arrays to native messages (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed review comments from asiva@ Created 8 years, 10 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/vm/dart_api_message.h ('k') | runtime/vm/dart_api_state.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/dart_api_message.cc
diff --git a/runtime/vm/dart_api_message.cc b/runtime/vm/dart_api_message.cc
index cef65c67e1b7dcba785bc5d613ed87adaa6799f4..d5f2e69d77bd4af57603a0de4fb1e5e0daa59104 100644
--- a/runtime/vm/dart_api_message.cc
+++ b/runtime/vm/dart_api_message.cc
@@ -56,6 +56,7 @@ intptr_t ApiMessageReader::LookupInternalClass(intptr_t class_header) {
Dart_CObject* ApiMessageReader::AllocateDartCObject(Dart_CObject::Type type) {
Dart_CObject* value =
reinterpret_cast<Dart_CObject*>(alloc_(NULL, 0, sizeof(Dart_CObject)));
+ ASSERT(value != NULL);
value->type = type;
return value;
}
@@ -94,12 +95,33 @@ Dart_CObject* ApiMessageReader::AllocateDartCObjectString(intptr_t length) {
Dart_CObject* value =
reinterpret_cast<Dart_CObject*>(
alloc_(NULL, 0, sizeof(Dart_CObject) + length + 1));
+ ASSERT(value != NULL);
value->value.as_string = reinterpret_cast<char*>(value) + sizeof(*value);
value->type = Dart_CObject::kString;
return value;
}
+Dart_CObject* ApiMessageReader::AllocateDartCObjectByteArray(intptr_t length) {
+ // Allocate a Dart_CObject structure followed by an array of bytes
+ // for the byte array content. The pointer to the byte array content
+ // is set up to this area.
+ Dart_CObject* value =
+ reinterpret_cast<Dart_CObject*>(
+ alloc_(NULL, 0, sizeof(Dart_CObject) + length));
+ ASSERT(value != NULL);
+ value->type = Dart_CObject::kByteArray;
+ value->value.as_array.length = length;
+ if (length > 0) {
+ value->value.as_byte_array.values =
+ reinterpret_cast<uint8_t*>(value) + sizeof(*value);
+ } else {
+ value->value.as_byte_array.values = NULL;
+ }
+ return value;
+}
+
+
Dart_CObject* ApiMessageReader::AllocateDartCObjectArray(intptr_t length) {
// Allocate a Dart_CObject structure followed by an array of
// pointers to Dart_CObject structures. The pointer to the array
@@ -107,6 +129,7 @@ Dart_CObject* ApiMessageReader::AllocateDartCObjectArray(intptr_t length) {
Dart_CObject* value =
reinterpret_cast<Dart_CObject*>(
alloc_(NULL, 0, sizeof(Dart_CObject) + length * sizeof(value)));
+ ASSERT(value != NULL);
value->type = Dart_CObject::kArray;
value->value.as_array.length = length;
if (length > 0) {
@@ -182,10 +205,9 @@ Dart_CObject* ApiMessageReader::ReadInlinedObject(intptr_t object_id) {
AddBackwardReference(object_id, object);
char* p = object->value.as_string;
for (intptr_t i = 0; i < len; i++) {
- *p = Read<uint8_t>();
- p++;
+ p[i] = Read<uint8_t>();
}
- *p = '\0';
+ p[len] = '\0';
return object;
break;
}
@@ -197,6 +219,19 @@ Dart_CObject* ApiMessageReader::ReadInlinedObject(intptr_t object_id) {
// Four byte strings not supported.
return NULL;
break;
+ case ObjectStore::kInternalByteArrayClass: {
+ intptr_t len = ReadSmiValue();
+ Dart_CObject* object = AllocateDartCObjectByteArray(len);
+ AddBackwardReference(object_id, object);
+ if (len > 0) {
+ uint8_t* p = object->value.as_byte_array.values;
+ for (intptr_t i = 0; i < len; i++) {
+ p[i] = Read<uint8_t>();
+ }
+ }
+ return object;
+ break;
+ }
default:
// Everything else not supported.
return NULL;
@@ -215,7 +250,8 @@ Dart_CObject* ApiMessageReader::ReadIndexedObject(intptr_t object_id) {
object_id == ObjectStore::kDoubleInterface ||
object_id == ObjectStore::kIntInterface ||
object_id == ObjectStore::kBoolInterface ||
- object_id == ObjectStore::kStringInterface) {
+ object_id == ObjectStore::kStringInterface ||
+ object_id == ObjectStore::kByteArrayInterface) {
// Always return dynamic type (this is only a marker).
return &dynamic_type_marker;
} else {
« no previous file with comments | « runtime/vm/dart_api_message.h ('k') | runtime/vm/dart_api_state.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698