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.
Parameters
| arr | pointer to an int64_t array | |
| idx | zero-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.
Parameters
| arr | pointer to an int64_t array | |
| idx | zero-based index to write | |
| value | value 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.
Parameters
| arr | source int64_t array pointer | |
| start | first element index (offset in int64_t units) | |
| len | number 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.
Parameters
| s | cstr value to pass (already a C string in v1) | |
| f | function 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).
Parameters
| s | C string to wrap |
Since: Phase U4
defn
box
(box [v :int] :ptr)
heap-allocate an int64 value and return a pointer to it.
Parameters
| v | integer value to box |
Since: Phase U4
defn
unbox
(unbox [p :ptr] :int)
read the int64 value from a heap pointer created by box.
Parameters
| p | pointer from box |
Since: Phase U4