New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
String view and the GC #159
Comments
This is actually expected behaviour. The short summary as to why it occurs is that the string view copies values into C storage, which is reclaimed by the GC since your code doesn't retain any references to it. In a little more detail, the second line is essentially equivalent to the following: let p : char ptr = coerce string (ptr char) s
let q : char ptr ptr = allocate (ptr char) p
let s' : string ptr = coerce (ptr (ptr char)) (ptr string) q except that no references are retained to the intermediate objects |
This is not consistent with the documentation : "To avoid problems with the garbage collector, values passed using Ctypes.string are copied into immovable C-managed storage before being passed to C.". GC issues are not at all avoided :/ Currently, my workaround is to go through a CArray. |
Ok, let's make it clear in the documentation that the GC problem in question concerns movability/stability, not (e.g.) lifetime. How about "To avoid passing references to (movable) OCaml objects to C ..."? |
Ok, I understand the issue better, thanks for the explanation. I think the wording is better. Maybe It would deserve a small section in the FAQ about the fact that lifetime issues may arise (and the workaround you presented). |
In the top level :
According to the documentation, isn't the string view supposed to avoid this issue ?
The text was updated successfully, but these errors were encountered: