Scoop API

scoop:scoop.core:0.1.0

src/data_borrow.scoop

Selected production source · src/data_borrow.scoop

1// Scoped native access. The compiler supplies layout and exception cleanup.
3@Unsafe
4@Intrinsic("array_with_data_pointer")
5internal fun <T : value, R> _withArrayDataPointer(array: Array<T>, block: (Ptr<T>, Long) -> R): R
7@Unsafe
8@Intrinsic("mutable_array_with_data_pointer")
9internal fun <T : value, R> _withMutableArrayDataPointer(array: MutableArray<T>, block: (Ptr<T>, Long) -> R): R
11@Unsafe
12@Intrinsic("string_with_utf8_bytes")
13internal fun <R> _withStringUtf8Bytes(value: String, block: (Ptr<UInt8>, Long) -> R): R
15/**
16 * Borrows contiguous array element storage for the callback, passing its pointer and element
17 * count. The pointer is valid only during the callback and must not escape.
18 */
19@Unsafe
20public fun <T : value, R> Array<T>.withDataPointer(block: (Ptr<T>, Long) -> R): R =
21 _withArrayDataPointer<T, R>(this, block)
23/**
24 * Borrows contiguous array element storage for the callback, passing its pointer and element
25 * count. The pointer is valid only during the callback and must not escape.
26 */
27@Unsafe
28public fun <T : value, R> MutableArray<T>.withDataPointer(block: (Ptr<T>, Long) -> R): R =
29 _withMutableArrayDataPointer<T, R>(this, block)
31/**
32 * Borrows the string's UTF-8 bytes for the callback, without a terminating NUL. The pointer is
33 * valid only during the callback.
34 */
35@Unsafe
36public fun <R> String.withUtf8Bytes(block: (Ptr<UInt8>, Long) -> R): R =
37 _withStringUtf8Bytes<R>(this, block)