doc: update obsolete string(x)/string(x,len) to .vstring() and .vstring_with_len(len)

pull/7398/head
Delyan Angelov 2020-12-18 18:18:16 +02:00
parent 6f7889a3ca
commit 3915d13b8d
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
1 changed files with 5 additions and 4 deletions

View File

@ -2854,11 +2854,12 @@ For example: `-cc gcc-9 -cflags -fsanitize=thread`.
### C types
Ordinary zero terminated C strings can be converted to V strings with `string(cstring)`
or `string(cstring, len)`.
Ordinary zero terminated C strings can be converted to V strings with
`unsafe { charptr(cstring).vstring() }` or if you know their length already with
`unsafe { charptr(cstring).vstring_with_len(len) }`.
NB: Each `string(...)` function does NOT create a copy of the `cstring`,
so you should NOT free it after calling `string()`.
NB: The .vstring() and .vstring_with_len() methods do NOT create a copy of the `cstring`,
so you should NOT free it after calling the method `.vstring()`.
If you need to make a copy of the C string (some libc APIs like `getenv` pretty much require that,
since they return pointers to internal libc memory), you can use `cstring_to_vstring(cstring)`.