Skip to content

Commit 26d0b67

Browse files
authored
Add root handle extern (#12510)
1 parent ab7a43d commit 26d0b67

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

std/cpp/marshal/RootHandle.hx

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package cpp.marshal;
2+
3+
/**
4+
* An object which has been rooted will not be collected by the GC even if it has no other references.
5+
* Rooted objects can also be used to safely pass managed objects into unmanaged code.
6+
*/
7+
@:semantics(value)
8+
@:cpp.ValueType({ namespace : [ "cpp", "marshal" ] })
9+
extern class RootHandle {
10+
/**
11+
* Root the provided object and return a handle representing it.
12+
*/
13+
public static function create(obj:Dynamic):RootHandle;
14+
15+
/**
16+
* Reinterpret the provided `void*` as a rooted object.
17+
* If `ptr` is not a rooted object the behaviour is undefined.
18+
*/
19+
public static function fromVoidPointer(ptr:cpp.Pointer<cpp.Void>):RootHandle;
20+
21+
/**
22+
* Unroot the object represented by this handle.
23+
* If there are no other references to the object it will be eligible for collection by the GC.
24+
*/
25+
function close():Void;
26+
27+
/**
28+
* Return the object represented by this handle.
29+
*/
30+
function getObject():Dynamic;
31+
32+
/**
33+
* Returns the rooted object reinterpreted as a `void*`.
34+
*/
35+
function toVoidPointer():cpp.Pointer<cpp.Void>;
36+
}

0 commit comments

Comments
 (0)