mirror of
https://github.com/logos-messaging/nim-ffi.git
synced 2026-07-24 08:43:16 +00:00
15 lines
407 B
Nim
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
|