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

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

Issue 9368049: Add external byte array API and finalize external strings and byte arrays. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: address review comments 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/include/dart_api.h ('k') | runtime/vm/dart_api_impl_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 "include/dart_api.h" 5 #include "include/dart_api.h"
6 6
7 #include "vm/bigint_operations.h" 7 #include "vm/bigint_operations.h"
8 #include "vm/class_finalizer.h" 8 #include "vm/class_finalizer.h"
9 #include "vm/compiler.h" 9 #include "vm/compiler.h"
10 #include "vm/dart.h" 10 #include "vm/dart.h"
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 const Object& old_ref = Object::Handle(Api::UnwrapHandle(object)); 399 const Object& old_ref = Object::Handle(Api::UnwrapHandle(object));
400 PersistentHandle* new_ref = state->persistent_handles().AllocateHandle(); 400 PersistentHandle* new_ref = state->persistent_handles().AllocateHandle();
401 new_ref->set_raw(old_ref); 401 new_ref->set_raw(old_ref);
402 return reinterpret_cast<Dart_Handle>(new_ref); 402 return reinterpret_cast<Dart_Handle>(new_ref);
403 } 403 }
404 404
405 405
406 DART_EXPORT Dart_Handle Dart_NewWeakPersistentHandle( 406 DART_EXPORT Dart_Handle Dart_NewWeakPersistentHandle(
407 Dart_Handle object, 407 Dart_Handle object,
408 void* peer, 408 void* peer,
409 Dart_PeerFinalizer callback) { 409 Dart_WeakPersistentHandleFinalizer callback) {
410 Isolate* isolate = Isolate::Current(); 410 Isolate* isolate = Isolate::Current();
411 CHECK_ISOLATE(isolate); 411 CHECK_ISOLATE(isolate);
412 DARTSCOPE_NOCHECKS(isolate); 412 DARTSCOPE_NOCHECKS(isolate);
413 ApiState* state = isolate->api_state(); 413 ApiState* state = isolate->api_state();
414 ASSERT(state != NULL); 414 ASSERT(state != NULL);
415 const Object& old_ref = Object::Handle(Api::UnwrapHandle(object)); 415 const Object& ref = Object::Handle(Api::UnwrapHandle(object));
416 WeakPersistentHandle* new_ref = 416 WeakPersistentHandle* weak_ref =
417 state->weak_persistent_handles().AllocateHandle(); 417 state->weak_persistent_handles().AllocateHandle();
418 new_ref->set_raw(old_ref); 418 weak_ref->set_raw(ref);
419 new_ref->set_peer(peer); 419 weak_ref->set_peer(peer);
420 new_ref->set_callback(callback); 420 weak_ref->set_callback(callback);
421 return reinterpret_cast<Dart_Handle>(new_ref); 421 return reinterpret_cast<Dart_Handle>(weak_ref);
422 } 422 }
423 423
424 424
425 DART_EXPORT void Dart_DeletePersistentHandle(Dart_Handle object) { 425 DART_EXPORT void Dart_DeletePersistentHandle(Dart_Handle object) {
426 Isolate* isolate = Isolate::Current(); 426 Isolate* isolate = Isolate::Current();
427 CHECK_ISOLATE(isolate); 427 CHECK_ISOLATE(isolate);
428 ApiState* state = isolate->api_state(); 428 ApiState* state = isolate->api_state();
429 ASSERT(state != NULL); 429 ASSERT(state != NULL);
430 if (state->IsValidWeakPersistentHandle(object)) { 430 if (state->IsValidWeakPersistentHandle(object)) {
431 WeakPersistentHandle* weak_ref = 431 WeakPersistentHandle* weak_ref =
(...skipping 771 matching lines...) Expand 10 before | Expand all | Expand 10 after
1203 *peer = str.GetPeer(); 1203 *peer = str.GetPeer();
1204 return Api::Success(); 1204 return Api::Success();
1205 } 1205 }
1206 1206
1207 1207
1208 DART_EXPORT Dart_Handle Dart_NewExternalString8(const uint8_t* codepoints, 1208 DART_EXPORT Dart_Handle Dart_NewExternalString8(const uint8_t* codepoints,
1209 intptr_t length, 1209 intptr_t length,
1210 void* peer, 1210 void* peer,
1211 Dart_PeerFinalizer callback) { 1211 Dart_PeerFinalizer callback) {
1212 DARTSCOPE(Isolate::Current()); 1212 DARTSCOPE(Isolate::Current());
1213 if (codepoints == NULL && length != 0) {
1214 return Api::NewError("%s expects argument 'codepoints' to be non-null.",
1215 CURRENT_FUNC);
1216 }
1217 if (length < 0) {
1218 return Api::NewError("%s expects argument 'length' to be greater than 0.",
1219 CURRENT_FUNC);
1220 }
1213 const String& obj = 1221 const String& obj =
1214 String::Handle(String::NewExternal(codepoints, length, peer, callback)); 1222 String::Handle(String::NewExternal(codepoints, length, peer, callback));
1215 return Api::NewLocalHandle(obj); 1223 return Api::NewLocalHandle(obj);
1216 } 1224 }
1217 1225
1218 1226
1219 DART_EXPORT Dart_Handle Dart_NewExternalString16(const uint16_t* codepoints, 1227 DART_EXPORT Dart_Handle Dart_NewExternalString16(const uint16_t* codepoints,
1220 intptr_t length, 1228 intptr_t length,
1221 void* peer, 1229 void* peer,
1222 Dart_PeerFinalizer callback) { 1230 Dart_PeerFinalizer callback) {
1223 DARTSCOPE(Isolate::Current()); 1231 DARTSCOPE(Isolate::Current());
1232 if (codepoints == NULL && length != 0) {
1233 return Api::NewError("%s expects argument 'codepoints' to be non-null.",
1234 CURRENT_FUNC);
1235 }
1236 if (length < 0) {
1237 return Api::NewError("%s expects argument 'length' to be greater than 0.",
1238 CURRENT_FUNC);
1239 }
1224 const String& obj = 1240 const String& obj =
1225 String::Handle(String::NewExternal(codepoints, length, peer, callback)); 1241 String::Handle(String::NewExternal(codepoints, length, peer, callback));
1226 return Api::NewLocalHandle(obj); 1242 return Api::NewLocalHandle(obj);
1227 } 1243 }
1228 1244
1229 1245
1230 DART_EXPORT Dart_Handle Dart_NewExternalString32(const uint32_t* codepoints, 1246 DART_EXPORT Dart_Handle Dart_NewExternalString32(const uint32_t* codepoints,
1231 intptr_t length, 1247 intptr_t length,
1232 void* peer, 1248 void* peer,
1233 Dart_PeerFinalizer callback) { 1249 Dart_PeerFinalizer callback) {
1234 DARTSCOPE(Isolate::Current()); 1250 DARTSCOPE(Isolate::Current());
1251 if (codepoints == NULL && length != 0) {
1252 return Api::NewError("%s expects argument 'codepoints' to be non-null.",
1253 CURRENT_FUNC);
1254 }
1255 if (length < 0) {
1256 return Api::NewError("%s expects argument 'length' to be greater than 0.",
1257 CURRENT_FUNC);
1258 }
1235 const String& obj = 1259 const String& obj =
1236 String::Handle(String::NewExternal(codepoints, length, peer, callback)); 1260 String::Handle(String::NewExternal(codepoints, length, peer, callback));
1237 return Api::NewLocalHandle(obj); 1261 return Api::NewLocalHandle(obj);
1238 } 1262 }
1239 1263
1240 1264
1241 DART_EXPORT Dart_Handle Dart_StringGet8(Dart_Handle str, 1265 DART_EXPORT Dart_Handle Dart_StringGet8(Dart_Handle str,
1242 uint8_t* codepoints, 1266 uint8_t* codepoints,
1243 intptr_t* length) { 1267 intptr_t* length) {
1244 DARTSCOPE(Isolate::Current()); 1268 DARTSCOPE(Isolate::Current());
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after
1642 1666
1643 1667
1644 DART_EXPORT Dart_Handle Dart_NewByteArray(intptr_t length) { 1668 DART_EXPORT Dart_Handle Dart_NewByteArray(intptr_t length) {
1645 DARTSCOPE(Isolate::Current()); 1669 DARTSCOPE(Isolate::Current());
1646 const InternalByteArray& obj = 1670 const InternalByteArray& obj =
1647 InternalByteArray::Handle(InternalByteArray::New(length)); 1671 InternalByteArray::Handle(InternalByteArray::New(length));
1648 return Api::NewLocalHandle(obj); 1672 return Api::NewLocalHandle(obj);
1649 } 1673 }
1650 1674
1651 1675
1676 DART_EXPORT Dart_Handle Dart_NewExternalByteArray(uint8_t* data,
1677 intptr_t length,
1678 void* peer,
1679 Dart_PeerFinalizer callback) {
1680 DARTSCOPE(Isolate::Current());
1681 if (data == NULL && length != 0) {
1682 return Api::NewError("%s expects argument 'data' to be non-null.",
1683 CURRENT_FUNC);
1684 }
1685 if (length < 0) {
1686 return Api::NewError("%s expects argument 'length' to be greater than 0.",
1687 CURRENT_FUNC);
1688 }
1689 const ExternalByteArray& obj =
1690 ExternalByteArray::Handle(ExternalByteArray::New(data,
1691 length,
1692 peer,
1693 callback));
1694 return Api::NewLocalHandle(obj);
1695 }
1696
1697
1698 DART_EXPORT Dart_Handle Dart_ExternalByteArrayGetPeer(Dart_Handle object,
1699 void** peer) {
1700 DARTSCOPE(Isolate::Current());
1701 const ExternalByteArray& array =
1702 Api::UnwrapExternalByteArrayHandle(object);
1703 if (array.IsNull()) {
1704 RETURN_TYPE_ERROR(object, ExternalByteArray);
1705 }
1706 if (peer == NULL) {
1707 return Api::NewError("%s expects argument 'peer' to be non-null.",
1708 CURRENT_FUNC);
1709 }
1710 *peer = array.GetPeer();
1711 return Api::Success();
1712 }
1713
1714
1652 // --- Closures --- 1715 // --- Closures ---
1653 1716
1654 1717
1655 DART_EXPORT bool Dart_IsClosure(Dart_Handle object) { 1718 DART_EXPORT bool Dart_IsClosure(Dart_Handle object) {
1656 DARTSCOPE(Isolate::Current()); 1719 DARTSCOPE(Isolate::Current());
1657 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); 1720 const Object& obj = Object::Handle(Api::UnwrapHandle(object));
1658 return obj.IsClosure(); 1721 return obj.IsClosure();
1659 } 1722 }
1660 1723
1661 1724
(...skipping 770 matching lines...) Expand 10 before | Expand all | Expand 10 after
2432 } 2495 }
2433 delete debug_region; 2496 delete debug_region;
2434 } else { 2497 } else {
2435 *buffer = NULL; 2498 *buffer = NULL;
2436 *buffer_size = 0; 2499 *buffer_size = 0;
2437 } 2500 }
2438 } 2501 }
2439 2502
2440 2503
2441 } // namespace dart 2504 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/include/dart_api.h ('k') | runtime/vm/dart_api_impl_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698