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

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
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 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
363 /** 366 /**
367 * Allocates a handle in the current scope from a persistent handle.
368 */
369 DART_EXPORT Dart_Handle Dart_HandleFromPersistent(Dart_PersistentHandle object);
370
371 /**
372 * Allocates a handle in the current scope from a weak persistent handle.
373 */
374 DART_EXPORT Dart_Handle Dart_HandleFromWeakPersistent(
375 Dart_WeakPersistentHandle object);
376
377 /**
364 * Allocates a persistent handle for an object. 378 * Allocates a persistent handle for an object.
365 * 379 *
366 * This handle has the lifetime of the current isolate unless it is 380 * This handle has the lifetime of the current isolate unless it is
367 * explicitly deallocated by calling Dart_DeletePersistentHandle. 381 * explicitly deallocated by calling Dart_DeletePersistentHandle.
368 * 382 *
369 * Requires there to be a current isolate. 383 * Requires there to be a current isolate.
370 */ 384 */
371 DART_EXPORT Dart_Handle Dart_NewPersistentHandle(Dart_Handle object); 385 DART_EXPORT Dart_PersistentHandle Dart_NewPersistentHandle(Dart_Handle object);
372 386
373 /** 387 /**
374 * Deallocates a persistent handle. 388 * Deallocates a persistent handle.
375 * 389 *
376 * Requires there to be a current isolate. 390 * Requires there to be a current isolate.
377 */ 391 */
378 DART_EXPORT void Dart_DeletePersistentHandle(Dart_Handle object); 392 DART_EXPORT void Dart_DeletePersistentHandle(Dart_PersistentHandle object);
379 393
380 /** 394 /**
381 * Allocates a weak persistent handle for an object. 395 * Allocates a weak persistent handle for an object.
382 * 396 *
383 * This handle has the lifetime of the current isolate unless it is 397 * This handle has the lifetime of the current isolate unless it is
384 * explicitly deallocated by calling Dart_DeletePersistentHandle. 398 * explicitly deallocated by calling Dart_DeletePersistentHandle.
385 * 399 *
386 * Requires there to be a current isolate. 400 * Requires there to be a current isolate.
387 * 401 *
388 * \param object An object. 402 * \param object An object.
389 * \param peer A pointer to a native object or NULL. This value is 403 * \param peer A pointer to a native object or NULL. This value is
390 * provided to callback when it is invoked. 404 * provided to callback when it is invoked.
391 * \param callback A function pointer that will be invoked sometime 405 * \param callback A function pointer that will be invoked sometime
392 * after the object is garbage collected. 406 * after the object is garbage collected.
393 * 407 *
394 * \return Success if the weak persistent handle was 408 * \return Success if the weak persistent handle was
395 * created. Otherwise, returns an error. 409 * created. Otherwise, returns an error.
396 */ 410 */
397 DART_EXPORT Dart_Handle Dart_NewWeakPersistentHandle( 411 DART_EXPORT Dart_WeakPersistentHandle Dart_NewWeakPersistentHandle(
398 Dart_Handle object, 412 Dart_Handle object,
399 void* peer, 413 void* peer,
400 Dart_WeakPersistentHandleFinalizer callback); 414 Dart_WeakPersistentHandleFinalizer callback);
401 415
402 /** 416 DART_EXPORT void Dart_DeleteWeakPersistentHandle(Dart_WeakPersistentHandle objec t);
403 * Is this object a weak persistent handle?
404 *
405 * Requires there to be a current isolate.
406 */
407 DART_EXPORT bool Dart_IsWeakPersistentHandle(Dart_Handle object);
408 417
409 /** 418 /**
410 * Allocates a prologue weak persistent handle for an object. 419 * Allocates a prologue weak persistent handle for an object.
411 * 420 *
412 * Prologue weak persistent handles are similar to weak persistent 421 * Prologue weak persistent handles are similar to weak persistent
413 * handles but exhibit different behavior during garbage collections 422 * handles but exhibit different behavior during garbage collections
414 * that invoke the prologue and epilogue callbacks. While weak 423 * that invoke the prologue and epilogue callbacks. While weak
415 * persistent handles always weakly reference their referents, 424 * persistent handles always weakly reference their referents,
416 * prologue weak persistent handles weakly reference their referents 425 * prologue weak persistent handles weakly reference their referents
417 * only during a garbage collection that invokes the prologue and 426 * only during a garbage collection that invokes the prologue and
418 * epilogue callbacks. During all other garbage collections, prologue 427 * epilogue callbacks. During all other garbage collections, prologue
419 * weak persistent handles strongly reference their referents. 428 * weak persistent handles strongly reference their referents.
420 * 429 *
421 * This handle has the lifetime of the current isolate unless it is 430 * This handle has the lifetime of the current isolate unless it is
422 * explicitly deallocated by calling Dart_DeletePersistentHandle. 431 * explicitly deallocated by calling Dart_DeletePersistentHandle.
423 * 432 *
424 * Requires there to be a current isolate. 433 * Requires there to be a current isolate.
425 * 434 *
426 * \param object An object. 435 * \param object An object.
427 * \param peer A pointer to a native object or NULL. This value is 436 * \param peer A pointer to a native object or NULL. This value is
428 * provided to callback when it is invoked. 437 * provided to callback when it is invoked.
429 * \param callback A function pointer that will be invoked sometime 438 * \param callback A function pointer that will be invoked sometime
430 * after the object is garbage collected. 439 * after the object is garbage collected.
431 * 440 *
432 * \return Success if the prologue weak persistent handle was created. 441 * \return Success if the prologue weak persistent handle was created.
433 * Otherwise, returns an error. 442 * Otherwise, returns an error.
434 */ 443 */
435 DART_EXPORT Dart_Handle Dart_NewPrologueWeakPersistentHandle( 444 DART_EXPORT Dart_WeakPersistentHandle Dart_NewPrologueWeakPersistentHandle(
436 Dart_Handle object, 445 Dart_Handle object,
437 void* peer, 446 void* peer,
438 Dart_WeakPersistentHandleFinalizer callback); 447 Dart_WeakPersistentHandleFinalizer callback);
439 448
440 /** 449 /**
441 * Is this object a prologue weak persistent handle? 450 * Is this object a prologue weak persistent handle?
442 * 451 *
443 * Requires there to be a current isolate. 452 * Requires there to be a current isolate.
444 */ 453 */
445 DART_EXPORT bool Dart_IsPrologueWeakPersistentHandle(Dart_Handle object); 454 DART_EXPORT bool Dart_IsPrologueWeakPersistentHandle(
455 Dart_WeakPersistentHandle object);
446 456
447 /** 457 /**
448 * Constructs a set of weak references from the Cartesian product of 458 * Constructs a set of weak references from the Cartesian product of
449 * the objects in the key set and the objects in values set. 459 * the objects in the key set and the objects in values set.
450 * 460 *
451 * \param keys A set of object references. These references will be 461 * \param keys A set of object references. These references will be
452 * considered weak by the garbage collector. 462 * considered weak by the garbage collector.
453 * \param num_keys the number of objects in the keys set. 463 * \param num_keys the number of objects in the keys set.
454 * \param values A set of object references. These references will be 464 * \param values A set of object references. These references will be
455 * considered weak by garbage collector unless any object reference 465 * considered weak by garbage collector unless any object reference
456 * in 'keys' is found to be strong. 466 * in 'keys' is found to be strong.
457 * \param num_values the size of the values set 467 * \param num_values the size of the values set
458 * 468 *
459 * \return Success if the weak reference set could be created. 469 * \return Success if the weak reference set could be created.
460 * Otherwise, returns an error handle. 470 * Otherwise, returns an error handle.
461 */ 471 */
462 DART_EXPORT Dart_Handle Dart_NewWeakReferenceSet(Dart_Handle* keys, 472 DART_EXPORT Dart_Handle Dart_NewWeakReferenceSet(
463 intptr_t num_keys, 473 Dart_WeakPersistentHandle* keys,
Anton Muhin 2013/05/27 15:45:49 there was one fancy trick in our code which curren
Ivan Posva 2013/05/28 21:12:20 I am not sure I understand your usage of this API
Anton Muhin 2013/05/29 07:43:13 Yes, that's exactly what we do: weak persistent ha
464 Dart_Handle* values, 474 intptr_t num_keys,
465 intptr_t num_values); 475 Dart_WeakPersistentHandle* values,
476 intptr_t num_values);
466 477
467 // --- Garbage Collection Callbacks --- 478 // --- Garbage Collection Callbacks ---
468 479
469 /** 480 /**
470 * Callbacks signal the beginning and end of a garbage collection. 481 * Callbacks signal the beginning and end of a garbage collection.
471 * 482 *
472 * These signals are intended to be used by the embedder to manage the 483 * These signals are intended to be used by the embedder to manage the
473 * lifetime of native objects with a managed object peer. 484 * lifetime of native objects with a managed object peer.
474 */ 485 */
475 486
(...skipping 1283 matching lines...) Expand 10 before | Expand all | Expand 10 after
1759 * \param type The type of the data array. 1770 * \param type The type of the data array.
1760 * \param value A data array. This array must not move. 1771 * \param value A data array. This array must not move.
1761 * \param length The length of the data array (length in type units). 1772 * \param length The length of the data array (length in type units).
1762 * \param peer An external pointer to associate with this array. 1773 * \param peer An external pointer to associate with this array.
1763 * 1774 *
1764 * \return The TypedData object if no error occurs. Otherwise returns 1775 * \return The TypedData object if no error occurs. Otherwise returns
1765 * an error handle. The TypedData object is returned in a 1776 * an error handle. The TypedData object is returned in a
1766 * WeakPersistentHandle which needs to be deleted in the specified callback 1777 * WeakPersistentHandle which needs to be deleted in the specified callback
1767 * using Dart_DeletePersistentHandle. 1778 * using Dart_DeletePersistentHandle.
1768 */ 1779 */
1769 DART_EXPORT Dart_Handle Dart_NewExternalTypedData( 1780 DART_EXPORT Dart_Handle Dart_NewExternalTypedData(Dart_TypedData_Type type,
1770 Dart_TypedData_Type type, 1781 void* data,
1771 void* data, 1782 intptr_t length);
1772 intptr_t length,
1773 void* peer,
1774 Dart_WeakPersistentHandleFinalizer callback);
1775
1776 /**
1777 * Retrieves the peer pointer associated with an external TypedData object.
1778 */
1779 DART_EXPORT Dart_Handle Dart_ExternalTypedDataGetPeer(Dart_Handle object,
Anton Muhin 2013/05/27 15:45:49 there still should be a way to fetch peer object a
Ivan Posva 2013/05/28 21:12:20 For now, please use Dart_SetPeer and Dart_GetPeer
1780 void** peer);
1781 1783
1782 /** 1784 /**
1783 * Acquires access to the internal data address of a TypedData object. 1785 * Acquires access to the internal data address of a TypedData object.
1784 * 1786 *
1785 * \param object The typed data object whose internal data address is to 1787 * \param object The typed data object whose internal data address is to
1786 * be accessed. 1788 * be accessed.
1787 * \param type The type of the object is returned here. 1789 * \param type The type of the object is returned here.
1788 * \param data The internal data address is returned here. 1790 * \param data The internal data address is returned here.
1789 * \param len Size of the typed array is returned here. 1791 * \param len Size of the typed array is returned here.
1790 * 1792 *
(...skipping 844 matching lines...) Expand 10 before | Expand all | Expand 10 after
2635 * 2637 *
2636 * \param object An object. 2638 * \param object An object.
2637 * \param peer A value to store in the peer field. 2639 * \param peer A value to store in the peer field.
2638 * 2640 *
2639 * \return Returns an error if 'object' is a subtype of Null, num, or 2641 * \return Returns an error if 'object' is a subtype of Null, num, or
2640 * bool. 2642 * bool.
2641 */ 2643 */
2642 DART_EXPORT Dart_Handle Dart_SetPeer(Dart_Handle object, void* peer); 2644 DART_EXPORT Dart_Handle Dart_SetPeer(Dart_Handle object, void* peer);
2643 2645
2644 #endif // INCLUDE_DART_API_H_ 2646 #endif // INCLUDE_DART_API_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698