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

Side by Side 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: 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/dart_api_message.h ('k') | runtime/vm/snapshot.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 "vm/dart_api_message.h" 5 #include "vm/dart_api_message.h"
6 #include "vm/object.h" 6 #include "vm/object.h"
7 #include "vm/object_store.h" 7 #include "vm/object_store.h"
8 8
9 namespace dart { 9 namespace dart {
10 10
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 // up to this area. 93 // up to this area.
94 Dart_CObject* value = 94 Dart_CObject* value =
95 reinterpret_cast<Dart_CObject*>( 95 reinterpret_cast<Dart_CObject*>(
96 alloc_(NULL, 0, sizeof(Dart_CObject) + length + 1)); 96 alloc_(NULL, 0, sizeof(Dart_CObject) + length + 1));
97 value->value.as_string = reinterpret_cast<char*>(value) + sizeof(*value); 97 value->value.as_string = reinterpret_cast<char*>(value) + sizeof(*value);
98 value->type = Dart_CObject::kString; 98 value->type = Dart_CObject::kString;
99 return value; 99 return value;
100 } 100 }
101 101
102 102
103 Dart_CObject* ApiMessageReader::AllocateDartCObjectByteArray(intptr_t length) {
104 // Allocate a Dart_CObject structure followed by an array of bytes
105 // for the byte array content. The pointer to the byte array content
106 // is set up to this area.
107 Dart_CObject* value =
108 reinterpret_cast<Dart_CObject*>(
109 alloc_(NULL, 0, sizeof(Dart_CObject) + length + 1));
siva 2012/02/09 01:58:57 (sizeof(Dart_Cobject) + length + 1) what is the +
Søren Gjesse 2012/02/09 09:34:16 Removed the + 1 (copy/paset from string allocation
110 value->type = Dart_CObject::kByteArray;
111 value->value.as_array.length = length;
112 if (length > 0) {
113 value->value.as_byte_array.values =
114 reinterpret_cast<uint8_t*>(value) + sizeof(*value);
115 } else {
116 value->value.as_byte_array.values = NULL;
117 }
118 return value;
119 }
120
121
103 Dart_CObject* ApiMessageReader::AllocateDartCObjectArray(intptr_t length) { 122 Dart_CObject* ApiMessageReader::AllocateDartCObjectArray(intptr_t length) {
104 // Allocate a Dart_CObject structure followed by an array of 123 // Allocate a Dart_CObject structure followed by an array of
105 // pointers to Dart_CObject structures. The pointer to the array 124 // pointers to Dart_CObject structures. The pointer to the array
106 // content is set up to this area. 125 // content is set up to this area.
107 Dart_CObject* value = 126 Dart_CObject* value =
108 reinterpret_cast<Dart_CObject*>( 127 reinterpret_cast<Dart_CObject*>(
109 alloc_(NULL, 0, sizeof(Dart_CObject) + length * sizeof(value))); 128 alloc_(NULL, 0, sizeof(Dart_CObject) + length * sizeof(value)));
110 value->type = Dart_CObject::kArray; 129 value->type = Dart_CObject::kArray;
111 value->value.as_array.length = length; 130 value->value.as_array.length = length;
112 if (length > 0) { 131 if (length > 0) {
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 break; 209 break;
191 } 210 }
192 case ObjectStore::kTwoByteStringClass: 211 case ObjectStore::kTwoByteStringClass:
193 // Two byte strings not supported. 212 // Two byte strings not supported.
194 return NULL; 213 return NULL;
195 break; 214 break;
196 case ObjectStore::kFourByteStringClass: 215 case ObjectStore::kFourByteStringClass:
197 // Four byte strings not supported. 216 // Four byte strings not supported.
198 return NULL; 217 return NULL;
199 break; 218 break;
219 case ObjectStore::kInternalByteArrayClass: {
220 intptr_t len = ReadSmiValue();
221 Dart_CObject* object = AllocateDartCObjectByteArray(len);
222 AddBackwardReference(object_id, object);
223 if (len > 0) {
224 uint8_t* p = object->value.as_byte_array.values;
225 for (intptr_t i = 0; i < len; i++) {
226 *p = Read<uint8_t>();
siva 2012/02/09 01:58:57 p[i] = Read<uint8_t>(); would avoid the need for
Søren Gjesse 2012/02/09 09:34:16 Done (for string as well).
227 p++;
228 }
229 }
230 return object;
231 break;
232 }
200 default: 233 default:
201 // Everything else not supported. 234 // Everything else not supported.
202 return NULL; 235 return NULL;
203 } 236 }
204 } 237 }
205 238
206 239
207 Dart_CObject* ApiMessageReader::ReadIndexedObject(intptr_t object_id) { 240 Dart_CObject* ApiMessageReader::ReadIndexedObject(intptr_t object_id) {
208 if (object_id == Object::kNullObject) { 241 if (object_id == Object::kNullObject) {
209 return AllocateDartCObjectNull(); 242 return AllocateDartCObjectNull();
210 } else if (object_id == ObjectStore::kTrueValue) { 243 } else if (object_id == ObjectStore::kTrueValue) {
211 return AllocateDartCObjectBool(true); 244 return AllocateDartCObjectBool(true);
212 } else if (object_id == ObjectStore::kFalseValue) { 245 } else if (object_id == ObjectStore::kFalseValue) {
213 return AllocateDartCObjectBool(false); 246 return AllocateDartCObjectBool(false);
214 } else if (object_id == ObjectStore::kDynamicType || 247 } else if (object_id == ObjectStore::kDynamicType ||
215 object_id == ObjectStore::kDoubleInterface || 248 object_id == ObjectStore::kDoubleInterface ||
216 object_id == ObjectStore::kIntInterface || 249 object_id == ObjectStore::kIntInterface ||
217 object_id == ObjectStore::kBoolInterface || 250 object_id == ObjectStore::kBoolInterface ||
218 object_id == ObjectStore::kStringInterface) { 251 object_id == ObjectStore::kStringInterface ||
252 object_id == ObjectStore::kByteArrayInterface) {
219 // Always return dynamic type (this is only a marker). 253 // Always return dynamic type (this is only a marker).
220 return &dynamic_type_marker; 254 return &dynamic_type_marker;
221 } else { 255 } else {
222 intptr_t index = object_id - kMaxPredefinedObjectIds; 256 intptr_t index = object_id - kMaxPredefinedObjectIds;
223 ASSERT(index < backward_references_.length()); 257 ASSERT(index < backward_references_.length());
224 ASSERT(backward_references_[index] != NULL); 258 ASSERT(backward_references_[index] != NULL);
225 return backward_references_[index]; 259 return backward_references_[index];
226 } 260 }
227 return NULL; 261 return NULL;
228 } 262 }
(...skipping 21 matching lines...) Expand all
250 return ReadObjectImpl(value); 284 return ReadObjectImpl(value);
251 } 285 }
252 286
253 287
254 void ApiMessageReader::AddBackwardReference(intptr_t id, Dart_CObject* obj) { 288 void ApiMessageReader::AddBackwardReference(intptr_t id, Dart_CObject* obj) {
255 ASSERT((id - kMaxPredefinedObjectIds) == backward_references_.length()); 289 ASSERT((id - kMaxPredefinedObjectIds) == backward_references_.length());
256 backward_references_.Add(obj); 290 backward_references_.Add(obj);
257 } 291 }
258 292
259 } // namespace dart 293 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/dart_api_message.h ('k') | runtime/vm/snapshot.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698