yallop / ocaml-ctypes

Library for binding to C libraries using pure OCaml
MIT License
363 stars 95 forks source link

Confused about the documentation of `string` #747

Closed Hirrolot closed 11 months ago

Hirrolot commented 11 months ago

From the documentation:

When the memory is not owned by the C code, -- i.e. when creating or initializing a struct in OCaml before passing it to C -- then the string view isn't a good choice, because there's no way to manage the lifetime of the C copy of the generated OCaml string.

Meanwhile, the tutorial from the "Real World OCaml" defines two functions addstr and mvwaddstr, which both take a string owned by OCaml:

let addstr = foreign "addstr" (string @-> returning void)

let mvwaddstr =
  foreign
    "mvwaddstr"
    (window @-> int @-> int @-> string @-> returning void)
yallop commented 11 months ago

I think you're quite right; the documentation you quoted isn't very clear. I've proposed a reworded version in #750.