No matching definitions.

tur/safe

stdlib/safe.tur

bounds-checked operations returning Option or Result.

Since: Phase U4

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

A :ptr to an option struct { bool is_some; int64_t value; }. is_some is false when idx is out of the v1 safe range.

(def opt (array-get arr 3))

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

1 if the write succeeded, 0 if idx was out of the v1 safe range.

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

A :ptr to a { void *ptr; size_t len; } slice struct.

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

Whatever f returns, as :ptr.

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

The same :cstr pointer (identity in v1).

Since: Phase U4

defn

box

(box [v :int] :ptr)

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

vinteger value to box

A :ptr to a newly heap-allocated int64_t cell containing v.

(def p (box 42))

Since: Phase U4

defn

unbox

(unbox [p :ptr] :int)

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

ppointer from box

The int64 value stored at p.

(unbox (box 42))  ; => 42

Since: Phase U4