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

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

Issue 1267603003: Support sending and receiving Capability objects from C code. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 4 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
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/snapshot_ids.h" 7 #include "vm/snapshot_ids.h"
8 #include "vm/symbols.h" 8 #include "vm/symbols.h"
9 #include "vm/unicode.h" 9 #include "vm/unicode.h"
10 10
(...skipping 663 matching lines...) Expand 10 before | Expand all | Expand 10 after
674 } 674 }
675 case kSendPortCid: { 675 case kSendPortCid: {
676 int64_t value64 = Read<int64_t>(); 676 int64_t value64 = Read<int64_t>();
677 int64_t originId = Read<uint64_t>(); 677 int64_t originId = Read<uint64_t>();
678 Dart_CObject* object = AllocateDartCObject(Dart_CObject_kSendPort); 678 Dart_CObject* object = AllocateDartCObject(Dart_CObject_kSendPort);
679 object->value.as_send_port.id = value64; 679 object->value.as_send_port.id = value64;
680 object->value.as_send_port.origin_id = originId; 680 object->value.as_send_port.origin_id = originId;
681 AddBackRef(object_id, object, kIsDeserialized); 681 AddBackRef(object_id, object, kIsDeserialized);
682 return object; 682 return object;
683 } 683 }
684 case kCapabilityCid: {
685 int64_t id = Read<int64_t>();
686 Dart_CObject* object = AllocateDartCObject(Dart_CObject_kCapability);
687 object->value.as_capability.id = id;
688 AddBackRef(object_id, object, kIsDeserialized);
689 return object;
690 }
684 691
685 #define READ_TYPED_DATA_HEADER(type) \ 692 #define READ_TYPED_DATA_HEADER(type) \
686 intptr_t len = ReadSmiValue(); \ 693 intptr_t len = ReadSmiValue(); \
687 Dart_CObject* object = \ 694 Dart_CObject* object = \
688 AllocateDartCObjectTypedData(Dart_TypedData_k##type, len); \ 695 AllocateDartCObjectTypedData(Dart_TypedData_k##type, len); \
689 AddBackRef(object_id, object, kIsDeserialized); \ 696 AddBackRef(object_id, object, kIsDeserialized); \
690 697
691 698
692 #define READ_TYPED_DATA(type, ctype) \ 699 #define READ_TYPED_DATA(type, ctype) \
693 { \ 700 { \
(...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after
1261 uint8_t* data = object->value.as_external_typed_data.data; 1268 uint8_t* data = object->value.as_external_typed_data.data;
1262 void* peer = object->value.as_external_typed_data.peer; 1269 void* peer = object->value.as_external_typed_data.peer;
1263 Dart_WeakPersistentHandleFinalizer callback = 1270 Dart_WeakPersistentHandleFinalizer callback =
1264 object->value.as_external_typed_data.callback; 1271 object->value.as_external_typed_data.callback;
1265 WriteSmi(length); 1272 WriteSmi(length);
1266 WriteRawPointerValue(reinterpret_cast<intptr_t>(data)); 1273 WriteRawPointerValue(reinterpret_cast<intptr_t>(data));
1267 WriteRawPointerValue(reinterpret_cast<intptr_t>(peer)); 1274 WriteRawPointerValue(reinterpret_cast<intptr_t>(peer));
1268 WriteRawPointerValue(reinterpret_cast<intptr_t>(callback)); 1275 WriteRawPointerValue(reinterpret_cast<intptr_t>(callback));
1269 break; 1276 break;
1270 } 1277 }
1278 case Dart_CObject_kCapability: {
1279 WriteInlinedHeader(object);
1280 WriteIndexedObject(kCapabilityCid);
1281 WriteTags(0);
1282 Write<uint64_t>(object->value.as_capability.id);
1283 break;
1284 }
1271 default: 1285 default:
1272 UNREACHABLE(); 1286 UNREACHABLE();
1273 } 1287 }
1274 1288
1275 return true; 1289 return true;
1276 } 1290 }
1277 1291
1278 1292
1279 bool ApiMessageWriter::WriteCMessage(Dart_CObject* object) { 1293 bool ApiMessageWriter::WriteCMessage(Dart_CObject* object) {
1280 bool success = WriteCObject(object); 1294 bool success = WriteCObject(object);
1281 if (!success) { 1295 if (!success) {
1282 UnmarkAllCObjects(object); 1296 UnmarkAllCObjects(object);
1283 return false; 1297 return false;
1284 } 1298 }
1285 // Write out all objects that were added to the forward list and have 1299 // Write out all objects that were added to the forward list and have
1286 // not been serialized yet. These would typically be fields of arrays. 1300 // not been serialized yet. These would typically be fields of arrays.
1287 // NOTE: The forward list might grow as we process the list. 1301 // NOTE: The forward list might grow as we process the list.
1288 for (intptr_t i = 0; i < forward_id_; i++) { 1302 for (intptr_t i = 0; i < forward_id_; i++) {
1289 success = WriteForwardedCObject(forward_list_[i]); 1303 success = WriteForwardedCObject(forward_list_[i]);
1290 if (!success) { 1304 if (!success) {
1291 UnmarkAllCObjects(object); 1305 UnmarkAllCObjects(object);
1292 return false; 1306 return false;
1293 } 1307 }
1294 } 1308 }
1295 UnmarkAllCObjects(object); 1309 UnmarkAllCObjects(object);
1296 return true; 1310 return true;
1297 } 1311 }
1298 1312
1299 } // namespace dart 1313 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698