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

Side by Side Diff: runtime/vm/dart_api_message.cc

Issue 9372024: Add missing backref collection when reading mint and bigint objects in a native message handler (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 | « no previous file | runtime/vm/snapshot_test.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 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 // TODO(sjesse): Remove this when message serialization format is 183 // TODO(sjesse): Remove this when message serialization format is
184 // updated (currently length is leaked). 184 // updated (currently length is leaked).
185 AddBackwardReference(object_id, NULL); 185 AddBackwardReference(object_id, NULL);
186 Dart_CObject* length = ReadObject(); 186 Dart_CObject* length = ReadObject();
187 ASSERT(length->type == Dart_CObject::kInt32); 187 ASSERT(length->type == Dart_CObject::kInt32);
188 for (int i = 0; i < length->value.as_int32; i++) { 188 for (int i = 0; i < length->value.as_int32; i++) {
189 Dart_CObject* type = ReadObject(); 189 Dart_CObject* type = ReadObject();
190 if (type != &dynamic_type_marker) return NULL; 190 if (type != &dynamic_type_marker) return NULL;
191 } 191 }
192 return &type_arguments_marker; 192 return &type_arguments_marker;
193 break;
194 } 193 }
195 case ObjectStore::kArrayClass: { 194 case ObjectStore::kArrayClass: {
196 intptr_t len = ReadSmiValue(); 195 intptr_t len = ReadSmiValue();
197 Dart_CObject* value = AllocateDartCObjectArray(len); 196 Dart_CObject* value = AllocateDartCObjectArray(len);
198 AddBackwardReference(object_id, value); 197 AddBackwardReference(object_id, value);
199 // Skip type arguments. 198 // Skip type arguments.
200 // TODO(sjesse): Remove this when message serialization format is 199 // TODO(sjesse): Remove this when message serialization format is
201 // updated (currently type_arguments is leaked). 200 // updated (currently type_arguments is leaked).
202 Dart_CObject* type_arguments = ReadObject(); 201 Dart_CObject* type_arguments = ReadObject();
203 if (type_arguments != &type_arguments_marker && 202 if (type_arguments != &type_arguments_marker &&
204 type_arguments->type != Dart_CObject::kNull) { 203 type_arguments->type != Dart_CObject::kNull) {
205 return NULL; 204 return NULL;
206 } 205 }
207 for (int i = 0; i < len; i++) { 206 for (int i = 0; i < len; i++) {
208 value->value.as_array.values[i] = ReadObject(); 207 value->value.as_array.values[i] = ReadObject();
209 } 208 }
210 return value; 209 return value;
211 break;
212 } 210 }
213 case ObjectStore::kMintClass: { 211 case ObjectStore::kMintClass: {
214 int64_t value = Read<int64_t>(); 212 int64_t value = Read<int64_t>();
213 Dart_CObject* object;
215 if (kMinInt32 <= value && value <= kMaxInt32) { 214 if (kMinInt32 <= value && value <= kMaxInt32) {
216 return AllocateDartCObjectInt32(value); 215 object = AllocateDartCObjectInt32(value);
217 } else { 216 } else {
218 return AllocateDartCObjectInt64(value); 217 object = AllocateDartCObjectInt64(value);
219 } 218 }
220 break; 219 AddBackwardReference(object_id, object);
220 return object;
221 } 221 }
222 case ObjectStore::kBigintClass: { 222 case ObjectStore::kBigintClass: {
223 // Read in the hex string representation of the bigint. 223 // Read in the hex string representation of the bigint.
224 intptr_t len = ReadIntptrValue(); 224 intptr_t len = ReadIntptrValue();
225 Dart_CObject* object = AllocateDartCObjectBigint(len); 225 Dart_CObject* object = AllocateDartCObjectBigint(len);
226 AddBackwardReference(object_id, object);
226 char* p = object->value.as_bigint; 227 char* p = object->value.as_bigint;
227 for (intptr_t i = 0; i < len; i++) { 228 for (intptr_t i = 0; i < len; i++) {
228 p[i] = Read<uint8_t>(); 229 p[i] = Read<uint8_t>();
229 } 230 }
230 p[len] = '\0'; 231 p[len] = '\0';
231 return object; 232 return object;
232 break;
233 } 233 }
234 case ObjectStore::kDoubleClass: { 234 case ObjectStore::kDoubleClass: {
235 // Read the double value for the object. 235 // Read the double value for the object.
236 Dart_CObject* object = AllocateDartCObjectDouble(Read<double>()); 236 Dart_CObject* object = AllocateDartCObjectDouble(Read<double>());
237 AddBackwardReference(object_id, object); 237 AddBackwardReference(object_id, object);
238 return object; 238 return object;
239 break;
240 } 239 }
241 case ObjectStore::kOneByteStringClass: { 240 case ObjectStore::kOneByteStringClass: {
242 intptr_t len = ReadSmiValue(); 241 intptr_t len = ReadSmiValue();
243 intptr_t hash = ReadSmiValue(); 242 intptr_t hash = ReadSmiValue();
244 USE(hash); 243 USE(hash);
245 Dart_CObject* object = AllocateDartCObjectString(len); 244 Dart_CObject* object = AllocateDartCObjectString(len);
246 AddBackwardReference(object_id, object); 245 AddBackwardReference(object_id, object);
247 char* p = object->value.as_string; 246 char* p = object->value.as_string;
248 for (intptr_t i = 0; i < len; i++) { 247 for (intptr_t i = 0; i < len; i++) {
249 p[i] = Read<uint8_t>(); 248 p[i] = Read<uint8_t>();
250 } 249 }
251 p[len] = '\0'; 250 p[len] = '\0';
252 return object; 251 return object;
253 break;
254 } 252 }
255 case ObjectStore::kTwoByteStringClass: 253 case ObjectStore::kTwoByteStringClass:
256 // Two byte strings not supported. 254 // Two byte strings not supported.
257 return NULL; 255 return NULL;
258 break;
259 case ObjectStore::kFourByteStringClass: 256 case ObjectStore::kFourByteStringClass:
260 // Four byte strings not supported. 257 // Four byte strings not supported.
261 return NULL; 258 return NULL;
262 break;
263 case ObjectStore::kInternalByteArrayClass: { 259 case ObjectStore::kInternalByteArrayClass: {
264 intptr_t len = ReadSmiValue(); 260 intptr_t len = ReadSmiValue();
265 Dart_CObject* object = AllocateDartCObjectByteArray(len); 261 Dart_CObject* object = AllocateDartCObjectByteArray(len);
266 AddBackwardReference(object_id, object); 262 AddBackwardReference(object_id, object);
267 if (len > 0) { 263 if (len > 0) {
268 uint8_t* p = object->value.as_byte_array.values; 264 uint8_t* p = object->value.as_byte_array.values;
269 for (intptr_t i = 0; i < len; i++) { 265 for (intptr_t i = 0; i < len; i++) {
270 p[i] = Read<uint8_t>(); 266 p[i] = Read<uint8_t>();
271 } 267 }
272 } 268 }
273 return object; 269 return object;
274 break;
275 } 270 }
276 default: 271 default:
277 // Everything else not supported. 272 // Everything else not supported.
278 return NULL; 273 return NULL;
279 } 274 }
280 } 275 }
281 276
282 277
283 Dart_CObject* ApiMessageReader::ReadIndexedObject(intptr_t object_id) { 278 Dart_CObject* ApiMessageReader::ReadIndexedObject(intptr_t object_id) {
284 if (object_id == Object::kNullObject) { 279 if (object_id == Object::kNullObject) {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 return ReadObjectImpl(value); 322 return ReadObjectImpl(value);
328 } 323 }
329 324
330 325
331 void ApiMessageReader::AddBackwardReference(intptr_t id, Dart_CObject* obj) { 326 void ApiMessageReader::AddBackwardReference(intptr_t id, Dart_CObject* obj) {
332 ASSERT((id - kMaxPredefinedObjectIds) == backward_references_.length()); 327 ASSERT((id - kMaxPredefinedObjectIds) == backward_references_.length());
333 backward_references_.Add(obj); 328 backward_references_.Add(obj);
334 } 329 }
335 330
336 } // namespace dart 331 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/snapshot_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698