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

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: fix simarm and other minor changes 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
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 394 matching lines...) Expand 10 before | Expand all | Expand 10 after
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_PeerFinalizer 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 1210 matching lines...) Expand 10 before | Expand all | Expand 10 after
1642 1642
1643 1643
1644 DART_EXPORT Dart_Handle Dart_NewByteArray(intptr_t length) { 1644 DART_EXPORT Dart_Handle Dart_NewByteArray(intptr_t length) {
1645 DARTSCOPE(Isolate::Current()); 1645 DARTSCOPE(Isolate::Current());
1646 const InternalByteArray& obj = 1646 const InternalByteArray& obj =
1647 InternalByteArray::Handle(InternalByteArray::New(length)); 1647 InternalByteArray::Handle(InternalByteArray::New(length));
1648 return Api::NewLocalHandle(obj); 1648 return Api::NewLocalHandle(obj);
1649 } 1649 }
1650 1650
1651 1651
1652 DART_EXPORT Dart_Handle Dart_NewExternalByteArray(uint8_t* data,
1653 intptr_t length,
1654 void* peer,
1655 Dart_PeerFinalizer callback) {
1656 DARTSCOPE(Isolate::Current());
siva 2012/02/11 03:00:58 Should we complain with error messages here for -
cshapiro 2012/02/11 04:11:50 Sure, done. I think it is okay for data to be NUL
1657 const ExternalByteArray& obj =
1658 ExternalByteArray::Handle(ExternalByteArray::New(data,
1659 length,
1660 peer,
1661 callback));
1662 return Api::NewLocalHandle(obj);
1663 }
1664
1665
1666 DART_EXPORT Dart_Handle Dart_ExternalByteArrayGetPeer(Dart_Handle object,
1667 void** peer) {
1668 DARTSCOPE(Isolate::Current());
1669 const ExternalByteArray& array =
1670 Api::UnwrapExternalByteArrayHandle(object);
1671 if (array.IsNull()) {
1672 RETURN_TYPE_ERROR(object, ExternalByteArray);
1673 }
1674 if (peer == NULL) {
1675 return Api::NewError("%s expects argument 'peer' to be non-null.",
1676 CURRENT_FUNC);
1677 }
1678 *peer = array.GetPeer();
1679 return Api::Success();
1680 }
1681
1682
1652 // --- Closures --- 1683 // --- Closures ---
1653 1684
1654 1685
1655 DART_EXPORT bool Dart_IsClosure(Dart_Handle object) { 1686 DART_EXPORT bool Dart_IsClosure(Dart_Handle object) {
1656 DARTSCOPE(Isolate::Current()); 1687 DARTSCOPE(Isolate::Current());
1657 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); 1688 const Object& obj = Object::Handle(Api::UnwrapHandle(object));
1658 return obj.IsClosure(); 1689 return obj.IsClosure();
1659 } 1690 }
1660 1691
1661 1692
(...skipping 770 matching lines...) Expand 10 before | Expand all | Expand 10 after
2432 } 2463 }
2433 delete debug_region; 2464 delete debug_region;
2434 } else { 2465 } else {
2435 *buffer = NULL; 2466 *buffer = NULL;
2436 *buffer_size = 0; 2467 *buffer_size = 0;
2437 } 2468 }
2438 } 2469 }
2439 2470
2440 2471
2441 } // namespace dart 2472 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698