nim-ffi/ffi/internal/c_wire.nim
2026-07-15 11:46:05 -03:00

15 lines
407 B
Nim

## Runtime cstring alloc/free for the macro-generated `*_CWire` types.
import ../alloc
proc cwireAllocStr*(s: string): cstring {.inline.} =
## NUL-terminated `malloc` copy of `s`; pair with `cwireFreeStr`.
alloc.alloc(s)
proc cwireFreeStr*(s: var cstring) {.inline.} =
## Idempotent free; reset to `nil` so a repeated call can't double-free.
if s.isNil():
return
alloc.dealloc(s)
s = nil