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

Side by Side Diff: runtime/include/dart_api.h

Issue 15772005: - Add different types for persistent and weak persistent handles (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 7 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/bin/secure_socket.cc ('k') | runtime/lib/mirrors.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 #ifndef INCLUDE_DART_API_H_ 5 #ifndef INCLUDE_DART_API_H_
6 #define INCLUDE_DART_API_H_ 6 #define INCLUDE_DART_API_H_
7 7
8 /** \mainpage Dart Embedding API Reference 8 /** \mainpage Dart Embedding API Reference
9 * 9 *
10 * Dart is a class-based programming language for creating structured 10 * Dart is a class-based programming language for creating structured
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 * Dart_EnterScope) and go away when the current scope exits. Unless 169 * Dart_EnterScope) and go away when the current scope exits. Unless
170 * otherwise indicated, callers should assume that all functions in 170 * otherwise indicated, callers should assume that all functions in
171 * the Dart embedding api return local handles. 171 * the Dart embedding api return local handles.
172 * 172 *
173 * Persistent handles are allocated within the current isolate. They 173 * Persistent handles are allocated within the current isolate. They
174 * can be used to store objects across scopes. Persistent handles have 174 * can be used to store objects across scopes. Persistent handles have
175 * the lifetime of the current isolate unless they are explicitly 175 * the lifetime of the current isolate unless they are explicitly
176 * deallocated (see Dart_DeletePersistentHandle). 176 * deallocated (see Dart_DeletePersistentHandle).
177 */ 177 */
178 typedef struct _Dart_Handle* Dart_Handle; 178 typedef struct _Dart_Handle* Dart_Handle;
179 typedef struct _Dart_PersistentHandle* Dart_PersistentHandle;
180 typedef struct _Dart_WeakPersistentHandle* Dart_WeakPersistentHandle;
179 181
180 typedef void (*Dart_WeakPersistentHandleFinalizer)(Dart_Handle handle, 182 typedef void (*Dart_WeakPersistentHandleFinalizer)(
181 void* peer); 183 Dart_WeakPersistentHandle handle,
184 void* peer);
182 typedef void (*Dart_PeerFinalizer)(void* peer); 185 typedef void (*Dart_PeerFinalizer)(void* peer);
183 186
184 /** 187 /**
185 * Is this an error handle? 188 * Is this an error handle?
186 * 189 *
187 * Requires there to be a current isolate. 190 * Requires there to be a current isolate.
188 */ 191 */
189 DART_EXPORT bool Dart_IsError(Dart_Handle handle); 192 DART_EXPORT bool Dart_IsError(Dart_Handle handle);
190 193
191 /** 194 /**
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 * 356 *
354 * This is equivalent to using the triple-equals (===) operator. 357 * This is equivalent to using the triple-equals (===) operator.
355 * 358 *
356 * \param obj1 An object to be compared. 359 * \param obj1 An object to be compared.
357 * \param obj2 An object to be compared. 360 * \param obj2 An object to be compared.
358 * 361 *
359 * \return True if the objects are identically equal. False otherwise. 362 * \return True if the objects are identically equal. False otherwise.
360 */ 363 */
361 DART_EXPORT bool Dart_IdentityEquals(Dart_Handle obj1, Dart_Handle obj2); 364 DART_EXPORT bool Dart_IdentityEquals(Dart_Handle obj1, Dart_Handle obj2);
362 365
366 DART_EXPORT Dart_Handle Dart_NewHandleFromPersistent(Dart_PersistentHandle objec t);
367 DART_EXPORT Dart_Handle Dart_NewHandleFromWeakPersistent(Dart_WeakPersistentHand le object);
368
363 /** 369 /**
364 * Allocates a persistent handle for an object. 370 * Allocates a persistent handle for an object.
365 * 371 *
366 * This handle has the lifetime of the current isolate unless it is 372 * This handle has the lifetime of the current isolate unless it is
367 * explicitly deallocated by calling Dart_DeletePersistentHandle. 373 * explicitly deallocated by calling Dart_DeletePersistentHandle.
368 * 374 *
369 * Requires there to be a current isolate. 375 * Requires there to be a current isolate.
370 */ 376 */
371 DART_EXPORT Dart_Handle Dart_NewPersistentHandle(Dart_Handle object); 377 DART_EXPORT Dart_PersistentHandle Dart_NewPersistentHandle(Dart_Handle object);
372 378
373 /** 379 /**
374 * Deallocates a persistent handle. 380 * Deallocates a persistent handle.
375 * 381 *
376 * Requires there to be a current isolate. 382 * Requires there to be a current isolate.
377 */ 383 */
378 DART_EXPORT void Dart_DeletePersistentHandle(Dart_Handle object); 384 DART_EXPORT void Dart_DeletePersistentHandle(Dart_PersistentHandle object);
379 385
380 /** 386 /**
381 * Allocates a weak persistent handle for an object. 387 * Allocates a weak persistent handle for an object.
382 * 388 *
383 * This handle has the lifetime of the current isolate unless it is 389 * This handle has the lifetime of the current isolate unless it is
384 * explicitly deallocated by calling Dart_DeletePersistentHandle. 390 * explicitly deallocated by calling Dart_DeletePersistentHandle.
385 * 391 *
386 * Requires there to be a current isolate. 392 * Requires there to be a current isolate.
387 * 393 *
388 * \param object An object. 394 * \param object An object.
389 * \param peer A pointer to a native object or NULL. This value is 395 * \param peer A pointer to a native object or NULL. This value is
390 * provided to callback when it is invoked. 396 * provided to callback when it is invoked.
391 * \param callback A function pointer that will be invoked sometime 397 * \param callback A function pointer that will be invoked sometime
392 * after the object is garbage collected. 398 * after the object is garbage collected.
393 * 399 *
394 * \return Success if the weak persistent handle was 400 * \return Success if the weak persistent handle was
395 * created. Otherwise, returns an error. 401 * created. Otherwise, returns an error.
396 */ 402 */
397 DART_EXPORT Dart_Handle Dart_NewWeakPersistentHandle( 403 DART_EXPORT Dart_WeakPersistentHandle Dart_NewWeakPersistentHandle(
398 Dart_Handle object, 404 Dart_Handle object,
399 void* peer, 405 void* peer,
400 Dart_WeakPersistentHandleFinalizer callback); 406 Dart_WeakPersistentHandleFinalizer callback);
401 407
408 DART_EXPORT void Dart_DeleteWeakPersistentHandle(Dart_WeakPersistentHandle objec t);
409
402 /** 410 /**
403 * Is this object a weak persistent handle? 411 * Is this object a weak persistent handle?
404 * 412 *
405 * Requires there to be a current isolate. 413 * Requires there to be a current isolate.
406 */ 414 */
407 DART_EXPORT bool Dart_IsWeakPersistentHandle(Dart_Handle object); 415 DART_EXPORT bool Dart_IsWeakPersistentHandle(Dart_WeakPersistentHandle object);
408 416
409 /** 417 /**
410 * Allocates a prologue weak persistent handle for an object. 418 * Allocates a prologue weak persistent handle for an object.
411 * 419 *
412 * Prologue weak persistent handles are similar to weak persistent 420 * Prologue weak persistent handles are similar to weak persistent
413 * handles but exhibit different behavior during garbage collections 421 * handles but exhibit different behavior during garbage collections
414 * that invoke the prologue and epilogue callbacks. While weak 422 * that invoke the prologue and epilogue callbacks. While weak
415 * persistent handles always weakly reference their referents, 423 * persistent handles always weakly reference their referents,
416 * prologue weak persistent handles weakly reference their referents 424 * prologue weak persistent handles weakly reference their referents
417 * only during a garbage collection that invokes the prologue and 425 * only during a garbage collection that invokes the prologue and
418 * epilogue callbacks. During all other garbage collections, prologue 426 * epilogue callbacks. During all other garbage collections, prologue
419 * weak persistent handles strongly reference their referents. 427 * weak persistent handles strongly reference their referents.
420 * 428 *
421 * This handle has the lifetime of the current isolate unless it is 429 * This handle has the lifetime of the current isolate unless it is
422 * explicitly deallocated by calling Dart_DeletePersistentHandle. 430 * explicitly deallocated by calling Dart_DeletePersistentHandle.
423 * 431 *
424 * Requires there to be a current isolate. 432 * Requires there to be a current isolate.
425 * 433 *
426 * \param object An object. 434 * \param object An object.
427 * \param peer A pointer to a native object or NULL. This value is 435 * \param peer A pointer to a native object or NULL. This value is
428 * provided to callback when it is invoked. 436 * provided to callback when it is invoked.
429 * \param callback A function pointer that will be invoked sometime 437 * \param callback A function pointer that will be invoked sometime
430 * after the object is garbage collected. 438 * after the object is garbage collected.
431 * 439 *
432 * \return Success if the prologue weak persistent handle was created. 440 * \return Success if the prologue weak persistent handle was created.
433 * Otherwise, returns an error. 441 * Otherwise, returns an error.
434 */ 442 */
435 DART_EXPORT Dart_Handle Dart_NewPrologueWeakPersistentHandle( 443 DART_EXPORT Dart_WeakPersistentHandle Dart_NewPrologueWeakPersistentHandle(
436 Dart_Handle object, 444 Dart_Handle object,
437 void* peer, 445 void* peer,
438 Dart_WeakPersistentHandleFinalizer callback); 446 Dart_WeakPersistentHandleFinalizer callback);
439 447
440 /** 448 /**
441 * Is this object a prologue weak persistent handle? 449 * Is this object a prologue weak persistent handle?
442 * 450 *
443 * Requires there to be a current isolate. 451 * Requires there to be a current isolate.
444 */ 452 */
445 DART_EXPORT bool Dart_IsPrologueWeakPersistentHandle(Dart_Handle object); 453 DART_EXPORT bool Dart_IsPrologueWeakPersistentHandle(Dart_WeakPersistentHandle o bject);
446 454
447 /** 455 /**
448 * Constructs a set of weak references from the Cartesian product of 456 * Constructs a set of weak references from the Cartesian product of
449 * the objects in the key set and the objects in values set. 457 * the objects in the key set and the objects in values set.
450 * 458 *
451 * \param keys A set of object references. These references will be 459 * \param keys A set of object references. These references will be
452 * considered weak by the garbage collector. 460 * considered weak by the garbage collector.
453 * \param num_keys the number of objects in the keys set. 461 * \param num_keys the number of objects in the keys set.
454 * \param values A set of object references. These references will be 462 * \param values A set of object references. These references will be
455 * considered weak by garbage collector unless any object reference 463 * considered weak by garbage collector unless any object reference
456 * in 'keys' is found to be strong. 464 * in 'keys' is found to be strong.
457 * \param num_values the size of the values set 465 * \param num_values the size of the values set
458 * 466 *
459 * \return Success if the weak reference set could be created. 467 * \return Success if the weak reference set could be created.
460 * Otherwise, returns an error handle. 468 * Otherwise, returns an error handle.
461 */ 469 */
462 DART_EXPORT Dart_Handle Dart_NewWeakReferenceSet(Dart_Handle* keys, 470 DART_EXPORT Dart_Handle Dart_NewWeakReferenceSet(
463 intptr_t num_keys, 471 Dart_WeakPersistentHandle* keys,
464 Dart_Handle* values, 472 intptr_t num_keys,
465 intptr_t num_values); 473 Dart_WeakPersistentHandle* values,
474 intptr_t num_values);
466 475
467 // --- Garbage Collection Callbacks --- 476 // --- Garbage Collection Callbacks ---
468 477
469 /** 478 /**
470 * Callbacks signal the beginning and end of a garbage collection. 479 * Callbacks signal the beginning and end of a garbage collection.
471 * 480 *
472 * These signals are intended to be used by the embedder to manage the 481 * These signals are intended to be used by the embedder to manage the
473 * lifetime of native objects with a managed object peer. 482 * lifetime of native objects with a managed object peer.
474 */ 483 */
475 484
(...skipping 1271 matching lines...) Expand 10 before | Expand all | Expand 10 after
1747 * \param type The type of the TypedData object. 1756 * \param type The type of the TypedData object.
1748 * \param length The length of the TypedData object (length in type units). 1757 * \param length The length of the TypedData object (length in type units).
1749 * 1758 *
1750 * \return The TypedData object if no error occurs. Otherwise returns 1759 * \return The TypedData object if no error occurs. Otherwise returns
1751 * an error handle. 1760 * an error handle.
1752 */ 1761 */
1753 DART_EXPORT Dart_Handle Dart_NewTypedData(Dart_TypedData_Type type, 1762 DART_EXPORT Dart_Handle Dart_NewTypedData(Dart_TypedData_Type type,
1754 intptr_t length); 1763 intptr_t length);
1755 1764
1756 /** 1765 /**
1757 * Returns a TypedData object which references an external data array. 1766 * Returns a TypedData object which references an external data array.
Anton Muhin 2013/05/23 17:18:04 nit: document needs an update
1758 * 1767 *
1759 * \param type The type of the data array. 1768 * \param type The type of the data array.
1760 * \param value A data array. This array must not move. 1769 * \param value A data array. This array must not move.
1761 * \param length The length of the data array (length in type units). 1770 * \param length The length of the data array (length in type units).
1762 * \param peer An external pointer to associate with this array. 1771 * \param peer An external pointer to associate with this array.
1763 * 1772 *
1764 * \return The TypedData object if no error occurs. Otherwise returns 1773 * \return The TypedData object if no error occurs. Otherwise returns
1765 * an error handle. The TypedData object is returned in a 1774 * an error handle. The TypedData object is returned in a
1766 * WeakPersistentHandle which needs to be deleted in the specified callback 1775 * WeakPersistentHandle which needs to be deleted in the specified callback
1767 * using Dart_DeletePersistentHandle. 1776 * using Dart_DeletePersistentHandle.
1768 */ 1777 */
1769 DART_EXPORT Dart_Handle Dart_NewExternalTypedData( 1778 DART_EXPORT Dart_Handle Dart_NewExternalTypedData(Dart_TypedData_Type type,
1770 Dart_TypedData_Type type, 1779 void* data,
1771 void* data, 1780 intptr_t length);
1772 intptr_t length,
1773 void* peer,
1774 Dart_WeakPersistentHandleFinalizer callback);
1775 1781
1776 /** 1782 /**
1777 * Retrieves the peer pointer associated with an external TypedData object. 1783 * Retrieves the peer pointer associated with an external TypedData object.
1778 */ 1784 */
1779 DART_EXPORT Dart_Handle Dart_ExternalTypedDataGetPeer(Dart_Handle object, 1785 DART_EXPORT Dart_Handle Dart_ExternalTypedDataGetPeer(Dart_Handle object,
1780 void** peer); 1786 void** peer);
1781 1787
1782 /** 1788 /**
1783 * Acquires access to the internal data address of a TypedData object. 1789 * Acquires access to the internal data address of a TypedData object.
1784 * 1790 *
(...skipping 850 matching lines...) Expand 10 before | Expand all | Expand 10 after
2635 * 2641 *
2636 * \param object An object. 2642 * \param object An object.
2637 * \param peer A value to store in the peer field. 2643 * \param peer A value to store in the peer field.
2638 * 2644 *
2639 * \return Returns an error if 'object' is a subtype of Null, num, or 2645 * \return Returns an error if 'object' is a subtype of Null, num, or
2640 * bool. 2646 * bool.
2641 */ 2647 */
2642 DART_EXPORT Dart_Handle Dart_SetPeer(Dart_Handle object, void* peer); 2648 DART_EXPORT Dart_Handle Dart_SetPeer(Dart_Handle object, void* peer);
2643 2649
2644 #endif // INCLUDE_DART_API_H_ 2650 #endif // INCLUDE_DART_API_H_
OLDNEW
« no previous file with comments | « runtime/bin/secure_socket.cc ('k') | runtime/lib/mirrors.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698