tur/safe

stdlib/safe.tur
defn

array-get

(array-get [arr :ptr<void> idx :int] :ptr)

bounds-checked array read; returns a heap-allocated Option struct.

arrpointer to an int64_t array
idxzero-based index to read

Since: Phase U4

defn

array-set

(array-set [arr :ptr<void> idx :int value :int] :int)

bounds-checked array write; returns 1 on success, 0 on out-of-range index.

arrpointer to an int64_t array
idxzero-based index to write
valuevalue to store

Since: Phase U4

defn

array-slice

(array-slice [arr :ptr<void> start :int len :int] :ptr)

create a { ptr, len } slice view starting at start for len elements.

arrsource int64_t array pointer
startfirst element index (offset in int64_t units)
lennumber of elements in the view

Since: Phase U4

defn

with-c-string

(with-c-string [s :cstr f :ptr] :ptr)

pass a Turmeric cstr to a callback function and return its result.

scstr value to pass (already a C string in v1)
ffunction pointer accepting a cstr; called with s

Since: Phase U4

defn

from-c-string

(from-c-string [s :cstr] :cstr)

return a Turmeric cstr from a C string (no-copy in v1).

sC string to wrap

Since: Phase U4

defn

box

(box [v :int] :ptr)

heap-allocate an int64 value and return a pointer to it.

vinteger value to box

Since: Phase U4

defn

unbox

(unbox [p :ptr] :int)

read the int64 value from a heap pointer created by box.

ppointer from box

Since: Phase U4